使 makefile 中的包含内容与当前文件的位置相关
序言:这个问题已经过时了。 NDK 构建/本机调试系统不再像这样工作了。
与此问题直接相关。如何使 makefile 中的 include
指令的行为相对于当前执行 makefile 的位置。
假设当前路径是任意的并且您无法控制它。仅 makefile 位置已知。您的 makefile 不是 make
调用中的根文件 - 它已包含在内。 Android NDK 中正是如此。
是否有带有当前 makefile 名称或路径的内置变量(而不是根级 makefile)?我可以去掉文件名,只留下路径吗?在 Cygwin 上使用 make 3.81。
PREAMBLE: the question is wildly obsolete. The NDK build/native debugging system doesn't work like this anymore.
Directly related to this question. How can I make the include
directive in makefiles behave relatively to the location of the currently executing makefile.
Assume that the current path is arbitrary and you have no control over it. Only the makefile location is known. Your makefile is not the root one from the make
invokation - it's included. That's exactly how it is in Android NDK.
Is there a builtin variable with the current makefile's name or path (as opposed to the root level makefile)? Can I strip filename away from it, leaving just the path? Using make 3.81 on Cygwin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
是否存在具有当前 makefile 名称的内置变量?
是的,有,使用 ${CURDIR}。这是顶级 Makefile 所在的目录,因此您不需要从中删除任何内容。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以从
获取当前正在处理的 makefile 的名称MAKEFILE_LIST
内置变量。鉴于当前的 makefile 是最后一个被包含的文件(换句话说,自当前脚本开始以来,您没有使用另一个
include
指令),路径脚本本身将是:现在您可以在同一目录中包含一个脚本(注意没有斜杠,它已经由
$(dir ...)
添加了):注意:在 GNU Make 3.80 中没有
lastword
内置函数。在这种情况下,您可以按如下方式实现它,将$(lastword ...)
替换为$(call lastword,...)
:You can get the name of the makefile being currently processed from
MAKEFILE_LIST
builtin variable.Given that the current makefile is the last one that has been included (in other words you didn't use another
include
directive since the beginning of the current script), the path to the script itself would be:Now you are able to include a script in the same directory as such (note an absence of slash, it has already been added by
$(dir ...)
):Note: In GNU Make 3.80 there was no
lastword
builtin function. In that case you may implement it as follows replacing$(lastword ...)
with$(call lastword,...)
: