2

Makefile:

SHELL := /bin/bash

all:

.PHONY: /home/% /home/dhp

/home/%:
        @echo do user $* USERRRRRR

plop: /home/dhp
        @echo plop

Shell:

# ll /home/
total 4
drwxr-xr-x 3 dhp dhp 4096 Mar 22 08:53 dhp
# make plop
plop

I know the topic have been asked many times, and the answer is in https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html https://www.gnu.org/software/make/manual/html_node/Special-Targets.html https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html#Chained-Rules but I don't understand why in my case USERRRRRR string is not printed. /home/dhp is a direct dep of my target, and, due to .PHONY it should be run even if file exists.

If I have no other choice, I may accept to make /home/%: depend on a very fresh file (which will be always more recent than /home/% by using, for example, the lock of PID file of current process, or depend on a virtual target which will never create anny file), but I would consider that as dirty. I don't think .INTERMEDIATE can help here.

EDIT: more tests:

SHELL := /bin/bash

all:

.PHONY: FORCE

.PHONY: /home/%

.PHONY: /home/dhp

FORCE:

/home/%: FORCE
        @echo do user $* USERRRRRR

plop: /home/dhp
        @echo plop

=>

# make plop
plop

...

SHELL := /bin/bash

all:

.PHONY: FORCE

FORCE:

/home/%: FORCE
        @echo do user $* USERRRRRR

plop: /home/dhp
        @echo plop

=>

# make plop
do user dhp USERRRRRR
plop

so, making my target phony prevents from running it ? This is strictly the opposite of what the documentation states:

When it is time to consider such a target, make will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is.

  • Possible duplicate of [in a makefile, declaring a phony target as a wildcard](http://stackoverflow.com/questions/11118197/in-a-makefile-declaring-a-phony-target-as-a-wildcard) – arved Mar 23 '17 at 11:51
  • After reading docs again, I have the confirmation that .PHONY can be used for real files, but, works only for targets specified on the command line, not for deps, dispite what is said in http://stackoverflow.com/questions/11118197/in-a-makefile-declaring-a-phony-target-as-a-wildcard , I found this in the doc: (see 2nd link) "When it is time to consider such a target, make will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is". In 1st link: "clean target will not work [....] if a file named clean is ever created" – Benoit-Pierre DEMAINE Mar 23 '17 at 15:39
  • Probably answer: 2 mistakes: -1- .PHONY seems to not accept wildcards (%), not sure it behaves properly when used with variables. -2- the target I want to run each time must not be phony itself, but, depend on a phony empty target: [link](http://bashdb.sourceforge.net/remake/make.html/Phony-Targets-Prerequisites.html) -3- folders seem to not be considered as files (unless PHONY prevents from seeing the directory at all). The base of my problem is that I want to always run a target that contains a wildcard (%) which can not be set as PHONY. Using FORCE has side effects when using $^ for inputs. – Benoit-Pierre DEMAINE Mar 23 '17 at 16:50
  • Possible duplicate of https://stackoverflow.com/questions/3095569/why-are-phony-implicit-pattern-rules-not-triggered – JohnLM May 11 '18 at 12:27
  • JohnLM, yes it looks like it. Thanks, because your link seems to provide a solution. I don't have time to dig the code now, and check it works for my project (which still bugs because of this), but after a quick reading ... looks like you are right. Not sure what's the policy of StackOverFlow for dups; may they remove this/my thread completely (please don't) ? or mark it as solved in doubt ? – Benoit-Pierre DEMAINE May 20 '18 at 17:53

0 Answers0