linux - 当 gnu make phony 目标恰好与目录名称相同时的行为

标签 linux makefile gnu-make

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

顶层生成文件:

$ 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

子生成文件:

$ 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  ****

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

最佳答案

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

.PHONY: all headers libs exes

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

关于linux - 当 gnu make phony 目标恰好与目录名称相同时的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292654/

相关文章:

linux - 使用 linux,我如何在/dev 目录之外创建一个设备文件,以允许我打开和读取它?

linux - 编译 MonoDevelop 4.2.3

git - 从 Makefile 跟踪分支更改

gcc - 在 Automake 中没有链接的情况下如何编译?

c - GNU gcc 编译器无法处理部分包含语句

postgresql - 如何在 Windows 7 (x64) 上安装 PgBouncer

linux - 使用 AWK 增加几天和几个月的日期

linux - 代码块输出不执行 linux

build - 如何不在输出中打印生成文件中的注释

Makefile 忽略段错误