我可以在Linux上的Makefile中设置PATH,但不能在Mac OS X中设置.在OS X中,PATH设置但不会被使用.这是一个演示:
在CentOS 6上使用bash 4.1.2(1)-release和GNU Make 3.81
$ pwd /tmp/experiment $ find * -type f -ls 132133 4 -rw-rw-r-- 1 tlim tlim 113 Aug 26 11:01 Makefile 132132 4 -rwxrwxr-x 1 tlim tlim 28 Aug 26 10:59 bin/myprog $ cat Makefile export PATH := $(shell /bin/pwd)/bin:$(PATH) what: @echo PATH=$$PATH @echo PATH=$(PATH) which myprog myprog $ cat bin/myprog #!/bin/bash echo HERE I AM. $ make what PATH=/tmp/experiment/bin:/usr/stack/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin PATH=/tmp/experiment/bin:/usr/stack/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin which myprog /tmp/experiment/bin/myprog myprog HERE I AM.
这是使用GNU Make 3.81在Mac OS X 10.9.4上运行的完全相同的文件:
$ pwd /tmp/experiment $ find * -type f -ls 51838886 8 -rw-rw-r-- 1 tal wheel 113 Aug 26 07:01 Makefile 51838887 8 -rwxrwxr-x 1 tal wheel 28 Aug 26 06:59 bin/myprog $ cat Makefile export PATH := $(shell /bin/pwd)/bin:$(PATH) what: @echo PATH=$$PATH @echo PATH=$(PATH) which myprog myprog $ cat bin/myprog #!/bin/bash echo HERE I AM. $ make what PATH=/tmp/experiment/bin:/Users/tal/bin:/opt/local/sbin:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin PATH=/tmp/experiment/bin:/Users/tal/bin:/opt/local/sbin:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin which myprog /tmp/experiment/bin/myprog myprog make: myprog: No such file or directory make: *** [what] Error 1
如您所见,PATH正在设置并导出到环境中."echo $ PATH"和"my myprog"都显示路径已设置.但是,当运行"myprog"时,shell无法找到它.
更新:如果我将这两行添加到what
Makefile中的配方:
@echo SHELL=$$SHELL @echo SHELL=$(SHELL)
Linux和Mac输出:
SHELL=/bin/bash SHELL=/bin/sh
两者在运行之前都SHELL
等于/bin/bash
环境make
.这让我觉得SHELL
在Makefile 中设置只是神奇而且是GNU Make Manual总是设置的众多原因之一SHELL
.