Quantcast
Channel: OS detecting makefile - Stack Overflow
Viewing all articles
Browse latest Browse all 15

Answer by Trevor Robinson for OS detecting makefile

$
0
0

There are many good answers here already, but I wanted to share a more complete example that both:

  • doesn't assume uname exists on Windows
  • also detects the processor

The CCFLAGS defined here aren't necessarily recommended or ideal; they're just what the project to which I was adding OS/CPU auto-detection happened to be using.

ifeq ($(OS),Windows_NT)    CCFLAGS += -D WIN32    ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)        CCFLAGS += -D AMD64    else        ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)            CCFLAGS += -D AMD64        endif        ifeq ($(PROCESSOR_ARCHITECTURE),x86)            CCFLAGS += -D IA32        endif    endifelse    UNAME_S := $(shell uname -s)    ifeq ($(UNAME_S),Linux)        CCFLAGS += -D LINUX    endif    ifeq ($(UNAME_S),Darwin)        CCFLAGS += -D OSX    endif    UNAME_P := $(shell uname -p)    ifeq ($(UNAME_P),x86_64)        CCFLAGS += -D AMD64    endif    ifneq ($(filter %86,$(UNAME_P)),)        CCFLAGS += -D IA32    endif    ifneq ($(filter arm%,$(UNAME_P)),)        CCFLAGS += -D ARM    endifendif

Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>