Linux 使用 $(basename $(notdir $@)) 理解 Makefile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16727021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:01:37  来源:igfitidea点击:

Understanding a Makefile with $(basename $(notdir $@))

linuxcompilationmakefile

提问by

I am trying to understand a Makefile, but I don't understand the recipe line with the comment.

我试图理解 Makefile,但我不理解注释中的配方行。

...
...
sample.a:
    cd ../$(basename $(notdir $@)) && make    ##i don't understand this
...
...

I'm still a newbie at this. Can you give me a very simple explanation about:

我在这方面还是个新手。你能给我一个非常简单的解释:

$(basename $(notdir $@))

$(basename $(notdir $@))

采纳答案by lurker

If you break it down:

如果你分解它:

$(notdir $@)takes away the path from the file name leaving just the file name (so /x/y/foo.abecomes foo.a) $(basename ...)takes away the extension (so foo.abecomes foo)

$(notdir $@)去掉文件名的路径,只留下文件名(所以/x/y/foo.a变成foo.a$(basename ...)去掉扩展名(foo.a变成foo

There's a decent reference here: http://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

这里有一个不错的参考:http: //www.gnu.org/software/make/manual/html_node/File-Name-Functions.html