【问题标题】:Is the first target in Makefile an implicit phony target?Makefile 中的第一个目标是隐含的虚假目标吗?
【发布时间】:2015-07-05 05:22:47
【问题描述】:

我正在研究从编译器课程项目中获得的 Makefile。这里只粘贴了一部分。

# Retain intermediate bitcode files
.PRECIOUS: %.bc

# The default target builds the plugin
plugin:
    make -C lib/p1

# create .bc from source
%.bc:   %.c
    clang -emit-llvm -O0 -c $*.c -o $*.bc

# run printCode on a .bc file
%.printCode: %.bc plugin
    opt -load Debug/lib/P1.so -printCode $*.bc 

如您所见,目标“插件”没有依赖关系,如果我理解正确,这应该意味着它的配方永远不会运行(除非它被声明为虚假目标,这里不是这种情况)

但是,当我键入“make printCode”时(printCode 是列表中的最后一个目标),插件目标会执行。这怎么可能?是否有一些隐含的规则表明 Makefile 的第一个目标被视为虚假目标,例如“all”?

【问题讨论】:

    标签: makefile


    【解决方案1】:

    你有点落后了。

    可以运行类似plugin 规则的规则。您可以通过执行“make plugin”来运行它,或者如果它是默认目标(在这种情况下由于是第一个目标),或者如果它是必须是另一个目标的先决条件,则可以运行它建成。

    我不确定当你“制作 printCode”时究竟会发生什么,因为你只向我们展示了 makefile 的一部分并且没有适合的规则,但根据这条规则来判断:

    %.printCode: %.bc plugin
        opt -load Debug/lib/P1.so -printCode $*.bc 
    

    我猜printCode 规则取决于plugin 或类似foo.printCode 的东西取决于plugin。所以 Make 看到 plugin 是一个先决条件,看到不存在这样的文件,因此确定必须构建 plugin。然后它会查找构建 plugin 的规则,找到并运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多