[PATCH 0/3] Makefile: "make tags" fixes & cleanup

STALE1836d

Revision v1 of 4 in this series.

40 messages, 7 authors, 2021-08-04 · open the first message on its own page

[PATCH 0/3] Makefile: "make tags" fixes & cleanup

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-22 14:21:32

A small series to fix the various "tags" targets, i.e. "make tags TAGS
cscope". We'll now properly detect their dependencies, so we don't
needlessly run them every time. I have this as part of my standard
"make git" command, so doing nothing when we have nothing to do is
preferrable, especially when my editor will eagerly reload the TAGS
file every time it changes.

As noted in 3/3 this is better on top of my just-submitted
.DELETE_ON_ERROR change[1], but will also work independently of that
patch/series.

1. https://lore.kernel.org/git/patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (3):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: fix "cscope" target to refer to cscope.out
  Makefile: don't use "FORCE" for tags targets

 .gitignore |  2 +-
 Makefile   | 31 +++++++++++++++++--------------
 2 files changed, 18 insertions(+), 15 deletions(-)

-- 
2.32.0.599.g3967b4fa4ac

[PATCH 1/3] Makefile: move ".PHONY: cscope" near its target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-22 14:21:35

Move the ".PHONY: cscope" rule to live alongside the "cscope" target
itself, not to be all the way near the bottom where we define the
"FORCE" rule.

That line was last modified in 2f76919517e (MinGW: avoid collisions
between "tags" and "TAGS", 2010-09-28).

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index c3565fc0f8f..4dd9711a653 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,6 +2737,7 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+.PHONY: cscope
 cscope:
 	$(RM) cscope*
 	$(FIND_SOURCE_FILES) | xargs cscope -b
@@ -3245,7 +3246,7 @@ endif
 
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
-.PHONY: FORCE cscope
+.PHONY: FORCE
 
 ### Check documentation
 #
-- 
2.32.0.599.g3967b4fa4ac

[PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-22 14:21:36

The cscope target added in a2a9150bf06 (makefile: Add a cscope target,
2007-10-06) has for some reason been referring to cscope* instead of
cscope.out. Let's generate the cscope.out file directly so we don't
need to speculate.

The "-fcscope.out" (note, no whitespace) argument is enabled by
default on my system's cscope 15.9, but let's provide it explicitly
for good measure.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 .gitignore | 2 +-
 Makefile   | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index 311841f9bed..d74029c1ca7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -217,7 +217,7 @@
 /.vscode/
 /tags
 /TAGS
-/cscope*
+/cscope.out
 /compile_commands.json
 *.hcc
 *.obj
diff --git a/Makefile b/Makefile
index 4dd9711a653..25d2a3e5ddc 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,10 +2737,11 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+cscope.out:
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(RM) cscope*
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
 
 ### Detect prefix changes
 TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
@@ -3211,7 +3212,7 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) $(HCC)
 	$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
 	$(RM) -r po/build/
-	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope*
+	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope.out
 	$(RM) -r .dist-tmp-dir .doc-tmp-dir
 	$(RM) $(GIT_TARNAME).tar.gz
 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
-- 
2.32.0.599.g3967b4fa4ac

[PATCH 3/3] Makefile: don't use "FORCE" for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-22 14:21:37

Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
targets, instead make them depend on whether or not the relevant
source files have changed.

I'm also removing the "-o" option from them, that seems to have been
cargo-culted when they were initially added in f81e7c626f3 (Makefile:
Add TAGS and tags targets, 2006-03-18). It would make sense to use
that option if we had been appending to tag files, it doesn't make any
sense that it was used after we'd just removed the files file being
appended to.

This will potentially cause a partial file to be left behind if the
command dies, but my in-flight series to use the ".DELETE_ON_ERROR"
flag in the Makefile[1] will make that problem go away. I think even
without that it's not problem we need to worry about in these cases.

1. https://lore.kernel.org/git/patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
index 25d2a3e5ddc..89d261230fb 100644
--- a/Makefile
+++ b/Makefile
@@ -2727,18 +2727,19 @@ FIND_SOURCE_FILES = ( \
 		| sed -e 's|^\./||' \
 	)
 
-$(ETAGS_TARGET): FORCE
-	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
-	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
+FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
 
-tags: FORCE
-	$(QUIET_GEN)$(RM) tags+ && \
-	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
-	mv tags+ tags
+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
+	xargs etags -o $@
+
+tags: $(FOUND_SOURCE_FILES)
+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
+	xargs ctags -o $@
 
 cscope.out:
-	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
+	xargs cscope -f$@ -b
 
 .PHONY: cscope
 cscope: cscope.out
@@ -2922,7 +2923,7 @@ check: config-list.h command-list.h
 		exit 1; \
 	fi
 
-FOUND_C_SOURCES = $(filter %.c,$(shell $(FIND_SOURCE_FILES)))
+FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
 COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
-- 
2.32.0.599.g3967b4fa4ac

Re: [PATCH 0/3] Makefile: "make tags" fixes & cleanup

From: Taylor Blau <hidden>
Date: 2021-06-22 15:16:33

On Tue, Jun 22, 2021 at 04:21:24PM +0200, Ævar Arnfjörð Bjarmason wrote:
A small series to fix the various "tags" targets, i.e. "make tags TAGS
cscope". We'll now properly detect their dependencies, so we don't
needlessly run them every time. I have this as part of my standard
"make git" command, so doing nothing when we have nothing to do is
preferrable, especially when my editor will eagerly reload the TAGS
file every time it changes.
:-). Very nice.
As noted in 3/3 this is better on top of my just-submitted
.DELETE_ON_ERROR change[1], but will also work independently of that
patch/series.
I took a look at this and [1], and I agree that 3/3 is probably better
applied after [1], since it doesn't leave any gap between the existing
behavior of ">$@+ && mv $@+ $@" and ">$@" with .DELETE_ON_ERROR.

But I don't feel strongly about the order in which the two are applied.
Your 3/3 without [1] isn't wrong, it just leaves us the opportunity to
permanently leave around a broken tags file permanently, whereas having
[1] applied ahead of time means that the broken tags file is only
visible racily.

I reviewed these patches carefully, and they look good to me. I'm
delighted that `make tags` is no longer PHONY.

    Reviewed-by: Taylor Blau [off-list ref]

Thanks,
Taylor

Re: [PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Jeff King <hidden>
Date: 2021-06-22 19:25:32

On Tue, Jun 22, 2021 at 04:21:26PM +0200, Ævar Arnfjörð Bjarmason wrote:
The cscope target added in a2a9150bf06 (makefile: Add a cscope target,
2007-10-06) has for some reason been referring to cscope* instead of
cscope.out. Let's generate the cscope.out file directly so we don't
need to speculate.

The "-fcscope.out" (note, no whitespace) argument is enabled by
default on my system's cscope 15.9, but let's provide it explicitly
for good measure.
I don't use cscope myself, but it can generate other files (e.g., with
"-q"). It looks like we don't even allow people to set $(CSCOPE),
though, so that shouldn't ever happen.

