the behavior when a gnu make phony target happens to be the same as a directory name

不问归期 提交于 2020-01-14 05:31:05

问题


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.

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

The sub make file:

$ cat libs/Makefile

.phony: headers libs exes

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

That result that does not descend:

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

[Edit] 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.


回答1:


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!



来源:https://stackoverflow.com/questions/25292654/the-behavior-when-a-gnu-make-phony-target-happens-to-be-the-same-as-a-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!