从makefile内部设置PATH变量对make 3.81不起作用

时间:2012-07-31 17:21:21

标签: xcode makefile osx-mountain-lion

更改Makefile中的环境变量`PATH'不会在CLT中使用make生效,而且我可以使用我从原始源编译的make util。

简单的Makefile

PATH := $(PATH):/opt/bin

export PATH

all:
      @cscope --version

我的测试

/tmp $ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin
/tmp $ ls /opt/bin/cscope
/opt/bin/cscope
/tmp $ which make
/usr/bin/make
/tmp $ make
make: cscope: No such file or directory
make: *** [all] Error 1
/tmp $ ./_install/bin/make
cscope: version 15.7a
/tmp $ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.


This program built for i386-apple-darwin11.3.0
/tmp $ ./_install/bin/make --version
GNU Make 3.82
Built for x86_64-apple-darwin12.0.0
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您将make变量与shell变量混淆。使用您的设置,调用的shell命令不受您设置的make变量PATH的影响。

您应该在食谱中设置PATH变量,例如

all:
    @PATH=$(PATH):/opt/bin; cscope --version

你必须同时在一条线上,因为配方中的每一行都将在另一个shell中运行,实际上会丢失你刚才所做的PATH设置。或者,您可以通过在每行末尾添加反斜杠\将其划分为多行:

all:
    @PATH=$(PATH):/opt/bin; \
    cscope --version

更新

抱歉,我错过了makefile使用make 3.82的重要性。我尝试了两个版本,事实上,3.813.82在这种情况下表现不同。

我确实通过调用3.81按照以下方式使用make

make SHELL="/bin/sh -c"

make SHELL=/bin/bash