(I wonder if anybody even really uses cscope. I wanted to love it as a
better form of ctags, but I have always found it so baroque and
complicated that it ends up being a waste of my time to try it).
+cscope.out:
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(RM) cscope*
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
This drops the $(RM). Does cscope always overwrite the output file, or
does it append? Just trying "cscope -b foo.c; cscope -b bar.c", it looks
like it overwrites. Which makes your patch correct, but that existing
"xargs" is somewhat questionable (if it splits into two commands, the
first half will get dropped).

-Peff

Re: [PATCH 3/3] Makefile: don't use "FORCE" for tags targets

From: Jeff King <hidden>
Date: 2021-06-22 19:28:10

On Tue, Jun 22, 2021 at 04:21:27PM +0200, Ævar Arnfjörð Bjarmason wrote:
Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
targets, instead make them depend on whether or not the relevant
source files have changed.

I'm also removing the "-o" option from them, that seems to have been
cargo-culted when they were initially added in f81e7c626f3 (Makefile:
Add TAGS and tags targets, 2006-03-18). It would make sense to use
that option if we had been appending to tag files, it doesn't make any
sense that it was used after we'd just removed the files file being
appended to.
You mean "-a" in this second paragraph, right?

I think it would help if xargs splits the source file list across
multiple invocations of the command.

-Peff

