Skip to content

Instantly share code, notes, and snippets.

@kosh04
Last active October 24, 2017 11:56
Show Gist options
  • Save kosh04/01b49756ac3b2a21c833 to your computer and use it in GitHub Desktop.
Save kosh04/01b49756ac3b2a21c833 to your computer and use it in GitHub Desktop.
Makefileで使用するコンパイラからターゲットとなるプラットフォームを判定する
CC ?= cc
usage := make -f $(notdir $(MAKEFILE_LIST)) [CC=cc]
platform_list := linux bsd darwin mingw cygwin solaris
machine := $(shell $(CC) -dumpmachine)
# $(call grep, string, word-list)
grep = $(strip $(foreach word,$2,$(findstring $(word),$1)))
all:
@echo $(CC) -dumpmachine : $(machine)
@echo found : $(call grep, $(machine), $(platform_list))
.PHONY: help usage
help usage:
@echo usage: $(usage)
@kosh04
Copy link
Author

kosh04 commented Jan 30, 2015

使用例:

$ make -f os.mk CC=gcc
gcc -dumpmachine : x86_64-w64-mingw32
found : mingw

@kosh04
Copy link
Author

kosh04 commented Feb 2, 2015

Bug 52096 - -dumpmachine does not respect -m32 - GCC Bugzilla
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52096

-dumpmachine の表示するアーキテクチャ情報でビット判定はすべきでないと書かれている。
一応参考までに。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment