我想编写一个可以运行测试的Makefile.测试位于目录"./tests"中,而要测试的可执行文件位于目录"./bin"中.
I want to write a Makefile which would run tests. Test are in a directory './tests' and executable files to be tested are in the directory './bin'.
运行测试时,他们看不到exec文件,因为目录./bin不在$ PATH中.
When I run the tests, they don't see the exec files, as the directory ./bin is not in the $PATH.
当我做这样的事情时:
EXPORT PATH=bin:$PATH make test一切正常.但是我需要在Makefile中更改$ PATH.
everything works. However I need to change the $PATH in the Makefile.
简单的Makefile内容:
Simple Makefile content:
test all: PATH=bin:${PATH} @echo $(PATH) x它可以正确打印路径,但是找不到文件x.
It prints the path correctly, however it doesn't find the file x.
当我手动执行此操作时:
When I do this manually:
$ export PATH=bin:$PATH $ x那么一切都很好.
如何更改Makefile中的$ PATH?
How could I change the $PATH in the Makefile?
推荐答案您尝试 Make本身的指令(假设您使用的是GNU Make)?
Did you try export directive of Make itself (assuming that you use GNU Make)?
export PATH := bin:$(PATH) test all: x此外,您的示例中还有一个错误:
Also, there is a bug in you example:
test all: PATH=bin:${PATH} @echo $(PATH) x首先,echo ed的值是由Make(而不是外壳程序)执行的PATH变量的扩展.我想,如果它输出期望值,那么您已经在Makefile中或调用Make的shell中的某个位置设置了PATH变量.为了防止这种行为,您应该逃脱美元的侵害:
First, the value being echoed is an expansion of PATH variable performed by Make, not the shell. If it prints the expected value then, I guess, you've set PATH variable somewhere earlier in your Makefile, or in a shell that invoked Make. To prevent such behavior you should escape dollars:
test all: PATH=bin:$$PATH @echo $$PATH x第二,无论如何这都不起作用,因为Make在单独的外壳.可以通过在单行中编写配方来更改它:
Second, in any case this won't work because Make executes each line of the recipe in a separate shell. This can be changed by writing the recipe in a single line:
test all: export PATH=bin:$$PATH; echo $$PATH; x更多推荐
如何在Makefile中将dir添加到$ PATH?
发布评论