Re: [PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Chris Torek <hidden>
Date: 2021-06-22 19:49:24

On Tue, Jun 22, 2021 at 12:26 PM Jeff King [off-list ref] wrote:
(I wonder if anybody even really uses cscope. I wanted to love it as a
better form of ctags, but I have always found it so baroque and
complicated that it ends up being a waste of my time to try it).
I use cscope all the time, from vim.  If you use vim, you'll probably want
cscope_maps.vim.

(Sadly, cscope is not very good at C++.)

I think you're right about the xargs issue here.

Chris

RE: [PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Felipe Contreras <hidden>
Date: 2021-06-23 19:26:04

Ævar Arnfjörð Bjarmason wrote:
quoted hunk
--- a/Makefile
+++ b/Makefile
@@ -2737,10 +2737,11 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+cscope.out:
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(RM) cscope*
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
The reason for the $(RM) removal is not explained in the commit message.

Otherwise the pach looks good to me.

-- 
Felipe Contreras

RE: [PATCH 3/3] Makefile: don't use "FORCE" for tags targets

From: Felipe Contreras <hidden>
Date: 2021-06-23 19:49:14

Ævar Arnfjörð Bjarmason wrote:
Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
targets, instead make them depend on whether or not the relevant
source files have changed.
Very nice.
I'm also removing the "-o" option from them,
As Jeff already pointed out, this is probably "-a".

Other than that looks good to me.

-- 
Felipe Contreras

Re: [PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Felipe Contreras <hidden>
Date: 2021-06-23 19:51:08

Jeff King wrote:
I don't use cscope myself, but it can generate other files (e.g., with
"-q"). It looks like we don't even allow people to set $(CSCOPE),
though, so that shouldn't ever happen.

(I wonder if anybody even really uses cscope.
I do. I don't use it regularly, as I find `git grep` sufficient most of
the time, but sometimes I do use cscope.

-- 
Felipe Contreras

Re: [PATCH 2/3] Makefile: fix "cscope" target to refer to cscope.out

From: Felipe Contreras <hidden>
Date: 2021-06-23 19:54:07

Chris Torek wrote:
On Tue, Jun 22, 2021 at 12:26 PM Jeff King [off-list ref] wrote:
quoted
(I wonder if anybody even really uses cscope. I wanted to love it as a
better form of ctags, but I have always found it so baroque and
complicated that it ends up being a waste of my time to try it).
I use cscope all the time, from vim.  If you use vim, you'll probably want
cscope_maps.vim.
Or just set cscopetag.

-- 
Felipe Contreras

Re: [PATCH 0/3] Makefile: "make tags" fixes & cleanup

From: Junio C Hamano <hidden>
Date: 2021-06-29 06:29:27

Ævar Arnfjörð Bjarmason  [off-list ref] writes:
A small series to fix the various "tags" targets, i.e. "make tags TAGS
cscope". We'll now properly detect their dependencies, so we don't
needlessly run them every time. I have this as part of my standard
"make git" command, so doing nothing when we have nothing to do is
preferrable, especially when my editor will eagerly reload the TAGS
file every time it changes.

As noted in 3/3 this is better on top of my just-submitted
.DELETE_ON_ERROR change[1], but will also work independently of that
patch/series.

1. https://lore.kernel.org/git/patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (3):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: fix "cscope" target to refer to cscope.out
  Makefile: don't use "FORCE" for tags targets

 .gitignore |  2 +-
 Makefile   | 31 +++++++++++++++++--------------
 2 files changed, 18 insertions(+), 15 deletions(-)
Looks mostly like good patches, with concrete suggestions for
improvements given.  Please do not leave another loose end that
should be easy to tie untied and float away to some other topics.

Thanks.

[PATCH v2 0/5] Makefile: "make tags" fixes & cleanup

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:23

A v2 of my fixes to the tags targets. This no longer depends on my
.DELETE_ON_ERROR change, and goes directly on top of "master". See [2]
for the just-submitted v2 of that other series.

The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.

I missed the interaction of the "-a" flag and xargs splitting the
arguments into am implicit -n, so in v1 of this we could end up with
incomplete tag files. In this v2 we more incrementally reach similar
ends, but in the end result retain our rm/gen/mv dance, since it's
needed in this case.

1. http://lore.kernel.org/git/cover-0.3-00000000000-20210622T141844Z-avarab@gmail.com
2. https://lore.kernel.org/git/patch-1.1-2557117855-20210629T084356Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (5):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: add QUIET_GEN to "cscope" target
  Makefile: fix "cscope" target to refer to cscope.out
  Makefile: don't use "FORCE" for tags targets
  Makefile: normalize clobbering & xargs for tags targets

 .gitignore |  2 +-
 Makefile   | 34 ++++++++++++++++++++--------------
 2 files changed, 21 insertions(+), 15 deletions(-)

Range-diff against v1:
1:  383a90c8ac = 1:  dd6cfd6022 Makefile: move ".PHONY: cscope" near its target
-:  ---------- > 2:  56daa09738 Makefile: add QUIET_GEN to "cscope" target
2:  ea39f1f5cd ! 3:  35c8b83904 Makefile: fix "cscope" target to refer to cscope.out
    @@ Commit message
     
         The cscope target added in a2a9150bf06 (makefile: Add a cscope target,
         2007-10-06) has for some reason been referring to cscope* instead of
    -    cscope.out. Let's generate the cscope.out file directly so we don't
    -    need to speculate.
    +    cscope.out.
     
    -    The "-fcscope.out" (note, no whitespace) argument is enabled by
    -    default on my system's cscope 15.9, but let's provide it explicitly
    -    for good measure.
    +    Let's generate the cscope.out file directly so we don't need to
    +    speculate. The "-fcscope.out" (note, no whitespace) argument is
    +    enabled by default on my system's cscope 15.9, but let's provide it
    +    explicitly for good measure.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
     
    @@ Makefile: tags: FORCE
      	mv tags+ tags
      
     +cscope.out:
    ++	$(QUIET_GEN)$(RM) cscope.out && \
     +	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
     +
      .PHONY: cscope
     -cscope:
    --	$(RM) cscope*
    +-	$(QUIET_GEN)$(RM) cscope* && \
     -	$(FIND_SOURCE_FILES) | xargs cscope -b
     +cscope: cscope.out
      
3:  67fc87665d ! 4:  b924cc3f56 Makefile: don't use "FORCE" for tags targets
    @@ Commit message
         targets, instead make them depend on whether or not the relevant
         source files have changed.
     
    -    I'm also removing the "-o" option from them, that seems to have been
    -    cargo-culted when they were initially added in f81e7c626f3 (Makefile:
    -    Add TAGS and tags targets, 2006-03-18). It would make sense to use
    -    that option if we had been appending to tag files, it doesn't make any
    -    sense that it was used after we'd just removed the files file being
    -    appended to.
    -
    -    This will potentially cause a partial file to be left behind if the
    -    command dies, but my in-flight series to use the ".DELETE_ON_ERROR"
    -    flag in the Makefile[1] will make that problem go away. I think even
    -    without that it's not problem we need to worry about in these cases.
    -
    -    1. https://lore.kernel.org/git/patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com/
    -
         Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
     
      ## Makefile ##
    @@ Makefile: FIND_SOURCE_FILES = ( \
      	)
      
     -$(ETAGS_TARGET): FORCE
    --	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
    --	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
    --	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
     +FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
    ++
    ++$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
    + 	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
    + 	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
    + 	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
      
     -tags: FORCE
    --	$(QUIET_GEN)$(RM) tags+ && \
    --	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    --	mv tags+ tags
    -+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
    -+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
    -+	xargs etags -o $@
    -+
     +tags: $(FOUND_SOURCE_FILES)
    -+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
    -+	xargs ctags -o $@
    + 	$(QUIET_GEN)$(RM) tags+ && \
    + 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    + 	mv tags+ tags
      
    - cscope.out:
    +-cscope.out:
    ++cscope.out: $(FOUND_SOURCE_FILES)
    + 	$(QUIET_GEN)$(RM) cscope.out && \
     -	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
    -+	$(QUIET_GEN)echo $(FOUND_SOURCE_FILES) | \
    -+	xargs cscope -f$@ -b
    ++	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
      
      .PHONY: cscope
      cscope: cscope.out
-:  ---------- > 5:  5195d99e25 Makefile: normalize clobbering & xargs for tags targets
-- 
2.32.0.613.g20d5ce26552

[PATCH v2 1/5] Makefile: move ".PHONY: cscope" near its target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:26

Move the ".PHONY: cscope" rule to live alongside the "cscope" target
itself, not to be all the way near the bottom where we define the
"FORCE" rule.

That line was last modified in 2f76919517e (MinGW: avoid collisions
between "tags" and "TAGS", 2010-09-28).

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index c3565fc0f8..4dd9711a65 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,6 +2737,7 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+.PHONY: cscope
 cscope:
 	$(RM) cscope*
 	$(FIND_SOURCE_FILES) | xargs cscope -b
@@ -3245,7 +3246,7 @@ endif
 
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
-.PHONY: FORCE cscope
+.PHONY: FORCE
 
 ### Check documentation
 #
-- 
2.32.0.613.g20d5ce26552

[PATCH v2 2/5] Makefile: add QUIET_GEN to "cscope" target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:26

Don't show the very verbose $(FIND_SOURCE_FILES) command on every
"make cscope" invocation.

See my recent 3c80fcb591 (Makefile: add QUIET_GEN to "tags" and "TAGS"
targets, 2021-03-28) for the same fix for the other adjacent targets.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 4dd9711a65..faa8900097 100644
--- a/Makefile
+++ b/Makefile
@@ -2739,7 +2739,7 @@ tags: FORCE
 
 .PHONY: cscope
 cscope:
-	$(RM) cscope*
+	$(QUIET_GEN)$(RM) cscope* && \
 	$(FIND_SOURCE_FILES) | xargs cscope -b
 
 ### Detect prefix changes
-- 
2.32.0.613.g20d5ce26552

[PATCH v2 3/5] Makefile: fix "cscope" target to refer to cscope.out

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:27

The cscope target added in a2a9150bf06 (makefile: Add a cscope target,
2007-10-06) has for some reason been referring to cscope* instead of
cscope.out.

Let's generate the cscope.out file directly so we don't need to
speculate. The "-fcscope.out" (note, no whitespace) argument is
enabled by default on my system's cscope 15.9, but let's provide it
explicitly for good measure.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 .gitignore |  2 +-
 Makefile   | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index 311841f9be..d74029c1ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -217,7 +217,7 @@
 /.vscode/
 /tags
 /TAGS
-/cscope*
+/cscope.out
 /compile_commands.json
 *.hcc
 *.obj
diff --git a/Makefile b/Makefile
index faa8900097..2e3b257164 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,10 +2737,12 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+cscope.out:
+	$(QUIET_GEN)$(RM) cscope.out && \
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(QUIET_GEN)$(RM) cscope* && \
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
 
 ### Detect prefix changes
 TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
@@ -3211,7 +3213,7 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) $(HCC)
 	$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
 	$(RM) -r po/build/
-	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope*
+	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope.out
 	$(RM) -r .dist-tmp-dir .doc-tmp-dir
 	$(RM) $(GIT_TARNAME).tar.gz
 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
-- 
2.32.0.613.g20d5ce26552

[PATCH v2 4/5] Makefile: don't use "FORCE" for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:29

Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
targets, instead make them depend on whether or not the relevant
source files have changed.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 2e3b257164..7b0d9773b0 100644
--- a/Makefile
+++ b/Makefile
@@ -2727,19 +2727,21 @@ FIND_SOURCE_FILES = ( \
 		| sed -e 's|^\./||' \
 	)
 
-$(ETAGS_TARGET): FORCE
+FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
+
+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
 	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
 	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
 
-tags: FORCE
+tags: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) tags+ && \
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
-cscope.out:
+cscope.out: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) cscope.out && \
-	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
 
 .PHONY: cscope
 cscope: cscope.out
@@ -2923,7 +2925,7 @@ check: config-list.h command-list.h
 		exit 1; \
 	fi
 
