makefile - 当前Makefile的绝对路径

标签 makefile gnu-make

在 GNU Make 中,给定某个绝对路径中的 makefile /path/Makefile ,如果Makefile是当前正在处理的makefile,如何恢复 Makefile 的绝对路径(例如 /path )无论是否正在处理和/或包含此类 Makefile?

我发现的最相似的 makefile 变量是 CURDIR ,但据我了解,这就像当前 makefile 调用的 PWD。

最佳答案

扩展comment通过 G.M. ,我建议你结合$(firstword)$(lastword)$(abspath)$(realpath),例如:

all:
        @echo "$(abspath $(lastword $(MAKEFILE_LIST)))"
        @echo "$(realpath $(firstword $(MAKEFILE_LIST)))"

关于makefile - 当前Makefile的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77653359/

相关文章:

c++ - 在 MinGW 中找不到 make

c - 具有多个目标文件的动态库在加载过程中失败

同时为静态库和可执行文件创建 makefile

c++ - 与一般的 makefile 作斗争

makefile - 当 PHONY 依赖项更新时,为什么 make 不考虑没有配方过时的目标?

c - Makefile 问题 - 无法理解问题出在哪里

android - 总是恢复到旧版本

c - 为 makefiles/kconfig 中的变量赋值

c++ - 在 makefile 中为 visual studio C++ build 定义宏

Makefile命令修改