【问题标题】:GNU Makefile, detect architectureGNU Makefile,检测架构
【发布时间】:2016-04-14 15:55:15
【问题描述】:

我想自动检测系统架构,当我在 freebsd 下编译我的程序并且我想要 2 个包含 x64 和 x32 但不工作时,我尝试这样:

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

这里有什么问题? 当我在 amd64 上编译时,使用下面的代码。 当我在 i388 上编译时不起作用。

当我在 amd64 上使用 makefile 下面的代码编译时,请参阅 x64 目录。 当我在 i386 上使用 makefile 下面的代码编译时,请参阅 x64 目录。 Soo bassicaly,否则没有任何效果?

【问题讨论】:

  • 改用uname -p
  • 不工作。这让我发疯......我不明白为什么。

标签: makefile gnu-make


【解决方案1】:

在 GNU make 语法中,$() 取消引用一个变量。你宁愿想要一个 shell 命令:

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

然后:

ifeq ($(uname_p),i386)

使用computed variable names 替代多级ifeq。这是我在我的系统上使用的一个工作 makefile:

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))

产生以下输出:

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

【讨论】:

  • ifeq ($(shell uname -p),i386) 像这样尝试过,但不工作。 :((((((((((((((((()))
  • @Starrrks_2 添加$(info $(shell uname -p)) 并发布其输出。
  • 我得到非法变量名。这里的错误是打印prntscr.com/asabll,这是我的系统prntscr.com/asabv5
  • @Starrrks_2 伙计,这些是 GNU Make 语法中用于生成文件的命令。它们不应该在 shell 中工作。
  • 这是我的makefile,请检查一下。 paste.ubuntu.com/15838571我的makefile不太好,所以我不知道在哪里运行下面的语法
猜你喜欢
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-11
  • 2012-03-31
  • 1970-01-01
相关资源
最近更新 更多