Question:
How can I disable implicit rule searches on a prerequisite while still ensuring that the prerequisite actually exists?
Background:
Consider the following initial Makefile:
b: a
@echo MAKING B
cp a b
a is a file which is required in order to make b. If the file a exists, make b runs successfully. If it doesn't exist, we obtain the following error:
make: *** No rule to make target `a', needed by `b'. Stop.`
This is exactly what we expected, however on inspecting the output of make --debug=a b, we see that even when a exists, make is searching through pre-defined implicit rules fitting a in order to see whether it can be re-made. For example, if the file a.c happened to exist, then make would try to compile a.c to produce the file a. To prevent this, we define an explicit rule for a with an empty recipe. This gives us the updated Makefile:
a: ;
b: a
@echo MAKING B
cp a b
The problem now is that the recipe for make b runs even if a does not exist, which results in a failure. Is there any other way to indicate that a should exist, while not searching for implicit rules to build a? I would like to do this without giving a recipe for a which checks its existence.
a: ; [ -f $@ ] # a should existI.e. failmake bwith a mild hint. I've tried few ways to suppress implicit pattern rules or override them for a with static patter, but I'd then end up seeing same thing as your emptya, i.e. it'd just dive into makingbwithoutabeing present. - Ondrej K.Makefile, but to get desired behavior for this specific case, you could run make with-ror add empty.SUFFIXES:to yourMakefile. Is that acceptable? Or too far reaching? - Ondrej K..SUFFIXESwould work, but-ris too far reaching. I might want to retain built-in rules for other targets. - justinpc.SUFFIXESand would similarly like to keep it as it is. Let's say I did set.SUFFIXESto empty or used-r, I might still have defined an implicit rule myself whose target matchesaand which in this case I would not want to match. - justinpc