Combine the definitions of $(FIND_SOURCE_FILES) and $(LIB_H) to speed up the Makefile, as these are the two main expensive $(shell) commands that we execute unconditionally. When see what was in $(FOUND_SOURCE_FILES) that wasn't in $(LIB_H) via the ad-hoc test of: $(error $(filter-out $(LIB_H),$(filter %.h,$(ALL_SOURCE_FILES)))) $(error $(filter-out $(ALL_SOURCE_FILES),$(filter %.h,$(LIB_H)))) We'll get, respectively: Makefile:850: *** t/helper/test-tool.h. Stop. Makefile:850: *** . Stop. I.e. we only had a discrepancy when it came to t/helper/test-tool.h. In terms of correctness this was broken before, but now works: $ make t/helper/test-tool.hco HDR t/helper/test-tool.h This speeds things up a lot: $ git -c hyperfine.hook.setup= hyperfine -L rev HEAD~1,HEAD~0 -s 'make -j8 all NO_TCLTK=Y' 'make NO_TCLTK=Y' --war mup 10 -M 10 Benchmark 1: make NO_TCLTK=Y' in 'HEAD~1 Time (mean ± σ): 99.5 ms ± 0.5 ms [User: 83.4 ms, System: 20.7 ms] Range (min … max): 98.8 ms … 100.2 ms 10 runs Benchmark 2: make NO_TCLTK=Y' in 'HEAD~0 Time (mean ± σ): 69.4 ms ± 0.5 ms [User: 58.8 ms, System: 14.2 ms] Range (min … max): 68.9 ms … 70.3 ms 10 runs Summary 'make NO_TCLTK=Y' in 'HEAD~0' ran 1.43 ± 0.01 times faster than 'make NO_TCLTK=Y' in 'HEAD~1' Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- Makefile | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index a9fa9461613..eb1c944787b 100644 --- a/Makefile +++ b/Makefile @@ -821,12 +821,33 @@ GENERATED_H += hook-list.h .PHONY: generated-hdrs generated-hdrs: $(GENERATED_H) -LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \ +## Exhaustive lists of our source files, either dynamically generated, +## or hardcoded. +SOURCES_CMD = ( \ + git ls-files \ + '*.[hcS]' \ + '*.sh' \ + ':!*[tp][0-9][0-9][0-9][0-9]*' \ + ':!contrib' \ + 2>/dev/null || \ $(FIND) . \ - -name .git -prune -o \ - -name t -prune -o \ - -name Documentation -prune -o \ - -name '*.h' -print))) + \( -name .git -type d -prune \) \ + -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \ + -o \( -name contrib -type d -prune \) \ + -o \( -name build -type d -prune \) \ + -o \( -name 'trash*' -type d -prune \) \ + -o \( -name '*.[hcS]' -type f -print \) \ + -o \( -name '*.sh' -type f -print \) \ + | sed -e 's|^\./||' \ + ) +FOUND_SOURCE_FILES := $(shell $(SOURCES_CMD)) + +FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES)) +FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES)) + +COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES)) + +LIB_H = $(FOUND_H_SOURCES) LIB_OBJS += abspath.o LIB_OBJS += add-interactive.o @@ -2660,26 +2681,6 @@ perl/build/man/man3/Git.3pm: perl/Git.pm $(call mkdir_p_parent_template) $(QUIET_GEN)pod2man $< $@ -FIND_SOURCE_FILES = ( \ - git ls-files \ - '*.[hcS]' \ - '*.sh' \ - ':!*[tp][0-9][0-9][0-9][0-9]*' \ - ':!contrib' \ - 2>/dev/null || \ - $(FIND) . \ - \( -name .git -type d -prune \) \ - -o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \ - -o \( -name contrib -type d -prune \) \ - -o \( -name build -type d -prune \) \ - -o \( -name 'trash*' -type d -prune \) \ - -o \( -name '*.[hcS]' -type f -print \) \ - -o \( -name '*.sh' -type f -print \) \ - | sed -e 's|^\./||' \ - ) - -FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES)) - $(ETAGS_TARGET): $(FOUND_SOURCE_FILES) $(QUIET_GEN)$(RM) $@+ && \ echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \ @@ -2859,9 +2860,6 @@ check: $(GENERATED_H) exit 1; \ fi -FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES)) -COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES)) - %.cocci.patch: %.cocci $(COCCI_SOURCES) $(QUIET_SPATCH) \ if test $(SPATCH_BATCH_SIZE) = 0; then \ -- 2.34.0.796.g2c87ed6146a