0

I'd like to declare a-test, b-test, c-test as phony targets. Can I declare:

.PHONY : *-test

instead of

.PHONY : a-test b-test c-test

Also, how about declaring .PHONY : %-test?

Leedehai
  • 3,660
  • 3
  • 21
  • 44
  • Why do you want to do this? Sounds like an XY problem. – G.M. Aug 13 '18 at 07:47
  • Becase a `a-test` is not a file. It's just an action that runs a bunch of programs. Same case with other `*-test`. And I don't know what XY problem is. – Leedehai Aug 13 '18 at 08:01
  • If the aim is to avoid having to manually specify the `.PHONY` target names multiple times then you might want to look at ["Is there a mechanism for something like python decorators in GNU Makefiles?"](https://stackoverflow.com/questions/51726975/is-there-a-mechanism-for-something-like-python-decorators-in-gnu-makefiles). – G.M. Aug 13 '18 at 08:13
  • @G.M. ouch.. thanks, con-f-use's solution there stands out for its sheer smartness and unreadability.. – Leedehai Aug 13 '18 at 08:18
  • The [XY-problem](https://en.wikipedia.org/wiki/XY_problem) which @G.M. rightfully points out here is that we both don't find an obvious or simple problem where a pattern of phony targets would make anyhing easier/better in a makefile. So maybe we could help better if you explained what you really want to solve with your phony-pattern solution instead of us trying to search for an unfitting patch to the `.PHONY` mechanism. – Vroomfondel Aug 13 '18 at 09:36
  • @Vroomfondel the problem I have is I have more than three `*-test` targets, do I need to list them all in `.PHONY`, one by one? – Leedehai Aug 13 '18 at 09:39
  • Are their execution recipes and their dependencies identical/analogous? I suppose not, so is it such a big deal to write an extra ` .PHONY:` for each of them? IOW which percentage of saved makefile source stands in favour of the approach you are searching? – Vroomfondel Aug 13 '18 at 09:55
  • You only need to use `.PHONY` if there is a file of the same name. For example, if you had a file called `all`, `.PHONY all` would mean `make` would not look at the modification time of `all` for `make all`. It would consider the file `all` not to exist. – shawnhcorey Aug 13 '18 at 14:09
  • I can't find references to support it, but `.PHONY: *-test` seems to work. – Beta Aug 13 '18 at 20:21

0 Answers0