[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proper usage of multiple rules for the same targets
From: |
Tiphaine Turpin |
Subject: |
Proper usage of multiple rules for the same targets |
Date: |
Tue, 4 Sep 2018 09:25:02 +0000 |
Hello,
I have discovered an issue while using an additional rule with just
prerequisites, as suggested in section "Multiple Rules for One Target" of the
documentation, when the "main" rule is a pattern rule. The problem it that this
changes the behavior in case of missing source files in a non intuitive way.
Here is a minimal example Makefile:
%.t: %.x
echo using implicit rule
foo.t : additional_prerequisite
If I run 'make foo.t', then
- if foo.x and additional_prerequisite both exist, then the pattern rule is
executed as expected, and outputs 'using implicit rule'
- if foo.x is missing then the build succeeds with "Nothing to be done for
'foo.t'."
However, what I would actually want is to get an error, as the one I get if I
remove the additional prerequisite rule: "No rule to make target 'foo.t'."
I found the explanation to this in the documentation: if foo.x is missing then
the pattern rule is not "enabled" because a pattern rule only matches when "all
prerequisites in that rule either exist or can be built" as mentioned in
sections "How Patterns Match" and "Using Implicit Rules". The latter
additionally says:
'A file “can be made” if it is mentioned explicitly in the makefile as a target
or a prerequisite, or if an implicit rule can be recursively found for how to
make it.'
In my case, foo.x clearly can't be made, so the pattern rule just does not
apply and the additional rule is interpreted as "making" foo.t by doing nothing.
So, a simple solution is to make sure that foo.x exists or can be made, for
example with another pattern rule:
%.x:
$(error no $@)
Could anyone suggest another approach ? Is it better to avoid additional rules
for this purpose, adding prerequisites to the pattern rule instead ? Is there a
way to define a rule as "dependency-only", so that it can't be used to actually
make its target using the implicit "no-op" reciepe ?
Thanks,
Tiphaine Turpin
- Proper usage of multiple rules for the same targets,
Tiphaine Turpin <=
- Re: Proper usage of multiple rules for the same targets, Sébastien Hinderer, 2018/09/04
- Re: Proper usage of multiple rules for the same targets, Tiphaine Turpin, 2018/09/05
- Re: Proper usage of multiple rules for the same targets, Sébastien Hinderer, 2018/09/05
- Re: Proper usage of multiple rules for the same targets, Max Gautier, 2018/09/05
- Re: Proper usage of multiple rules for the same targets, Tiphaine Turpin, 2018/09/06
- Re: Proper usage of multiple rules for the same targets, Sébastien Hinderer, 2018/09/06
- Re: Proper usage of multiple rules for the same targets, Paul Smith, 2018/09/06
- Re: Proper usage of multiple rules for the same targets, Thomas Martitz, 2018/09/06