【问题标题】:Understanding a Makefile with $(basename $(notdir $@))使用 $(basename $(notdir $@)) 理解 Makefile
【发布时间】:2013-05-19 14:03:35
【问题描述】:

我正在尝试理解 Makefile,但我不理解带有注释的配方行。

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

我还是个新手。你能给我一个非常简单的解释吗:

$(basename $(notdir $@))

【问题讨论】:

    标签: linux compilation makefile


    【解决方案1】:

    如果你把它分解:

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

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

    【讨论】:

    • 优秀的答案。我也使用目录名作为$(notdir $@) 的前缀。例如:@echo "Building source file: " $< $(CC) $(CFLAGS) -c $< -o $(OBJECT-DIR)/$(notdir $@) 和之前定义的OBJECT-DIR = obj
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多