Skip to content

Commit f62106d

Browse files
committed
Merge branch 'ab/make-optim-noop'
Makefile refactoring with a bit of suffixes rule stripping to optimize the runtime overhead. * ab/make-optim-noop: Makefiles: add and use wildcard "mkdir -p" template Makefile: add "$(QUIET)" boilerplate to shared.mak Makefile: move $(comma), $(empty) and $(space) to shared.mak Makefile: move ".SUFFIXES" rule to shared.mak Makefile: define $(LIB_H) in terms of $(FIND_SOURCE_FILES) Makefile: disable GNU make built-in wildcard rules Makefiles: add "shared.mak", move ".DELETE_ON_ERROR" to it scalar Makefile: use "The default target of..." pattern
2 parents 851d2f0 + 0b6d0bc commit f62106d

File tree

10 files changed

+165
-160
lines changed

10 files changed

+165
-160
lines changed

Documentation/Makefile

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Import tree-wide shared Makefile behavior and libraries
2+
include ../shared.mak
3+
14
# Guard against environment variables
25
MAN1_TXT =
36
MAN5_TXT =
@@ -215,38 +218,6 @@ DEFAULT_EDITOR_SQ = $(subst ','\'',$(DEFAULT_EDITOR))
215218
ASCIIDOC_EXTRA += -a 'git-default-editor=$(DEFAULT_EDITOR_SQ)'
216219
endif
217220

218-
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
219-
QUIET_SUBDIR1 =
220-
221-
ifneq ($(findstring $(MAKEFLAGS),w),w)
222-
PRINT_DIR = --no-print-directory
223-
else # "make -w"
224-
NO_SUBDIR = :
225-
endif
226-
227-
ifneq ($(findstring $(MAKEFLAGS),s),s)
228-
ifndef V
229-
QUIET = @
230-
QUIET_ASCIIDOC = @echo ' ' ASCIIDOC $@;
231-
QUIET_XMLTO = @echo ' ' XMLTO $@;
232-
QUIET_DB2TEXI = @echo ' ' DB2TEXI $@;
233-
QUIET_MAKEINFO = @echo ' ' MAKEINFO $@;
234-
QUIET_DBLATEX = @echo ' ' DBLATEX $@;
235-
QUIET_XSLTPROC = @echo ' ' XSLTPROC $@;
236-
QUIET_GEN = @echo ' ' GEN $@;
237-
QUIET_STDERR = 2> /dev/null
238-
QUIET_SUBDIR0 = +@subdir=
239-
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
240-
$(MAKE) $(PRINT_DIR) -C $$subdir
241-
242-
QUIET_LINT_GITLINK = @echo ' ' LINT GITLINK $<;
243-
QUIET_LINT_MANSEC = @echo ' ' LINT MAN SEC $<;
244-
QUIET_LINT_MANEND = @echo ' ' LINT MAN END $<;
245-
246-
export V
247-
endif
248-
endif
249-
250221
all: html man
251222

252223
html: $(DOC_HTML)
@@ -463,25 +434,11 @@ quick-install-html: require-htmlrepo
463434
print-man1:
464435
@for i in $(MAN1_TXT); do echo $$i; done
465436

466-
## Lint: Common
467-
.build:
468-
$(QUIET)mkdir $@
469-
.build/lint-docs: | .build
470-
$(QUIET)mkdir $@
471-
472437
## Lint: gitlink
473-
.build/lint-docs/gitlink: | .build/lint-docs
474-
$(QUIET)mkdir $@
475-
.build/lint-docs/gitlink/howto: | .build/lint-docs/gitlink
476-
$(QUIET)mkdir $@
477-
.build/lint-docs/gitlink/config: | .build/lint-docs/gitlink
478-
$(QUIET)mkdir $@
479438
LINT_DOCS_GITLINK = $(patsubst %.txt,.build/lint-docs/gitlink/%.ok,$(HOWTO_TXT) $(DOC_DEP_TXT))
480-
$(LINT_DOCS_GITLINK): | .build/lint-docs/gitlink
481-
$(LINT_DOCS_GITLINK): | .build/lint-docs/gitlink/howto
482-
$(LINT_DOCS_GITLINK): | .build/lint-docs/gitlink/config
483439
$(LINT_DOCS_GITLINK): lint-gitlink.perl
484440
$(LINT_DOCS_GITLINK): .build/lint-docs/gitlink/%.ok: %.txt
441+
$(call mkdir_p_parent_template)
485442
$(QUIET_LINT_GITLINK)$(PERL_PATH) lint-gitlink.perl \
486443
$< \
487444
$(HOWTO_TXT) $(DOC_DEP_TXT) \
@@ -492,23 +449,18 @@ $(LINT_DOCS_GITLINK): .build/lint-docs/gitlink/%.ok: %.txt
492449
lint-docs-gitlink: $(LINT_DOCS_GITLINK)
493450

