gnu make phony目标恰好与目录名称相同时的行为 [英] the behavior when a gnu make phony target happens to be the same as a directory name

查看:50
本文介绍了gnu make phony目标恰好与目录名称相同时的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

makefile有一个虚假的目标 libs ,还有一个目录 libs .在一台机器上,它运行良好,而在另一台机器上,它没有进入 libs 目标的 libs 目录.在这两种情况下,gnu make版本均为3.81,但一个在Windows上,另一个在centos上.

A makefile has a phony target libs, and also a directory libs to descend into. On one machine it works well, and another it does not descend into libs directory for the libs target. In both cases the gnu make version is 3.81, but one on windows and another on a centos.

最上面的make文件:

The top make file:

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

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

I expected it to have a section in the middle with:

    ****  submake target libs  ****

问题是 .PHONY:必须大写,如回答者所建议的那样,我进行了验证.Windows版本的make不需要此功能.

The problem is that .PHONY: has to be in upper case, as the answerer suggests, and I verified. The windows version of make does not require this though.

推荐答案

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

Special targets are case-sensitive. To make libs etc actually be phony targets, you need to spell .PHONY thus:

.PHONY: all headers libs exes

实际上,您有一条普通规则,但目标名称有些不同!

As it is, you have an ordinary rule with a somewhat unusually-named target!

这篇关于gnu make phony目标恰好与目录名称相同时的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