On 2024-01-27 11:00, Antonio Diaz Diaz wrote:
> Hello,
> 
> In order to increase the efficiency of the build, I added empty recipes to my 
> makefiles to prevent 'make' from trying to remake source files:

Make does not remake any files which exist already and which are not the 
targets of rules.

If it is trying to update source files, it's because you introduced a rule for 
it somewhere; you must remove that rule.

Or, if the rule is necessary for certain files, you must make sure it only 
applies to those files.



 
> $(VPATH)/configure $(VPATH)/Makefile.in $(VPATH)/doc/$(pkgname).texi : ;
> %.h %.cc : ;
> 
> It works. The output of 'make -d' is reduced to less than 1/4 of its original 
> size.
> 
> The problem is that the second rule above breaks detection of invalid targets:
> 
> Expected:
> $ make -n foobar
> make: *** No rule to make target `foobar'.  Stop.
> 
> Obtained:
> $ make -n foobar
> g++  -Wall -W -O2 -c -o foobar.o foobar.cc
> cc   foobar.o   -o foobar
> rm foobar.o foobar.cc

Is this coming from the built-in rule for making whatever from whatever.cc?

If you don't want that, it might be a good idea to remove the built-in rules
using:

.SUFFIXES:

and then don't write such a rule yourself. Write only direct rules for
your supported targets, not to make any prog from a prog.cc.

> Is there a way to tell make with an implicit rule to not try to remake source 
> files? For example files with extensions .h and .cc.

Don't have .h and .cc files as the left hand side of any direct rule.

If you have implicit rules that can generate .cc and .h files, they won't be
used, except for those files which have a matching prerequisite (which
is out of date).

For instance, if we have a rule like this:

  %.cc : %.y    # used for making parser.cc out of parser.y

this will not try to make every one of your source files from a
corresponding .y file. Only those which have such a file!
If there is no such file, the rule doesn't match.

If a foo.cc file is needed, and exists, and is not accompanied
by a foo.y, make will not try to make it from a nonexistent
foo.y and complain that foo.y doesn't exist. It will just not
apply that pattern rule.

So the problem is somewhere else.

Reply via email to