我能够设置PATH在一个Makefile在Linux上,不支持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.
这里是完全相同的文件在Mac OS X 10.9.4上运行与GNU制作3.81:
$ 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”和“这MYPROG”显示,路径设置。 但是,运行“MYPROG”壳时无法找到它。
更新:如果我这两行添加到what
在Makefile食谱:
@echo SHELL=$$SHELL
@echo SHELL=$(SHELL)
Linux和Mac的输出:
SHELL=/bin/bash
SHELL=/bin/sh
两者都有SHELL
等于/bin/bash
在环境中运行前make
。 这让我觉得有SHELL
Makefile中集只是魔术和是众多原因,GNU Make使用手册说,总是设置一个SHELL
。