我知道变量可以导出到子makefile:将变量传递给子-make。
示例:
假设第一个Makefile位于/path/to/first/makefile,上面的代码将打印:
/path/to/first/makefile
/path/to/first/makefile我的问题是:是否有一种方法让变量PWD是隐式地在子生成文件中计算?输出应该如下所示:
/path/to/first/makefile
/path/to/first/makefile/somewhere到目前为止,我只能想到:
eval.SECONDEXPANSION来做所有这些解决方案都可以解释:它们意味着要将代码添加到子makefile中。我正在搜索的是一个隐式解决方案,它将只更改第一个Makefile中的代码。
另外,honestly...the前两种解决方案太难看了,我宁愿在每个子makefile中手动声明PWD。
编辑
为了更清楚地说明:变量PWD只是一个例子,我并不试图获得每个Makefile的路径。
发布于 2016-09-29 10:39:48
使用${MAKEFILE_LIST}变量,让您更改目录:
[max@earth:~/tmp]$ cat Makefile
target:
@echo $(abspath $(lastword ${MAKEFILE_LIST}))
${MAKE} -C somewhere $@
[max@earth:~/tmp]$ cat somewhere/Makefile
target:
@echo $(abspath $(lastword ${MAKEFILE_LIST}))
[max@earth:~/tmp]$ make target
/home/max/tmp/Makefile
make -C somewhere target
make[1]: Entering directory '/home/max/tmp/somewhere'
/home/max/tmp/somewhere/Makefile
make[1]: Leaving directory '/home/max/tmp/somewhere'它打印正在处理的makefile的完整路径。使用$(dir $(abspath $(lastword ${MAKEFILE_LIST})))砍掉文件名Makefile。
https://stackoverflow.com/questions/39767814
复制相似问题