GNU Makefile, detect architecture

浪尽此生 提交于 2019-12-07 05:09:43

问题


I want to autodetect system architecture, when i compile my program under freebsd and i want 2 includes for x64 and x32 but don't work, i tried like this :

ifeq ($(uname -a),i386)
INCDIR += -I../../x32
else
INCDIR += -I../../x64
endif

What is wrong here? When i compile on amd64 work with code below. When i compile on i388 don't work.

When i compile on amd64 with code below the makefile see x64 dir. When i compile on i386 with code below the makefile see x64 dir. Soo bassicaly that else don't have any effect ?


回答1:


In GNU make syntax $() dereferences a variable. You rather want a shell command:

uname_p := $(shell uname -p) # store the output of the command in a variable

And then:

ifeq ($(uname_p),i386)

Alternative to multi-level ifeq using computed variable names. Here is a working makefile I used on my system:

uname_s := $(shell uname -s)
$(info uname_s=$(uname_s))
uname_m := $(shell uname -m)
$(info uname_m=$(uname_m))

# system specific variables, add more here    
INCDIR.Linux.x86_64 := -I../../x64
INCDIR.Linux.i386 := -I../../x32

INCDIR += $(INCDIR.$(uname_s).$(uname_m))
$(info INCDIR=$(INCDIR))

Which produces the following output:

$ make 
uname_s=Linux
uname_m=x86_64
INCDIR=-I../../x64


来源:https://stackoverflow.com/questions/36628165/gnu-makefile-detect-architecture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!