-FOUND_C_SOURCES = $(filter %.c,$(shell $(FIND_SOURCE_FILES)))
+FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
 COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
-- 
2.32.0.613.g20d5ce26552

[PATCH v2 5/5] Makefile: normalize clobbering & xargs for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 11:13:30

Since the "tags", "TAGS" and "cscope.out" targets rely on ping into
xargs with an "echo <list> | xargs" pattern, we need to make sure
we're in an append mode.

Unlike recent changes of mine to make use of ".DELETE_ON_ERROR" we
really do need the "rm $@+" at the beginning (note, not "rm $@").

This is because the xargs command may decide on multiple invocations
of the program. 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 <redacted>
---
 Makefile | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index 7b0d9773b0..926c9efe43 100644
--- a/Makefile
+++ b/Makefile
@@ -2730,18 +2730,19 @@ FIND_SOURCE_FILES = ( \
 FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
 
 $(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
-	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
+	mv $@+ $@
 
 tags: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) tags+ && \
-	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
-	mv tags+ tags
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o $@+ && \
+	mv $@+ $@
 
 cscope.out: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) cscope.out && \
-	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@+ -b && \
+	mv $@+ $@
 
 .PHONY: cscope
 cscope: cscope.out
-- 
2.32.0.613.g20d5ce26552

Re: [PATCH 0/3] Makefile: "make tags" fixes & cleanup

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-06-29 12:07:26

On Mon, Jun 28 2021, Junio C Hamano wrote:
Ævar Arnfjörð Bjarmason  [off-list ref] writes:
quoted
A small series to fix the various "tags" targets, i.e. "make tags TAGS
cscope". We'll now properly detect their dependencies, so we don't
needlessly run them every time. I have this as part of my standard
"make git" command, so doing nothing when we have nothing to do is
preferrable, especially when my editor will eagerly reload the TAGS
file every time it changes.

As noted in 3/3 this is better on top of my just-submitted
.DELETE_ON_ERROR change[1], but will also work independently of that
patch/series.

1. https://lore.kernel.org/git/patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com/

Ævar Arnfjörð Bjarmason (3):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: fix "cscope" target to refer to cscope.out
  Makefile: don't use "FORCE" for tags targets

 .gitignore |  2 +-
 Makefile   | 31 +++++++++++++++++--------------
 2 files changed, 18 insertions(+), 15 deletions(-)
Looks mostly like good patches, with concrete suggestions for
improvements given.  Please do not leave another loose end that
should be easy to tie untied and float away to some other topics.
In the v2 re-roll of both I detached these two topics from each other,
as it turns out it wasn't needed to begin with. Sorry about that.

Re: [PATCH v2 4/5] Makefile: don't use "FORCE" for tags targets

From: Ramsay Jones <hidden>
Date: 2021-06-30 00:13:09


On 29/06/2021 12:12, Ævar Arnfjörð Bjarmason wrote:
quoted hunk
Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
targets, instead make them depend on whether or not the relevant
source files have changed.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 2e3b257164..7b0d9773b0 100644
--- a/Makefile
+++ b/Makefile
@@ -2727,19 +2727,21 @@ FIND_SOURCE_FILES = ( \
 		| sed -e 's|^\./||' \
 	)
 
-$(ETAGS_TARGET): FORCE
+FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
+
+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
 	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
 	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
 
-tags: FORCE
+tags: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) tags+ && \
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
I was expecting to see the above targets to be changed, similarly to ...
 
-cscope.out:
+cscope.out: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) cscope.out && \
-	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
... this hunk (ie. 'an "echo <list> | xargs" pattern')
Indeed, the above phrase was taken from the commit message of
the next patch (5/5), which implies that this change had already
happened (presumably in this patch).

ATB,
Ramsay Jones
quoted hunk
 
 .PHONY: cscope
 cscope: cscope.out
@@ -2923,7 +2925,7 @@ check: config-list.h command-list.h
 		exit 1; \
 	fi
 
-FOUND_C_SOURCES = $(filter %.c,$(shell $(FIND_SOURCE_FILES)))
+FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
 COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)

Re: [PATCH v2 3/5] Makefile: fix "cscope" target to refer to cscope.out

From: Jeff King <hidden>
Date: 2021-07-01 22:23:54

On Tue, Jun 29, 2021 at 01:12:57PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted hunk
diff --git a/Makefile b/Makefile
index faa8900097..2e3b257164 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,10 +2737,12 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+cscope.out:
+	$(QUIET_GEN)$(RM) cscope.out && \
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(QUIET_GEN)$(RM) cscope* && \
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
Doesn't this break subsequent runs after the first generation? With a
phony "cscope" target, "make cscope" will always run the command, even
if it's not necessary. But with a real "cscope.out" target but not
dependencies, it will _never_ run it, even if one of the files changed.

E.g., with your patch:

  $ make cscope.out
    GEN cscope.out

  $ make cscope.out
  make: 'cscope.out' is up to date.

  $ echo 'void foo(void) { }' >>git.c
  $ make cscope.out
  GIT_VERSION = 2.32.0.96.g5daee1b7bb.dirty
  make: 'cscope.out' is up to date.

-Peff

Re: [PATCH v2 3/5] Makefile: fix "cscope" target to refer to cscope.out

From: Jeff King <hidden>
Date: 2021-07-01 22:25:07

On Thu, Jul 01, 2021 at 06:23:52PM -0400, Jeff King wrote:
On Tue, Jun 29, 2021 at 01:12:57PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
diff --git a/Makefile b/Makefile
index faa8900097..2e3b257164 100644
--- a/Makefile
+++ b/Makefile
@@ -2737,10 +2737,12 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+cscope.out:
+	$(QUIET_GEN)$(RM) cscope.out && \
+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
+
 .PHONY: cscope
-cscope:
-	$(QUIET_GEN)$(RM) cscope* && \
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+cscope: cscope.out
Doesn't this break subsequent runs after the first generation? With a
phony "cscope" target, "make cscope" will always run the command, even
if it's not necessary. But with a real "cscope.out" target but not
dependencies, it will _never_ run it, even if one of the files changed.

E.g., with your patch:

  $ make cscope.out
    GEN cscope.out

  $ make cscope.out
  make: 'cscope.out' is up to date.

  $ echo 'void foo(void) { }' >>git.c
  $ make cscope.out
  GIT_VERSION = 2.32.0.96.g5daee1b7bb.dirty
  make: 'cscope.out' is up to date.
Ah, I see it is un-broken in the next commit, which adds actual
dependencies. I think it is OK to have a temporarily-broken state in the
history for something so trivial, but it might be worth mentioning it in
the commit message.

-Peff

[PATCH v3 0/5] Makefile: "make tags" fixes & cleanup

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:15

The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.

For v2, see
https://lore.kernel.org/git/cover-0.5-0000000000-20210629T110837Z-avarab@gmail.com/

