2012-07-31 162 views
2

更改Makefile中的环境变量`PATH'在CLT中不会生效,并且可以使用我从原始源编译的make util。设置内部makefile中的PATH变量对make不起作用3.81

简单的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. 

谁能帮助?

+0

是'cscope'的唯一工具你担心,或者是其他的在'/ opt/bin /'中? – Beta 2012-07-31 17:57:25

+0

不,这只是一个简单的测试util,不在系统'PATH'中。 – ShadowStar 2012-07-31 19:17:49

回答

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的确在这种情况下表现不同。

我没有得到这个通过调用make如下与3.81的工作,虽然:

make SHELL="/bin/sh -c" 

make SHELL=/bin/bash 
+0

首先感谢您的回答。按照你的方式,我必须在每个目标的命令中添加“@PATH = $(PATH):/ opt/bin”。而从源头上构建的util util没有这个问题。 – ShadowStar 2012-07-31 17:46:57

+0

有问题的Makefile是一个简单的例子,而不是真正使用的例子。 – ShadowStar 2012-07-31 18:08:20

+0

是的,它的工作原理。但环境变量中的'SHELL =/bin/bash'可以被'env'看到。 – ShadowStar 2012-07-31 18:55:33