【问题标题】:the behavior when a gnu make phony target happens to be the same as a directory name当 gnu make phony target 恰好与目录名称相同时的行为
【发布时间】:2014-08-13 17:34:58
【问题描述】:

makefile 有一个虚假的目标libs,还有一个目录libs 要下降。在一台机器上,它运行良好,而另一台机器上却没有进入libs 目标的libs 目录。在这两种情况下,gnu make 版本都是 3.81,但一个在 windows 上,另一个在 centos 上。

顶级make文件:

$ cat Makefile

SUBDIRS := libs

.phony: all headers libs exes

  all: headers libs exes

headers libs exes:
        @for d in $(SUBDIRS); do \
          echo -e "\n\n";                                 \
          echo -e "=================\n";                  \
          echo -e "  ++Build subdir $$d  target $(@)\n";  \
          make -f $$d/Makefile DIR=$$d TGT=$(@) $(@);     \
          y=$$?; if [ ! "x$$y" == "x0" ]; then                      \
            echo -e "\n  Error $$y: in top makefile\n"; exit 1; fi; \
          echo ;                                              \
          echo -e "  --Build subdir $$d  target $(@) done\n"; \
          echo -e "=================\n";                      \
        done

子make文件:

$ cat libs/Makefile

.phony: headers libs exes

headers libs exes:
        @echo -e "\n\n    **** " submake target $(@) " **** \n\n"

那个不下降的结果:

$ make

=================
  ++Build subdir libs  target headers
make[1]: Entering directory `/home/dev2/tmp/tt'

    ****  submake target headers  ****

make[1]: Leaving directory `/home/dev2/tmp/tt'

  --Build subdir libs  target headers done
=================

=================
  ++Build subdir libs  target exes
make[1]: Entering directory `/home/dev2/tmp/tt'

    ****  submake target exes  ****

make[1]: Leaving directory `/home/dev2/tmp/tt'
  --Build subdir libs  target exes done
=================

我希望它在中间有一个部分:

    ****  submake target libs  ****

[编辑] 问题是 .PHONY: 必须是大写的,正如回答者所建议的那样,我验证了。但是,make 的 windows 版本不需要这个。

【问题讨论】:

  • 我怀疑显示的输出是由这些 makefile 生成的。为什么要输入/home/dev2/tmp/tt
  • /home/dev2/tmp/tt是顶级目录吗?
  • 它可以在 Windows 机器上运行,而不是在 CentOS 机器上运行吗? libs 的大小写在虚假目标和目录之间是否不同?
  • 是的 /home/dev2/tmp/tt 是顶级目录。与在 makefile 中一样,它使用make -f 而不是make -C,打算从顶层目录构建所有内容,以便 gdb 以更完整的路径查看源文件或头文件。
  • libs 的情况可能不是问题所在。我在 Windows 上将所有 libs 更改为 LIBS,它仍然运行良好。因此,对于.phony目标,windows上的make一定是不区分大小写的。

标签: linux makefile gnu-make


【解决方案1】:

特殊目标区分大小写。要使 libs 等实际上成为虚假目标,您需要拼写 .PHONY 如下:

.PHONY: all headers libs exes

事实上,你有一个普通的规则和一个有点不寻常的目标!

【讨论】:

  • 已验证这是原因。唯一的问题是它在 Windows 上不区分大小写,使用 yagarto-tools 20100703 版本 3.81。
猜你喜欢
  • 1970-01-01
  • 2023-02-07
  • 2015-07-31
  • 2019-10-27
  • 1970-01-01
  • 2012-09-17
  • 2022-08-18
  • 2014-05-29
  • 1970-01-01
相关资源
最近更新 更多