This fixes the series per feedback from Jeff King and Ramsay Jones,
i.e:

 * In v2 the 3/5 broke things in a way that 4/5 fixed, that's now
   re-arranged and fixed.

 * I now use $(FOUND_SOURCE_FILES) instead of $(FIND_SOURCE_FILES)
   consistently. I was redundantly re-running the "find" command.


Ævar Arnfjörð Bjarmason (5):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: add QUIET_GEN to "cscope" target
  Makefile: don't use "FORCE" for tags targets
  Makefile: the "cscope" target always creates a "cscope.out"
  Makefile: normalize clobbering & xargs for tags targets

 .gitignore |  2 +-
 Makefile   | 34 ++++++++++++++++++++--------------
 2 files changed, 21 insertions(+), 15 deletions(-)

Range-diff against v2:
1:  dd6cfd6022c = 1:  6b4ddc126d9 Makefile: move ".PHONY: cscope" near its target
2:  56daa09738f = 2:  d3d5d332e92 Makefile: add QUIET_GEN to "cscope" target
4:  b924cc3f566 ! 3:  9dd69d68178 Makefile: don't use "FORCE" for tags targets
    @@ Metadata
      ## Commit message ##
         Makefile: don't use "FORCE" for tags targets
     
    -    Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope.out"
    +    Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope"
         targets, instead make them depend on whether or not the relevant
         source files have changed.
     
    +    For the cscope target we need to change it to depend on the actual
    +    generated file while we generate while we're at it, as the next commit
    +    will discuss we always generate a cscope.out file.
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
     
      ## Makefile ##
    @@ Makefile: FIND_SOURCE_FILES = ( \
     +
     +$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
      	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
    - 	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
    +-	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
    ++	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
      	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
      
     -tags: FORCE
     +tags: $(FOUND_SOURCE_FILES)
      	$(QUIET_GEN)$(RM) tags+ && \
    - 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    +-	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    ++	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
      	mv tags+ tags
      
    --cscope.out:
    +-.PHONY: cscope
    +-cscope:
     +cscope.out: $(FOUND_SOURCE_FILES)
    - 	$(QUIET_GEN)$(RM) cscope.out && \
    --	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
    -+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
    + 	$(QUIET_GEN)$(RM) cscope* && \
    +-	$(FIND_SOURCE_FILES) | xargs cscope -b
    ++	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
    ++
    ++.PHONY: cscope
    ++cscope: cscope.out
      
    - .PHONY: cscope
    - cscope: cscope.out
    + ### Detect prefix changes
    + TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
     @@ Makefile: check: config-list.h command-list.h
      		exit 1; \
      	fi
3:  35c8b839048 ! 4:  f8d151f1f6a Makefile: fix "cscope" target to refer to cscope.out
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason [off-list ref]
     
      ## Commit message ##
    -    Makefile: fix "cscope" target to refer to cscope.out
    +    Makefile: the "cscope" target always creates a "cscope.out"
     
    -    The cscope target added in a2a9150bf06 (makefile: Add a cscope target,
    -    2007-10-06) has for some reason been referring to cscope* instead of
    +    In the preceding commit the "cscope" target was changed to be a phony
    +    alias for the "cscope.out" target.
    +
    +    The cscope target was added in a2a9150bf06 (makefile: Add a cscope
    +    target, 2007-10-06), and has always referred to cscope* instead of to
         cscope.out.
     
    -    Let's generate the cscope.out file directly so we don't need to
    -    speculate. The "-fcscope.out" (note, no whitespace) argument is
    -    enabled by default on my system's cscope 15.9, but let's provide it
    -    explicitly for good measure.
    +    As far as I can tell this ambiguity was never needed. The
    +    "-fcscope.out" (note, no whitespace) argument is enabled by default,
    +    but let's provide it explicitly for good measure.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
     
    @@ .gitignore
      *.obj
     
      ## Makefile ##
    -@@ Makefile: tags: FORCE
    - 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    +@@ Makefile: tags: $(FOUND_SOURCE_FILES)
      	mv tags+ tags
      
    -+cscope.out:
    -+	$(QUIET_GEN)$(RM) cscope.out && \
    -+	$(FIND_SOURCE_FILES) | xargs cscope -f$@ -b
    -+
    - .PHONY: cscope
    --cscope:
    + cscope.out: $(FOUND_SOURCE_FILES)
     -	$(QUIET_GEN)$(RM) cscope* && \
    --	$(FIND_SOURCE_FILES) | xargs cscope -b
    -+cscope: cscope.out
    +-	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
    ++	$(QUIET_GEN)$(RM) cscope.out && \
    ++	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
      
    - ### Detect prefix changes
    - TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
    + .PHONY: cscope
    + cscope: cscope.out
     @@ Makefile: clean: profile-clean coverage-clean cocciclean
      	$(RM) $(HCC)
      	$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
5:  5195d99e25c ! 5:  f3ff76d0e98 Makefile: normalize clobbering & xargs for tags targets
    @@ Metadata
      ## Commit message ##
         Makefile: normalize clobbering & xargs for tags targets
     
    -    Since the "tags", "TAGS" and "cscope.out" targets rely on ping into
    +    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 recent changes of mine to make use of ".DELETE_ON_ERROR" we
    -    really do need the "rm $@+" at the beginning (note, not "rm $@").
    +    Unlike my recent change to make use of ".DELETE_ON_ERROR" in
    +    7b76d6bf221 (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 on multiple invocations
    -    of the program. We need to make sure we've got a union of its results
    +    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
    @@ Makefile: FIND_SOURCE_FILES = ( \
      
      $(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
     -	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
    --	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
    +-	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
     -	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
     +	$(QUIET_GEN)$(RM) $@+ && \
     +	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
    @@ Makefile: FIND_SOURCE_FILES = ( \
      
      tags: $(FOUND_SOURCE_FILES)
     -	$(QUIET_GEN)$(RM) tags+ && \
    --	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
    +-	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
     -	mv tags+ tags
     +	$(QUIET_GEN)$(RM) $@+ && \
     +	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o $@+ && \
-- 
2.32.0.955.ge7c5360f7e7

[PATCH v3 1/5] Makefile: move ".PHONY: cscope" near its target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:17

Move the ".PHONY: cscope" rule to live alongside the "cscope" target
itself, not to be all the way near the bottom where we define the
"FORCE" rule.

That line was last modified in 2f76919517e (MinGW: avoid collisions
between "tags" and "TAGS", 2010-09-28).

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index c7c46c017d3..7dd93ef4c3e 100644
--- a/Makefile
+++ b/Makefile
@@ -2749,6 +2749,7 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+.PHONY: cscope
 cscope:
 	$(RM) cscope*
 	$(FIND_SOURCE_FILES) | xargs cscope -b
@@ -3260,7 +3261,7 @@ endif
 
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
-.PHONY: FORCE cscope
+.PHONY: FORCE
 
 ### Check documentation
 #
-- 
2.32.0.955.ge7c5360f7e7

[PATCH v3 2/5] Makefile: add QUIET_GEN to "cscope" target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:19

Don't show the very verbose $(FIND_SOURCE_FILES) command on every
"make cscope" invocation.

See my recent 3c80fcb591 (Makefile: add QUIET_GEN to "tags" and "TAGS"
targets, 2021-03-28) for the same fix for the other adjacent targets.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 7dd93ef4c3e..69410095949 100644
--- a/Makefile
+++ b/Makefile
@@ -2751,7 +2751,7 @@ tags: FORCE
 
 .PHONY: cscope
 cscope:
-	$(RM) cscope*
+	$(QUIET_GEN)$(RM) cscope* && \
 	$(FIND_SOURCE_FILES) | xargs cscope -b
 
 ### Detect prefix changes
-- 
2.32.0.955.ge7c5360f7e7

[PATCH v3 3/5] Makefile: don't use "FORCE" for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:20

Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope"
targets, instead make them depend on whether or not the relevant
source files have changed.

For the cscope target we need to change it to depend on the actual
generated file while we generate while we're at it, as the next commit
will discuss we always generate a cscope.out file.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index 69410095949..18895d94ffa 100644
--- a/Makefile
+++ b/Makefile
@@ -2739,20 +2739,24 @@ FIND_SOURCE_FILES = ( \
 		| sed -e 's|^\./||' \
 	)
 
-$(ETAGS_TARGET): FORCE
+FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
+
+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
+	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
 	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
 
-tags: FORCE
+tags: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) tags+ && \
-	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
-.PHONY: cscope
-cscope:
+cscope.out: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) cscope* && \
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
+
+.PHONY: cscope
+cscope: cscope.out
 
 ### Detect prefix changes
 TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
@@ -2936,7 +2940,7 @@ check: config-list.h command-list.h
 		exit 1; \
 	fi
 
-FOUND_C_SOURCES = $(filter %.c,$(shell $(FIND_SOURCE_FILES)))
+FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
 COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
-- 
2.32.0.955.ge7c5360f7e7

[PATCH v3 4/5] Makefile: the "cscope" target always creates a "cscope.out"

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:21

In the preceding commit the "cscope" target was changed to be a phony
alias for the "cscope.out" target.

The cscope target was added in a2a9150bf06 (makefile: Add a cscope
target, 2007-10-06), and has always referred to cscope* instead of to
cscope.out.

As far as I can tell this ambiguity was never needed. The
"-fcscope.out" (note, no whitespace) argument is enabled by default,
but let's provide it explicitly for good measure.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 .gitignore | 2 +-
 Makefile   | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
index 311841f9bed..d74029c1ca7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -217,7 +217,7 @@
 /.vscode/
 /tags
 /TAGS
-/cscope*
+/cscope.out
 /compile_commands.json
 *.hcc
 *.obj
diff --git a/Makefile b/Makefile
index 18895d94ffa..730ff23b923 100644
--- a/Makefile
+++ b/Makefile
@@ -2752,8 +2752,8 @@ tags: $(FOUND_SOURCE_FILES)
 	mv tags+ tags
 
 cscope.out: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) cscope* && \
-	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
+	$(QUIET_GEN)$(RM) cscope.out && \
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
 
 .PHONY: cscope
 cscope: cscope.out
@@ -3230,7 +3230,7 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) $(HCC)
 	$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
 	$(RM) -r po/build/
-	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope*
+	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope.out
 	$(RM) -r .dist-tmp-dir .doc-tmp-dir
 	$(RM) $(GIT_TARNAME).tar.gz
 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
-- 
2.32.0.955.ge7c5360f7e7

[PATCH v3 5/5] Makefile: normalize clobbering & xargs for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-07-21 23:23:21

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
7b76d6bf221 (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 <redacted>
---
 Makefile | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index 730ff23b923..295ac359cea 100644
--- a/Makefile
+++ b/Makefile
@@ -2742,18 +2742,19 @@ FIND_SOURCE_FILES = ( \
 FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
 
 $(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
-	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
+	mv $@+ $@
 
 tags: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) tags+ && \
-	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
-	mv tags+ tags
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o $@+ && \
+	mv $@+ $@
 
 cscope.out: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) cscope.out && \
-	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@+ -b && \
+	mv $@+ $@
 
 .PHONY: cscope
 cscope: cscope.out
-- 
2.32.0.955.ge7c5360f7e7

Re: [PATCH v3 5/5] Makefile: normalize clobbering & xargs for tags targets

From: Jeff King <hidden>
Date: 2021-07-23 10:43:16

On Thu, Jul 22, 2021 at 01:23:06AM +0200, Ævar Arnfjörð Bjarmason wrote:
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.
Hrm, that's not the experience I get with cscope. E.g.:

  $ cscope -b wt-status.c
  $ grep -m1 wt-status.c cscope.out
	@wt-status.c
  $ cscope -b git.c
  $ grep -m1 wt-status.c cscope.out
  [no output]

I wondered if I was being too hacky with my grep there. But if I
simulate more extreme cmdline-splitting like so:
diff --git a/Makefile b/Makefile
index c7c46c017d..8a1ec00938 100644
--- a/Makefile
+++ b/Makefile
@@ -2751,7 +2751,7 @@ tags: FORCE
 
 cscope:
 	$(RM) cscope*
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+	$(FIND_SOURCE_FILES) | xargs -n1 cscope -b
 
 ### Detect prefix changes
 TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
then I get a file that is much smaller (1MB versus 9MB), and fails to
find lots of things:

  $ cscope -d -L1cmd_pack_objects
  [no output]

(by the way, I confused myself several times while testing this because
without "-d", it will actually rebuild the index using files in the
current directory. So something like " cscope -L1main" gives the same
result in both cases, or even if you don't have a cscope.out file at
all!)

But it really seems like cscope is not appending as we'd want. From
skimming the manpage, I think replacing xargs with "cscope -b -i -"
should work (and seems to for me).

-Peff

Re: [PATCH v3 5/5] Makefile: normalize clobbering & xargs for tags targets

From: Jeff King <hidden>
Date: 2021-07-23 10:47:57

On Fri, Jul 23, 2021 at 06:43:13AM -0400, Jeff King wrote:
On Thu, Jul 22, 2021 at 01:23:06AM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
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.
Hrm, that's not the experience I get with cscope. E.g.:
Just to make it extra clear: this is not a problem introduced by your
series, since we were already using xargs with cscope. But this seems
like a good time to fix it.

-Peff

Re: [PATCH v3 0/5] Makefile: "make tags" fixes & cleanup

From: Jeff King <hidden>
Date: 2021-07-23 10:48:02

On Thu, Jul 22, 2021 at 01:23:01AM +0200, Ævar Arnfjörð Bjarmason wrote:
The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.

For v2, see
https://lore.kernel.org/git/cover-0.5-0000000000-20210629T110837Z-avarab@gmail.com/

This fixes the series per feedback from Jeff King and Ramsay Jones,
i.e:

 * In v2 the 3/5 broke things in a way that 4/5 fixed, that's now
   re-arranged and fixed.
Thanks. Aside from some cscope appending arcana I found, these look good
to me. I have no opinion on "cscope*" versus "cscope.out", except that
it is not worth anybody's time to argue about. :)

-Peff

Re: [PATCH v3 0/5] Makefile: "make tags" fixes & cleanup

From: Felipe Contreras <hidden>
Date: 2021-07-23 19:32:45

Jeff King wrote:
On Thu, Jul 22, 2021 at 01:23:01AM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.

For v2, see
https://lore.kernel.org/git/cover-0.5-0000000000-20210629T110837Z-avarab@gmail.com/

This fixes the series per feedback from Jeff King and Ramsay Jones,
i.e:

 * In v2 the 3/5 broke things in a way that 4/5 fixed, that's now
   re-arranged and fixed.
Thanks. Aside from some cscope appending arcana I found, these look good
to me. I have no opinion on "cscope*" versus "cscope.out", except that
it is not worth anybody's time to argue about. :)
I agree with that as well.

-- 
Felipe Contreras

RE: [PATCH v3 0/5] Makefile: "make tags" fixes & cleanup

From: Felipe Contreras <hidden>
Date: 2021-07-23 19:41:52

Ævar Arnfjörð Bjarmason wrote:
The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.
Very nice.

I think most of the nitpicking in the comments is not really worth the
trouble (either for or against), there is one comment from Jeff King
regarding multiple runs of the xargs command that I think is valid, but
too hypothetical for me to care about (ARG_MAX is 2097152 on my system),
so it would be nice to fix, but not necessary.

Reviewed-by: Felipe Contreras <redacted>

-- 
Felipe Contreras

[PATCH v4 0/5] Makefile: "make tags" fixes & cleanup

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:48

The big win here is that none of the tags targets depend on "FORCE"
anymore, so we'll only re-generate them if our sources change.

For v3, see:
https://lore.kernel.org/git/cover-0.5-00000000000-20210721T231900Z-avarab@gmail.com/

This addresses the feedback about the cscope* v.s. cscope.out rule in
.gitignore and "make clean", i.e. those rules are not being changed
anymore. I also changed a stray cscope.out to $@ in 4/5, which was
missed in v3.

Ævar Arnfjörð Bjarmason (5):
  Makefile: move ".PHONY: cscope" near its target
  Makefile: add QUIET_GEN to "cscope" target
  Makefile: don't use "FORCE" for tags targets
  Makefile: remove "cscope.out", not "cscope*" in cscope.out target
  Makefile: normalize clobbering & xargs for tags targets

 Makefile | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Range-diff against v3:
1:  6b4ddc126d9 = 1:  2ee725e2fba Makefile: move ".PHONY: cscope" near its target
2:  d3d5d332e92 = 2:  2122cb25633 Makefile: add QUIET_GEN to "cscope" target
3:  9dd69d68178 = 3:  8649716772b Makefile: don't use "FORCE" for tags targets
4:  f8d151f1f6a ! 4:  643c514e12a Makefile: the "cscope" target always creates a "cscope.out"
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason [off-list ref]
     
      ## Commit message ##
    -    Makefile: the "cscope" target always creates a "cscope.out"
    +    Makefile: remove "cscope.out", not "cscope*" in cscope.out target
     
    -    In the preceding commit the "cscope" target was changed to be a phony
    -    alias for the "cscope.out" target.
    +    Before we generate a "cscope.out" file, remove that file explicitly,
    +    and not everything matching "cscope*". This doesn't change any
    +    behavior of the Makefile in practice, but makes this rule less
    +    confusing, and consistent with other similar rules.
     
         The cscope target was added in a2a9150bf06 (makefile: Add a cscope
    -    target, 2007-10-06), and has always referred to cscope* instead of to
    -    cscope.out.
    +    target, 2007-10-06). It has always referred to cscope* instead of to
    +    cscope.out in .gitignore and the "clean" target, even though we only
    +    ever generated a cscope.out file.
     
    -    As far as I can tell this ambiguity was never needed. The
    -    "-fcscope.out" (note, no whitespace) argument is enabled by default,
    -    but let's provide it explicitly for good measure.
    +    This was seemingly done to aid use-cases where someone invoked cscope
    +    with the "-q" flag, which would make it create a "cscope.in.out" and
    +    "cscope.po.out" files in addition to "cscope.out".
     
    -    Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
    +    But us removing those files we never generated is confusing, so let's
    +    only remove the file we need to, furthermore let's use the "-f" flag
    +    to explicitly name the cscope.out file, even though it's the default
    +    if not "-f" argument is supplied.
    +
    +    It is somewhat inconsistent to change from the glob here but not in
    +    the "clean" rule and .gitignore, an earlier version of this change
    +    updated those as well, but see [1][2] for why they were kept.
     
    - ## .gitignore ##
    -@@
    - /.vscode/
    - /tags
    - /TAGS
    --/cscope*
    -+/cscope.out
    - /compile_commands.json
    - *.hcc
    - *.obj
    +    1. https://lore.kernel.org/git/87k0lit57x.fsf@evledraar.gmail.com/
    +    2. https://lore.kernel.org/git/87im0kn983.fsf@evledraar.gmail.com/
    +
    +    Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
     
      ## Makefile ##
     @@ Makefile: tags: $(FOUND_SOURCE_FILES)
    @@ Makefile: tags: $(FOUND_SOURCE_FILES)
      cscope.out: $(FOUND_SOURCE_FILES)
     -	$(QUIET_GEN)$(RM) cscope* && \
     -	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
    -+	$(QUIET_GEN)$(RM) cscope.out && \
    ++	$(QUIET_GEN)$(RM) $@ && \
     +	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
      
      .PHONY: cscope
      cscope: cscope.out
    -@@ Makefile: clean: profile-clean coverage-clean cocciclean
    - 	$(RM) $(HCC)
    - 	$(RM) -r bin-wrappers $(dep_dirs) $(compdb_dir) compile_commands.json
    - 	$(RM) -r po/build/
    --	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope*
    -+	$(RM) *.pyc *.pyo */*.pyc */*.pyo $(GENERATED_H) $(ETAGS_TARGET) tags cscope.out
    - 	$(RM) -r .dist-tmp-dir .doc-tmp-dir
    - 	$(RM) $(GIT_TARNAME).tar.gz
    - 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
5:  f3ff76d0e98 ! 5:  1eaf3416329 Makefile: normalize clobbering & xargs for tags targets
    @@ Makefile: FIND_SOURCE_FILES = ( \
     +	mv $@+ $@
      
      cscope.out: $(FOUND_SOURCE_FILES)
    --	$(QUIET_GEN)$(RM) cscope.out && \
    +-	$(QUIET_GEN)$(RM) $@ && \
     -	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
     +	$(QUIET_GEN)$(RM) $@+ && \
     +	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@+ -b && \
-- 
2.33.0.rc0.597.gc569a812f0a

[PATCH v4 1/5] Makefile: move ".PHONY: cscope" near its target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:49

Move the ".PHONY: cscope" rule to live alongside the "cscope" target
itself, not to be all the way near the bottom where we define the
"FORCE" rule.

That line was last modified in 2f76919517e (MinGW: avoid collisions
between "tags" and "TAGS", 2010-09-28).

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 9573190f1d7..671dde5c7a1 100644
--- a/Makefile
+++ b/Makefile
@@ -2756,6 +2756,7 @@ tags: FORCE
 	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
+.PHONY: cscope
 cscope:
 	$(RM) cscope*
 	$(FIND_SOURCE_FILES) | xargs cscope -b
@@ -3267,7 +3268,7 @@ endif
 
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
-.PHONY: FORCE cscope
+.PHONY: FORCE
 
 ### Check documentation
 #
-- 
2.33.0.rc0.597.gc569a812f0a

[PATCH v4 2/5] Makefile: add QUIET_GEN to "cscope" target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:50

Don't show the very verbose $(FIND_SOURCE_FILES) command on every
"make cscope" invocation.

See my recent 3c80fcb591 (Makefile: add QUIET_GEN to "tags" and "TAGS"
targets, 2021-03-28) for the same fix for the other adjacent targets.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 671dde5c7a1..59c2e98795b 100644
--- a/Makefile
+++ b/Makefile
@@ -2758,7 +2758,7 @@ tags: FORCE
 
 .PHONY: cscope
 cscope:
-	$(RM) cscope*
+	$(QUIET_GEN)$(RM) cscope* && \
 	$(FIND_SOURCE_FILES) | xargs cscope -b
 
 ### Detect prefix changes
-- 
2.33.0.rc0.597.gc569a812f0a

[PATCH v4 3/5] Makefile: don't use "FORCE" for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:51

Remove the "FORCE" dependency from the "tags", "TAGS" and "cscope"
targets, instead make them depend on whether or not the relevant
source files have changed.

For the cscope target we need to change it to depend on the actual
generated file while we generate while we're at it, as the next commit
will discuss we always generate a cscope.out file.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index 59c2e98795b..d1012cf71d2 100644
--- a/Makefile
+++ b/Makefile
@@ -2746,20 +2746,24 @@ FIND_SOURCE_FILES = ( \
 		| sed -e 's|^\./||' \
 	)
 
-$(ETAGS_TARGET): FORCE
+FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
+
+$(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	$(FIND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
+	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
 	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
 
-tags: FORCE
+tags: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) tags+ && \
-	$(FIND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
 	mv tags+ tags
 
-.PHONY: cscope
-cscope:
+cscope.out: $(FOUND_SOURCE_FILES)
 	$(QUIET_GEN)$(RM) cscope* && \
-	$(FIND_SOURCE_FILES) | xargs cscope -b
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
+
+.PHONY: cscope
+cscope: cscope.out
 
 ### Detect prefix changes
 TRACK_PREFIX = $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
@@ -2943,7 +2947,7 @@ check: config-list.h command-list.h
 		exit 1; \
 	fi
 
-FOUND_C_SOURCES = $(filter %.c,$(shell $(FIND_SOURCE_FILES)))
+FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES))
 COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES))
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
-- 
2.33.0.rc0.597.gc569a812f0a