494451
## Lint: man-end-blurb
495-
.build/lint-docs/man-end-blurb: | .build/lint-docs
496-
$(QUIET)mkdir $@
497452
LINT_DOCS_MAN_END_BLURB = $(patsubst %.txt,.build/lint-docs/man-end-blurb/%.ok,$(MAN_TXT))
498-
$(LINT_DOCS_MAN_END_BLURB): | .build/lint-docs/man-end-blurb
499453
$(LINT_DOCS_MAN_END_BLURB): lint-man-end-blurb.perl
500454
$(LINT_DOCS_MAN_END_BLURB): .build/lint-docs/man-end-blurb/%.ok: %.txt
455+
$(call mkdir_p_parent_template)
501456
$(QUIET_LINT_MANEND)$(PERL_PATH) lint-man-end-blurb.perl $< >$@
502457
.PHONY: lint-docs-man-end-blurb
503-
lint-docs-man-end-blurb: $(LINT_DOCS_MAN_END_BLURB)
504458

505459
## Lint: man-section-order
506-
.build/lint-docs/man-section-order: | .build/lint-docs
507-
$(QUIET)mkdir $@
508460
LINT_DOCS_MAN_SECTION_ORDER = $(patsubst %.txt,.build/lint-docs/man-section-order/%.ok,$(MAN_TXT))
509-
$(LINT_DOCS_MAN_SECTION_ORDER): | .build/lint-docs/man-section-order
510461
$(LINT_DOCS_MAN_SECTION_ORDER): lint-man-section-order.perl
511462
$(LINT_DOCS_MAN_SECTION_ORDER): .build/lint-docs/man-section-order/%.ok: %.txt
463+
$(call mkdir_p_parent_template)
512464
$(QUIET_LINT_MANSEC)$(PERL_PATH) lint-man-section-order.perl $< >$@
513465
.PHONY: lint-docs-man-section-order
514466
lint-docs-man-section-order: $(LINT_DOCS_MAN_SECTION_ORDER)
@@ -524,7 +476,4 @@ doc-l10n install-l10n::
524476
$(MAKE) -C po $@
525477
endif
526478

527-
# Delete the target file on error
528-
.DELETE_ON_ERROR:
529-
530479
.PHONY: FORCE

Makefile

Lines changed: 36 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# The default target of this Makefile is...
22
all::
33

4+
# Import tree-wide shared Makefile behavior and libraries
5+
include shared.mak
6+
47
# Define V=1 to have a more verbose compile.
58
#
69
# Define SHELL_PATH to a POSIX shell if your /bin/sh is broken.
@@ -830,12 +833,33 @@ GENERATED_H += hook-list.h
830833
.PHONY: generated-hdrs
831834
generated-hdrs: $(GENERATED_H)
832835

833-
LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
836+
## Exhaustive lists of our source files, either dynamically generated,
837+
## or hardcoded.
838+
SOURCES_CMD = ( \
839+
git ls-files \
840+
'*.[hcS]' \
841+
'*.sh' \
842+
':!*[tp][0-9][0-9][0-9][0-9]*' \
843+
':!contrib' \
844+
2>/dev/null || \
834845
$(FIND) . \
835-
-name .git -prune -o \
836-
-name t -prune -o \
837-
-name Documentation -prune -o \
838-
-name '*.h' -print)))
846+
\( -name .git -type d -prune \) \
847+
-o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
848+
-o \( -name contrib -type d -prune \) \
849+
-o \( -name build -type d -prune \) \
850+
-o \( -name 'trash*' -type d -prune \) \
851+
-o \( -name '*.[hcS]' -type f -print \) \
852+
-o \( -name '*.sh' -type f -print \) \
853+
| sed -e 's|^\./||' \
854+
)
855+
FOUND_SOURCE_FILES := $(shell $(SOURCES_CMD))
856+
857+
FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
858+
FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES))
859+
860+
COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
861+
862+
LIB_H = $(FOUND_H_SOURCES)
839863

