Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Forked from sighingnow/Makefile
Last active July 15, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseluisq/e62fa55c10af24ab2c2a735ddd76f219 to your computer and use it in GitHub Desktop.
Save joseluisq/e62fa55c10af24ab2c2a735ddd76f219 to your computer and use it in GitHub Desktop.
Detect operating system in Makefile.
# Detect operating system in Makefile.
# Author: He Tao
# Date: 2015-05-30
OSFLAG :=
ifeq ($(OS),Windows_NT)
OSFLAG += -D WIN32
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
OSFLAG += -D AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
OSFLAG += -D IA32
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG += -D LINUX
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG += -D OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
OSFLAG += -D AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
OSFLAG += -D IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
OSFLAG += -D ARM
endif
endif
all:
@echo $(OSFLAG)
## OS name short alternative for Unix-like only
OS_NAME := $(shell uname -s | tr A-Z a-z)
os:
@echo $(OS_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment