Skip to content

Commit 8990624

Browse files
avargitster
authored andcommitted
Makefile: normalize clobbering & xargs for tags targets
Since the "tags", "TAGS" and "cscope.out" targets rely on piping into xargs with an "echo <list> | xargs" pattern, we need to make sure we're in an append mode. Unlike my recent change to make use of ".DELETE_ON_ERROR" in 7b76d6b (Makefile: add and use the ".DELETE_ON_ERROR" flag, 2021-06-29), we really do need the "rm $@+" at the beginning (note, not "rm $@"). This is because the xargs command may decide to invoke the program multiple times. We need to make sure we've got a union of its results at the end. For "ctags" and "etags" we used the "-a" flag for this, for cscope that behavior is the default. Its "-u" flag disables its equivalent of an implicit "-a" flag. Let's also consistently use the $@ and $@+ names instead of needlessly hardcoding or referring to more verbose names in the "tags" and "TAGS" rules. These targets could perhaps be improved in the future by factoring this "echo <list> | xargs" pattern so that we make intermediate tags files for each source file, and then assemble them into one "tags" file at the end. The etags manual page suggests that doing that (or perhaps just --update) might be counter-productive, in any case, the tag building is fast enough for me, so I'm leaving that for now. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 530a446 commit 8990624

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,18 +2730,19 @@ FIND_SOURCE_FILES = ( \
27302730
FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
27312731

27322732
$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
2733-
$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
2734-
echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
2735-
mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
2733+
$(QUIET_GEN)$(RM) $@+ && \
2734+
echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
2735+
mv $@+ $@
27362736

27372737
tags: $(FOUND_SOURCE_FILES)
2738-
$(QUIET_GEN)$(RM) tags+ && \
2739-
echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
2740-
mv tags+ tags
2738+
$(QUIET_GEN)$(RM) $@+ && \
2739+
echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o $@+ && \
2740+
mv $@+ $@
27412741

27422742
cscope.out: $(FOUND_SOURCE_FILES)
2743-
$(QUIET_GEN)$(RM) $@ && \
2744-
echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
2743+
$(QUIET_GEN)$(RM) $@+ && \
2744+
echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@+ -b && \
2745+
mv $@+ $@
27452746

27462747
.PHONY: cscope
27472748
cscope: cscope.out

0 commit comments

Comments
 (0)