840864
LIB_OBJS += abspath.o
841865
LIB_OBJS += add-interactive.o
@@ -1265,10 +1289,6 @@ endif
12651289
ALL_CFLAGS = $(DEVELOPER_CFLAGS) $(CPPFLAGS) $(CFLAGS)
12661290
ALL_LDFLAGS = $(LDFLAGS)
12671291

1268-
comma := ,
1269-
empty :=
1270-
space := $(empty) $(empty)
1271-
12721292
ifdef SANITIZE
12731293
SANITIZERS := $(foreach flag,$(subst $(comma),$(space),$(SANITIZE)),$(flag))
12741294
BASIC_CFLAGS += -fsanitize=$(SANITIZE) -fno-sanitize-recover=$(SANITIZE)
@@ -1981,39 +2001,6 @@ ifndef PAGER_ENV
19812001
PAGER_ENV = LESS=FRX LV=-c
19822002
endif
19832003

1984-
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
1985-
QUIET_SUBDIR1 =
1986-
1987-
ifneq ($(findstring w,$(MAKEFLAGS)),w)
1988-
PRINT_DIR = --no-print-directory
1989-
else # "make -w"
1990-
NO_SUBDIR = :
1991-
endif
1992-
1993-
ifneq ($(findstring s,$(MAKEFLAGS)),s)
1994-
ifndef V
1995-
QUIET_CC = @echo ' ' CC $@;
1996-
QUIET_AR = @echo ' ' AR $@;
1997-
QUIET_LINK = @echo ' ' LINK $@;
1998-
QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
1999-
QUIET_GEN = @echo ' ' GEN $@;
2000-
QUIET_LNCP = @echo ' ' LN/CP $@;
2001-
QUIET_XGETTEXT = @echo ' ' XGETTEXT $@;
2002-
QUIET_MSGFMT = @echo ' ' MSGFMT $@;
2003-
QUIET_GCOV = @echo ' ' GCOV $@;
2004-
QUIET_SP = @echo ' ' SP $<;
2005-
QUIET_HDR = @echo ' ' HDR $(<:hcc=h);
2006-
QUIET_RC = @echo ' ' RC $@;
2007-
QUIET_SPATCH = @echo ' ' SPATCH $<;
2008-
QUIET_SUBDIR0 = +@subdir=
2009-
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
2010-
$(MAKE) $(PRINT_DIR) -C $$subdir
2011-
export V
2012-
export QUIET_GEN
2013-
export QUIET_BUILT_IN
2014-
endif
2015-
endif
2016-
20172004
ifdef NO_INSTALL_HARDLINKS
20182005
export NO_INSTALL_HARDLINKS
20192006
endif
@@ -2194,16 +2181,6 @@ shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
21942181
strip: $(PROGRAMS) git$X
21952182
$(STRIP) $(STRIP_OPTS) $^
21962183

2197-
### Flags affecting all rules
2198-
2199-
# A GNU make extension since gmake 3.72 (released in late 1994) to
2200-
# remove the target of rules if commands in those rules fail. The
2201-
# default is to only do that if make itself receives a signal. Affects
2202-
# all targets, see:
2203-
#
2204-
# info make --index-search=.DELETE_ON_ERROR
2205-
.DELETE_ON_ERROR:
2206-
22072184
### Target-specific flags and dependencies
22082185

22092186
# The generic compilation pattern rule and automatically
@@ -2566,8 +2543,6 @@ ASM_SRC := $(wildcard $(OBJECTS:o=S))
25662543
ASM_OBJ := $(ASM_SRC:S=o)
25672544
C_OBJ := $(filter-out $(ASM_OBJ),$(OBJECTS))
25682545

2569-
.SUFFIXES:
2570-
25712546
$(C_OBJ): %.o: %.c GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)
25722547
$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
25732548
$(ASM_OBJ): %.o: %.S GIT-CFLAGS $(missing_dep_dirs) $(missing_compdb_dir)
@@ -2770,7 +2745,8 @@ all:: $(MOFILES)
27702745
endif
27712746