[PATCH v4 4/5] Makefile: remove "cscope.out", not "cscope*" in cscope.out target

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:51

Before we generate a "cscope.out" file, remove that file explicitly,
and not everything matching "cscope*". This doesn't change any
behavior of the Makefile in practice, but makes this rule less
confusing, and consistent with other similar rules.

The cscope target was added in a2a9150bf06 (makefile: Add a cscope
target, 2007-10-06). It has always referred to cscope* instead of to
cscope.out in .gitignore and the "clean" target, even though we only
ever generated a cscope.out file.

This was seemingly done to aid use-cases where someone invoked cscope
with the "-q" flag, which would make it create a "cscope.in.out" and
"cscope.po.out" files in addition to "cscope.out".

But us removing those files we never generated is confusing, so let's
only remove the file we need to, furthermore let's use the "-f" flag
to explicitly name the cscope.out file, even though it's the default
if not "-f" argument is supplied.

It is somewhat inconsistent to change from the glob here but not in
the "clean" rule and .gitignore, an earlier version of this change
updated those as well, but see [1][2] for why they were kept.

1. https://lore.kernel.org/git/87k0lit57x.fsf@evledraar.gmail.com/
2. https://lore.kernel.org/git/87im0kn983.fsf@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index d1012cf71d2..2a176ba5742 100644
--- a/Makefile
+++ b/Makefile
@@ -2759,8 +2759,8 @@ tags: $(FOUND_SOURCE_FILES)
 	mv tags+ tags
 
 cscope.out: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) cscope* && \
