Last active
October 4, 2024 05:08
-
-
Save sighingnow/deee806603ec9274fd47 to your computer and use it in GitHub Desktop.
Detect operating system in Makefile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
@joseluisq 👍👍
Thank you!
Thank you!!
My simplified version for Unix-like systems (
uname
):Makefile
OS_NAME := $(shell uname -s | tr A-Z a-z) os: @echo $(OS_NAME)
Thank you
Thank you :)
This is my laptop information
Device name DESKTOP-RK0Q93P
Processor 13th Gen Intel(R) Core(TM) i5-1340P 1.90 GHz
Installed RAM 16.0 GB (15.6 GB usable)
Device ID 140104E8-85AA-3D55-990E-5185A62E169B
Product ID 00425-00000-00002-AA904
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display
And this is the output i am getting
C:\Users\Hecker>make
-D WIN32 -D IA32
Can someone tell me whats the issue ?
OS_MAKE_NAME="OS"
OS_NAME := $(shell uname -s | tr A-Z a-z)
OS_ARCH := $(shell uname -m | tr A-Z a-z)
os:
@echo ""
@echo ""
@echo "--- $(OS_MAKE_NAME) ---"
@echo "OS_NAME: $(OS_NAME)"
@echo "OS_ARCH: $(OS_ARCH)"
@echo ""
make os
--- OS ---
OS_NAME: darwin
OS_ARCH: arm64
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@joseluisq 👍