27722747
po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
2773-
$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
2748+
$(call mkdir_p_parent_template)
2749+
$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
27742750

27752751
LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
27762752
LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
@@ -2786,35 +2762,16 @@ NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS))
27862762
endif
27872763

27882764
perl/build/lib/%.pm: perl/%.pm GIT-PERL-DEFINES
2789-
$(QUIET_GEN)mkdir -p $(dir $@) && \
2765+
$(call mkdir_p_parent_template)
2766+
$(QUIET_GEN) \
27902767
sed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' \
27912768
-e 's|@@NO_GETTEXT@@|$(NO_GETTEXT_SQ)|g' \
27922769
-e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
27932770
< $< > $@
27942771

27952772
perl/build/man/man3/Git.3pm: perl/Git.pm
2796-
$(QUIET_GEN)mkdir -p $(dir $@) && \
2797-
pod2man $< $@
2798-
2799-
FIND_SOURCE_FILES = ( \
2800-
git ls-files \
2801-
'*.[hcS]' \
2802-
'*.sh' \
2803-
':!*[tp][0-9][0-9][0-9][0-9]*' \
2804-
':!contrib' \
2805-
2>/dev/null || \
2806-
$(FIND) . \
2807-
\( -name .git -type d -prune \) \
2808-
-o \( -name '[tp][0-9][0-9][0-9][0-9]*' -prune \) \
2809-
-o \( -name contrib -type d -prune \) \
2810-
-o \( -name build -type d -prune \) \
2811-
-o \( -name 'trash*' -type d -prune \) \
2812-
-o \( -name '*.[hcS]' -type f -print \) \
2813-
-o \( -name '*.sh' -type f -print \) \
2814-
| sed -e 's|^\./||' \
2815-
)
2816-
2817-
FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
2773+
$(call mkdir_p_parent_template)
2774+
$(QUIET_GEN)pod2man $< $@
28182775

28192776
$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
28202777
$(QUIET_GEN)$(RM) $@+ && \
@@ -2948,7 +2905,7 @@ test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(
29482905
all:: $(TEST_PROGRAMS) $(test_bindir_programs)
29492906

29502907
bin-wrappers/%: wrap-for-bin.sh
2951-
@mkdir -p bin-wrappers
2908+
$(call mkdir_p_parent_template)
29522909
$(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
29532910
-e 's|@@BUILD_DIR@@|$(shell pwd)|' \
29542911
-e 's|@@PROG@@|$(patsubst test-%,t/helper/test-%$(X),$(@F))$(patsubst git%,$(X),$(filter $(@F),$(BINDIR_PROGRAMS_NEED_X)))|' < $< > $@ && \
@@ -3025,9 +2982,6 @@ check: $(GENERATED_H)
30252982
exit 1; \
30262983
fi
30272984

3028-
FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
3029-
COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
3030-
30312985
%.cocci.patch: %.cocci $(COCCI_SOURCES)
30322986
$(QUIET_SPATCH) \
30332987
if test $(SPATCH_BATCH_SIZE) = 0; then \

config.mak.uname

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ vcxproj:
727727
git diff-index --cached --quiet HEAD --
728728

729729
# Make .vcxproj files and add them
730-
unset QUIET_GEN QUIET_BUILT_IN; \
731730
perl contrib/buildsystems/generate -g Vcxproj
732731
git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj
733732

contrib/scalar/Makefile

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
2-
QUIET_SUBDIR1 =
3-
4-
ifneq ($(findstring s,$(MAKEFLAGS)),s)
5-
ifndef V
6-
QUIET_GEN = @echo ' ' GEN $@;
7-
QUIET_SUBDIR0 = +@subdir=
8-
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
9-
$(MAKE) $(PRINT_DIR) -C $$subdir
10-
else
11-
export V
12-
endif
13-
endif
14-
15-
all:
1+
# The default target of this Makefile is...
2+
all::
3+
4+
# Import tree-wide shared Makefile behavior and libraries
5+
include ../../shared.mak
166

177
include ../../config.mak.uname
188
-include ../../config.mak.autogen

contrib/scalar/t/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Import tree-wide shared Makefile behavior and libraries
2+
include ../../../shared.mak
3+
14
# Run scalar tests
25
#
36
# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin

0 commit comments

Comments
 (0)