git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/8] Makefile: disable GNU make built-in wildcard rules

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 17, 2021, 01:39 UTC
Message-ID
<patch-2.8-b0c63abe091-20211217T012902Z-avarab@gmail.com>
In-Reply-To
<cover-0.8-00000000000-20211217T012902Z-avarab@gmail.com>

Override built-in rules of GNU make that use a wildcard target. This can speeds things up significantly as we don't need to stat() so many files. GNU make does that by default to see if it can retrieve their contents from RCS or SCCS. See [1] for an old mailing list discussion about how to disable these.

The speed-up may wary. I've seen 1-10% depending on the speed of the local disk, caches, -jN etc. Running:

    strace -f -c -S calls make -j1 NO_TCLTK=Y

Shows that we reduce the number of syscalls we make, mostly in "stat" calls.

We could also invoke make with "-r" by setting "MAKEFLAGS = -r" early. Doing so might make us a bit faster still. But doing so is a much bigger hammer, since it will disable all built-in rules, some (all?) of which can be seen with:

    make -f/dev/null -p | grep -v -e ^# -e ^$

We may have something that relies on them, so let's go for the more isolated optimization here that gives us most or all of the wins.

1. https://lists.gnu.org/archive/html/help-make/2002-11/msg00063.html
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 shared.mak | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/shared.mak b/shared.mak
index 0170bb397ae..29f0e69ecb9 100644
--- a/shared.mak
+++ b/shared.mak
@@ -1,3 +1,14 @@
+### Remove GNU make implicit rules
+
+## This speeds things up since we don't need to look for and stat() a
+## "foo.c,v" every time a rule referring to "foo.c" is in play. See
+## "make -p -f/dev/null | grep ^%::'".
+%:: %,v
+%:: RCS/%,v
+%:: RCS/%
+%:: s.%
+%:: SCCS/s.%
+
 ### Flags affecting all rules
 
 # A GNU make extension since gmake 3.72 (released in late 1994) to
-- 
2.34.1.1119.g7a3fc8778ee
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 2 of 11 in “Makefile: optimize noop runs, add shared.mak”
  1. 0/8 Makefile: optimize noop runs, add shared.makÆvar Arnfjörð Bjarmason, Dec 17, 2021
  2. 2/8 Makefile: disable GNU make built-in wildcard rulesÆvar Arnfjörð Bjarmason, Dec 17, 2021
  3. 1/8 Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to itÆvar Arnfjörð Bjarmason, Dec 17, 2021
  4. 3/8 Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES)Ævar Arnfjörð Bjarmason, Dec 17, 2021
  5. 4/8 Makefile: move ".SUFFIXES" rule to shared.makÆvar Arnfjörð Bjarmason, Dec 17, 2021
  6. 5/8 Makefile: move $(comma), $(empty) and $(space) to shared.makÆvar Arnfjörð Bjarmason, Dec 17, 2021
  7. 6/8 Makefile: add "$(QUIET)" boilerplate to shared.makÆvar Arnfjörð Bjarmason, Dec 17, 2021
  8. 8/8 Makefiles: add and use wildcard "mkdir -p" templateÆvar Arnfjörð Bjarmason, Dec 17, 2021
  9. Eric SunshineDec 17, 2021
  10. Ævar Arnfjörð BjarmasonDec 24, 2021
  11. 7/8 Makefile: use $(wspfx) for $(QUIET...) in shared.makÆvar Arnfjörð Bjarmason, Dec 17, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.