Skip to contentSkip to conversation

Makefile: add GNU global tags support

RFC PATCH In review Alex Bennée 2 participants 7 messages Jan 8, 2021 – Jan 12, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Makefile: add GNU global tags support

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

Quoted 50 lines
---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
#2 lore raw
Quoted 9 lines · Ben Widawsky
Quoted 8 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

Quoted 7 lines
Quoted 1 line

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

So I take it that's a reviewed-by and a tested-by tag from you?

Quoted 51 lines
Quoted 51 lines
---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
#3 lore raw
Quoted 14 lines · Alex Bennée
Quoted 11 lines · Ben Widawsky
Quoted 9 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

Quoted 8 lines
Quoted 5 lines

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

So I take it that's a reviewed-by and a tested-by tag from you?

It doesn't actually work correctly for me, I just like the idea :-)

make gtags 2>&1 | grep ignored | wc -l
6266

Warning: '/home/bwidawsk/work/clk/qemu/accel/qtest/qtest.c' is out of source tree. ignored.

Quoted 55 lines
Quoted 51 lines
Quoted 51 lines
---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
#4 lore raw
Quoted 24 lines · Ben Widawsky
Quoted 14 lines · Alex Bennée
Quoted 11 lines · Ben Widawsky
Quoted 9 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

Quoted 8 lines
Quoted 5 lines

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

So I take it that's a reviewed-by and a tested-by tag from you?

Quoted 7 lines

It doesn't actually work correctly for me, I just like the idea :-)

make gtags 2>&1 | grep ignored | wc -l
6266

Warning: '/home/bwidawsk/work/clk/qemu/accel/qtest/qtest.c' is out of source tree. ignored.

Did you run this in the build directory by any chance? I tested in the source directory because that's generally where you want the tags.

I wonder what the best solution is to this? Always force ourselves to be in the source dir? Or error out when we are not in the source tree?

Quoted 56 lines
Quoted 56 lines
Quoted 52 lines
Quoted 52 lines

---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
Signature · 1 line
Alex Bennée
#5 lore raw
Quoted 32 lines · Alex Bennée
Quoted 29 lines · Ben Widawsky
Quoted 14 lines · Alex Bennée
Quoted 11 lines · Ben Widawsky
Quoted 9 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

Quoted 8 lines
Quoted 5 lines

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

So I take it that's a reviewed-by and a tested-by tag from you?

It doesn't actually work correctly for me, I just like the idea :-)

make gtags 2>&1 | grep ignored | wc -l
6266

Quoted 8 lines
Quoted 2 lines

Warning: '/home/bwidawsk/work/clk/qemu/accel/qtest/qtest.c' is out of source tree. ignored.

Did you run this in the build directory by any chance? I tested in the source directory because that's generally where you want the tags.

I wonder what the best solution is to this? Always force ourselves to be in the source dir? Or error out when we are not in the source tree?

I was in the build directory. With ctags, that works for me in both source and build directory.

It does indeed work from the source directory.

I'm wondering how gtags can't seem to do this (I wasn't able to figure it out, at least).

I'd be in favor of error.

Quoted 62 lines
Quoted 58 lines
Quoted 58 lines
Quoted 54 lines
Quoted 54 lines



---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
Signature · 1 line
Alex Bennée
#6 lore raw
Quoted 42 lines · Ben Widawsky
Quoted 32 lines · Alex Bennée
Quoted 29 lines · Ben Widawsky
Quoted 14 lines · Alex Bennée
Quoted 11 lines · Ben Widawsky
Quoted 9 lines · Alex Bennée

GNU Global is another tags engine which is more like cscope in being able to support finding both references and definitions. You will be un-surprised to know it also integrates well with Emacs.

The main benefit of integrating it into find-src-path is it takes less time to rebuild the database from scratch when you have a lot of build directories under your source tree.

Quoted 8 lines
Quoted 5 lines

It might be worth mentioning that the Linux kernel has supported this for a long time now (10+ years).

Having switched to gtags about 3 years ago, I think it's summarily better and would really like this to get merged.

So I take it that's a reviewed-by and a tested-by tag from you?

It doesn't actually work correctly for me, I just like the idea :-)

make gtags 2>&1 | grep ignored | wc -l
6266

Quoted 8 lines
Quoted 2 lines

Warning: '/home/bwidawsk/work/clk/qemu/accel/qtest/qtest.c' is out of source tree. ignored.

Did you run this in the build directory by any chance? I tested in the source directory because that's generally where you want the tags.

I wonder what the best solution is to this? Always force ourselves to be in the source dir? Or error out when we are not in the source tree?

Quoted 7 lines

I was in the build directory. With ctags, that works for me in both source and build directory.

It does indeed work from the source directory.

I'm wondering how gtags can't seem to do this (I wasn't able to figure it out, at least).

The start of the manual states:

Gtags recursively collects source files under the current directory, picks up symbols and writes the cross-reference data into the tag files (´GTAGS´, ´GRTAGS´ and ´GPATH´).

so I guess when it finds files outside of CWD it gets confused. While all of my build trees are inside the source tree ("builds/foo|bar|baz") they don't have to be.

Quoted 1 line

I'd be in favor of error.

The other tags targets always generate to source root so I'm going to go for:

  .PHONY: gtags
  gtags:
          $(call quiet-command, \
                  rm -f "$(SRC_PATH)/"GTAGS \
                  rm -f "$(SRC_PATH)/"GRTAGS \
                  rm -f "$(SRC_PATH)/"GPATH, \
                  "GTAGS", "Remove old")
          $(call quiet-command, \
            (cd $(SRC_PATH) && $(find-src-path) | gtags -f -), \
            "GTAGS", "Re-index $(SRC_PATH)")

which also makes the output a bit nicer.

Quoted 64 lines
Quoted 64 lines
Quoted 60 lines
Quoted 60 lines
Quoted 56 lines
Quoted 56 lines





---
 Makefile   | 9 ++++++++-
 .gitignore | 3 +++
 2 files changed, 11 insertions(+), 1 deletion(-)
Makefile +8 -1
index fb9923ff22..66eec99685 100644
@@ -253,6 +253,13 @@ ctags:
 	rm -f "$(SRC_PATH)/"tags
 	$(find-src-path) -exec ctags -f "$(SRC_PATH)/"tags --append {} +
 
+.PHONY: gtags
+gtags:
+	rm -f "$(SRC_PATH)/"GTAGS
+	rm -f "$(SRC_PATH)/"GRTAGS
+	rm -f "$(SRC_PATH)/"GPATH
+	$(find-src-path) | gtags -f -
+
 .PHONY: TAGS
 TAGS:
 	rm -f "$(SRC_PATH)/"TAGS
@@ -279,7 +286,7 @@ help:
 	$(call print-help,all,Build all)
 	$(call print-help,dir/file.o,Build specified target only)
 	$(call print-help,install,Install QEMU, documentation and tools)
-	$(call print-help,ctags/TAGS,Generate tags file for editors)
+	$(call print-help,ctags/gtags/TAGS,Generate tags file for editors)
 	$(call print-help,cscope,Generate cscope index)
 	$(call print-help,sparse,Run sparse on the QEMU source)
 	@echo  ''
.gitignore +3 -0
index b32bca1315..75a4be0724 100644
@@ -7,6 +7,9 @@
 cscope.*
 tags
 TAGS
+GPATH
+GRTAGS
+GTAGS
 *~
 *.ast_raw
 *.depend_raw
Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
Signature · 1 line
Alex Bennée
Signature · 1 line
Alex Bennée