Re: [PATCH 3/4] Makefile: Replace old suffix rules with pattern rules

Eli Zaretskii
2016-11-16T17:14:50Z

> Cc: gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 16 Nov 2016 16:56:02 +0000
>
> Given the shared ancestry, and the fact that GCC nowadays requires
> GNU make, I think it may be worth it to take a look at what
> does GCC's Makefile.in do.
>
> In this case, it has:
>
> ~~~
> # Suppress smart makes who think they know how to automake yacc and flex file
> .y.c:
> .l.c:
>
> # The only suffixes we want for implicit rules are .c and .o, so clear
> # the list and add them. This speeds up GNU Make, and allows -r to work.
> # For i18n support, we also need .gmo, .po, .pox.
> # This must come before the language makefile fragments to allow them to
> # add suffixes and rules of their own.
> .SUFFIXES:
> .SUFFIXES: .c .cc .o .po .pox .gmo
> ~~~
>
> I don't know why they still add some suffixes instead of relying
> on the pattern rules. Might just be legacy.

No, it's because of the built-in rules. They are by default
considered no matter which pattern rules you have in the Makefile,
because theoretically each .c file can be built from some other file
in any number of ways.

> This doesn't get rid of all the implicit rules in GNU make, however,
> because some default rules are pattern rules which are not affected by
> the .SUFFIXES special target.
>
> To get rid of all implicit rules in GNU make you have to either invoke
> make with the -r option [...], or else add this to your makefile:
>
> .SUFFIXES:
> %:: %,v
> %:: RCS/%,v
> %:: RCS/%
> %:: s.%
> %:: SCCS/s.%
> ~~~
>
> I'd be curious if this makes any difference in a "make" invocation
> that ends up building nothing (because all targets are already
> up to date).

It might produce a significant difference, but of course the
interesting case is when a small number of files need to be
recompiled.