Bartlomiej Grzeskowiak
Bartlomiej Grzeskowiak

Reputation: 1019

Makefile: Match-Anything Pattern Rule

I have a main Makefile that calls Makefiles placed in subfolders. For testing purposes I would like to add Match-Anything rule at the end of main Makefile. This rule would be:

%:
     make -e -C subdir $@

Are there any contrarguments for such a rule?

Upvotes: 0

Views: 118

Answers (1)

MadScientist
MadScientist

Reputation: 100836

I think you meant "con", as in "pro or con", not "cont". "Con" is short for the Latin "contra".

For your question, the downside of adding a new "match anything" rule is that any file that doesn't exist, will try to be created using this rule. For example suppose you run include foo.mk and foo.mk doesn't exist... make will attempt to build foo.mk by running your rule. Basically it can be confusing. It's possible there could be some performance impact; if you run make -d and examine it you should see if your match-anything rule is being used at all during a normal build. I'm not sure if there are any other serious downsides.

By the way you should always only use the make variable $(MAKE) when invoking a sub-make in a recipe; never use the raw make command.

Upvotes: 1

Related Questions