-	echo $(FOUND_SOURCE_FILES) | xargs cscope -b
+	$(QUIET_GEN)$(RM) $@ && \
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
 
 .PHONY: cscope
 cscope: cscope.out
-- 
2.33.0.rc0.597.gc569a812f0a

[PATCH v4 5/5] Makefile: normalize clobbering & xargs for tags targets

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-08-04 22:54:53

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
7b76d6bf221 (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 <redacted>
---
 Makefile | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index 2a176ba5742..1ad7a685d10 100644
--- a/Makefile
+++ b/Makefile
@@ -2749,18 +2749,19 @@ FIND_SOURCE_FILES = ( \
 FOUND_SOURCE_FILES = $(shell $(FIND_SOURCE_FILES))
 
 $(ETAGS_TARGET): $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) "$(ETAGS_TARGET)+" && \
-	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o "$(ETAGS_TARGET)+" && \
-	mv "$(ETAGS_TARGET)+" "$(ETAGS_TARGET)"
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs etags -a -o $@+ && \
+	mv $@+ $@
 
 tags: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) tags+ && \
-	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o tags+ && \
-	mv tags+ tags
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs ctags -a -o $@+ && \
+	mv $@+ $@
 
 cscope.out: $(FOUND_SOURCE_FILES)
-	$(QUIET_GEN)$(RM) $@ && \
-	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@ -b
+	$(QUIET_GEN)$(RM) $@+ && \
+	echo $(FOUND_SOURCE_FILES) | xargs cscope -f$@+ -b && \
+	mv $@+ $@
 
 .PHONY: cscope
 cscope: cscope.out
-- 
2.33.0.rc0.597.gc569a812f0a
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help