Skip to content

Commit 92b88eb

Browse files
dschogitster
authored andcommitted
Makefile: use git ls-files to list header files, if possible
In d85b0df (Makefile: use `find` to determine static header dependencies, 2014-08-25), we switched from a static list of header files to a dynamically-generated one, asking `find` to enumerate them. Back in those days, we did not use `$(LIB_H)` by default, and many a `make` implementation seems smart enough not to run that `find` command in that case, so it was deemed okay to run `find` for special targets requiring this macro. However, as of ebb7baf (Makefile: add a hdr-check target, 2018-09-19), $(LIB_H) is part of a global rule and therefore must be expanded. Meaning: this `find` command has to be run upon every `make` invocation. In the presence of many a worktree, this can tax the developers' patience quite a bit. Even in the absence of worktrees or other untracked files and directories, the cost of I/O to generate that list of header files is simply a lot larger than a simple `git ls-files` call. Therefore, just like in 3353397 (Makefile: ask "ls-files" to list source files if available, 2011-10-18), we now prefer to use `git ls-files` to enumerate the header files to enumerating them via `find`, falling back to the latter if the former failed (which would be the case e.g. in a worktree that was extracted from a source .tar file rather than from a clone of Git's sources). This has one notable consequence: we no longer include `command-list.h` in `LIB_H`, as it is a generated file, not a tracked one, but that is easily worked around. Of the three sites that use `LIB_H`, two (`LOCALIZED_C` and `CHK_HDRS`) already handle generated headers separately. In the third, the computed-dependency fallback, we can just add in a reference to $(GENERATED_H). Likewise, we no longer include not-yet-tracked header files in `LIB_H`. Given the speed improvements, these consequences seem a comparably small price to pay. Signed-off-by: Johannes Schindelin <[email protected]> Acked-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36eb1cb commit 92b88eb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ VCSSVN_LIB = vcs-svn/lib.a
841841

842842
GENERATED_H += command-list.h
843843

844-
LIB_H = $(shell $(FIND) . \
844+
LIB_H := $(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
845+
$(FIND) . \
845846
-name .git -prune -o \
846847
-name t -prune -o \
847848
-name Documentation -prune -o \
@@ -2363,7 +2364,7 @@ else
23632364
# should _not_ be included here, since they are necessary even when
23642365
# building an object for the first time.
23652366

2366-
$(OBJECTS): $(LIB_H)
2367+
$(OBJECTS): $(LIB_H) $(GENERATED_H)
23672368
endif
23682369

23692370
exec-cmd.sp exec-cmd.s exec-cmd.o: GIT-PREFIX

0 commit comments

Comments
 (0)