Skip to content

Commit c234e8a

Browse files
avargitster
authored andcommitted
Makefile: make the "sparse" target non-.PHONY
Change the "sparse" target and its *.sp dependencies to be non-.PHONY. Before this change "make sparse" would take ~5s to re-run all the *.c files through "cgcc", after it it'll create an empty *.sp file sitting alongside the *.c file, only if the *.c file or its dependencies are newer than the *.sp is the *.sp re-made. We ensure that the recursive dependencies are correct by depending on the *.o file, which in turn will have correct dependencies by either depending on all header files, or under "COMPUTE_HEADER_DEPENDENCIES=yes" the headers it needs. This means that a plain "make sparse" is much slower, as we'll now need to make the *.o files just to create the *.sp files, but incrementally creating the *.sp files is *much* faster and less verbose, it thus becomes viable to run "sparse" along with "all" as e.g. "git rebase --exec 'make all sparse'". On my box with -j8 "make sparse" was fast before, or around 5 seconds, now it only takes that long the first time, and the common case is <100ms, or however long it takes GNU make to stat the *.sp file and see that all the corresponding *.c file and its dependencies are older. See 0bcd9ae (sparse: Fix errors due to missing target-specific variables, 2011-04-21) for the modern implementation of the sparse target being changed here. It is critical that we use -Wsparse-error here, otherwise the error would only show up once, but we'd successfully create the empty *.sp file, and running a second time wouldn't show the error. I'm therefore not putting it into SPARSE_FLAGS or SP_EXTRA_FLAGS, it's not optional, the Makefile logic won't behave properly without it. Appending to $@ without a move is OK here because we're using the .DELETE_ON_ERROR Makefile feature. See 7b76d6b (Makefile: add and use the ".DELETE_ON_ERROR" flag, 2021-06-29). GNU make ensures that on error this file will be removed. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 99c99ed commit c234e8a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
*.lib
225225
*.res
226226
*.sln
227+
*.sp
227228
*.suo
228229
*.ncb
229230
*.vcproj

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,11 +2903,13 @@ check-sha1:: t/helper/test-tool$X
29032903

29042904
SP_OBJ = $(patsubst %.o,%.sp,$(C_OBJ))
29052905

2906-
$(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
2906+
$(SP_OBJ): %.sp: %.c %.o GIT-CFLAGS
29072907
$(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) \
2908-
$(SPARSE_FLAGS) $(SP_EXTRA_FLAGS) $<
2908+
-Wsparse-error \
2909+
$(SPARSE_FLAGS) $(SP_EXTRA_FLAGS) $< && \
2910+
>$@
29092911

2910-
.PHONY: sparse $(SP_OBJ)
2912+
.PHONY: sparse
29112913
sparse: $(SP_OBJ)
29122914

29132915
EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/%
@@ -3234,6 +3236,7 @@ clean: profile-clean coverage-clean cocciclean
32343236
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
32353237
$(RM) $(TEST_PROGRAMS)
32363238
$(RM) $(FUZZ_PROGRAMS)
3239+
$(RM) $(SP_OBJ)
32373240
$(RM) $(HCC)
32383241
$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
32393242
$(RM) -r po/build/

0 commit comments

Comments
 (0)