Skip to content

Commit 7b76d6b

Browse files
avargitster
authored andcommitted
Makefile: add and use the ".DELETE_ON_ERROR" flag
Use the GNU make ".DELETE_ON_ERROR" flag in our main Makefile, as we already do in the Documentation/Makefile since db10fc6 (doc: simplify Makefile using .DELETE_ON_ERROR, 2021-05-21). Now if a command to make X fails X will be removed, the default behavior of GNU make is to only do so if "make" itself is interrupted with a signal. E.g. if we now intentionally break one of the rules with: - mv $@+ $@ + mv $@+ $@ && \ + false We'll get output like: $ make git CC git.o LINK git make: *** [Makefile:2179: git] Error 1 make: *** Deleting file 'git' $ file git git: cannot open `git' (No such file or directory) Before this change we'd leave the file in place in under this scenario. As in db10fc6 this allows us to remove patterns of removing leftover $@ files at the start of rules, since previous failing runs of the Makefile won't have left those littered around anymore. I'm not as confident that we should be replacing the "mv $@+ $@" pattern entirely, since that means that external programs or one of our other Makefiles might race and get partial content. I'm not changing $(REMOTE_CURL_ALIASES) since that uses a ln/ln -s/cp dance, and would require the addition of "-f" flags if the "rm" at the start was removed. I've also got plans to fix that ln/ln -s/cp pattern in another series. For $(LIB_FILE) and $(XDIFF_LIB) we can rely on the "c" (create) being present in ARFLAGS. I'm not changing "$(ETAGS_TARGET)", "tags" and "cscope" because they've got a messy combination of removing "$@+" not "$@" at the beginning, or "$@*". I'm also addressing those in another series. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebf3c04 commit 7b76d6b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Makefile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,16 @@ shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
21602160
strip: $(PROGRAMS) git$X
21612161
$(STRIP) $(STRIP_OPTS) $^
21622162

2163+
### Flags affecting all rules
2164+
2165+
# A GNU make extension since gmake 3.72 (released in late 1994) to
2166+
# remove the target of rules if commands in those rules fail. The
2167+
# default is to only do that if make itself receives a signal. Affects
2168+
# all targets, see:
2169+
#
2170+
# info make --index-search=.DELETE_ON_ERROR
2171+
.DELETE_ON_ERROR:
2172+
21632173
### Target-specific flags and dependencies
21642174

21652175
# The generic compilation pattern rule and automatically
@@ -2243,7 +2253,6 @@ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
22432253
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\
22442254
$(perllibdir_SQ)
22452255
define cmd_munge_script
2246-
$(RM) $@ $@+ && \
22472256
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
22482257
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
22492258
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
@@ -2313,7 +2322,7 @@ endif
23132322
PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
23142323

23152324
$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
2316-
$(QUIET_GEN)$(RM) $@ $@+ && \
2325+
$(QUIET_GEN) \
23172326
sed -e '1{' \
23182327
-e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
23192328
-e ' r GIT-PERL-HEADER' \
@@ -2333,7 +2342,7 @@ GIT-PERL-DEFINES: FORCE
23332342
fi
23342343

23352344
GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile
2336-
$(QUIET_GEN)$(RM) $@ && \
2345+
$(QUIET_GEN) \
23372346
INSTLIBDIR='$(perllibdir_SQ)' && \
23382347
INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
23392348
INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
@@ -2359,7 +2368,7 @@ git-instaweb: git-instaweb.sh GIT-SCRIPT-DEFINES
23592368
mv $@+ $@
23602369
else # NO_PERL
23612370
$(SCRIPT_PERL_GEN) git-instaweb: % : unimplemented.sh
2362-
$(QUIET_GEN)$(RM) $@ $@+ && \
2371+
$(QUIET_GEN) \
23632372
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
23642373
-e 's|@@REASON@@|NO_PERL=$(NO_PERL)|g' \
23652374
unimplemented.sh >$@+ && \
@@ -2373,23 +2382,22 @@ $(SCRIPT_PYTHON_GEN): GIT-BUILD-OPTIONS
23732382
ifndef NO_PYTHON
23742383
$(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
23752384
$(SCRIPT_PYTHON_GEN): % : %.py
2376-
$(QUIET_GEN)$(RM) $@ $@+ && \
2385+
$(QUIET_GEN) \
23772386
sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
23782387
$< >$@+ && \
23792388
chmod +x $@+ && \
23802389
mv $@+ $@
23812390
else # NO_PYTHON
23822391
$(SCRIPT_PYTHON_GEN): % : unimplemented.sh
2383-
$(QUIET_GEN)$(RM) $@ $@+ && \
2392+
$(QUIET_GEN) \
23842393
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
23852394
-e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
23862395
unimplemented.sh >$@+ && \
23872396
chmod +x $@+ && \
23882397
mv $@+ $@
23892398
endif # NO_PYTHON
23902399

2391-
CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \
2392-
sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
2400+
CONFIGURE_RECIPE = sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
23932401
configure.ac >configure.ac+ && \
23942402
autoconf -o configure configure.ac+ && \
23952403
$(RM) configure.ac+
@@ -2514,7 +2522,6 @@ endif
25142522
ifeq ($(GENERATE_COMPILATION_DATABASE),yes)
25152523
all:: compile_commands.json
25162524
compile_commands.json:
2517-
@$(RM) $@
25182525
$(QUIET_GEN)sed -e '1s/^/[/' -e '$$s/,$$/]/' $(compdb_dir)/*.o.json > $@+
25192526
@if test -s $@+; then mv $@+ $@; else $(RM) $@+; fi
25202527
endif
@@ -2587,10 +2594,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
25872594
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
25882595

25892596
$(LIB_FILE): $(LIB_OBJS)
2590-
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2597+
$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
25912598

25922599
$(XDIFF_LIB): $(XDIFF_OBJS)
2593-
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2600+
$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
25942601

25952602
export DEFAULT_EDITOR DEFAULT_PAGER
25962603

0 commit comments

Comments
 (0)