I was trying to make Automake generate a rule for creating cscope tags: http://rishi.fedorapeople.org/gnu/0001-New-target-to-generate-cscope-database.patch (also inlined below)
I found a discussion involving Jesse Barnes (http://sources.redhat.com/ml/automake/2004-07/msg00051.html) which seemed inconclusive. I have tried this patch with Automake 1.10.2 and the msmtp source base and it seems to work, but my knowledge of Automake's internals and Perl is zero. I ran this through Jim Meyering on IRC and he said that it might be a good idea to try and reduce the amount of backslash escaping in the automake.in related changes. Since I am really clueless about Perl, I did not change anything yet. >From 1396b3d1b8e576f00db4b82e156dffa12a9e4a06 Mon Sep 17 00:00:00 2001 From: Debarshi Ray <ri...@gnu.org> Date: Wed, 6 May 2009 14:37:39 +0530 Subject: [PATCH] New target to generate cscope database. * automake.in (handle_tags): Handle cscope. * doc/automake.texi (Tags): Document cscope. * lib/am/tags.am (CSCOPE): New macro. (cscope): New target. (cscope.file): Likewise. (cscopelist): Likewise. (distclean-tags): Remove `cscope.out', `cscope.in.out', `cscope.po.out' and `cscope.files'. * Makefile.in: Regenerate. * doc/Makefile.in: Likewise. * lib/Automake/Makefile.in: Likewise. * lib/Makefile.in: Likewise. * lib/am/Makefile.in: Likewise. * m4/Makefile.in: Likewise. * tests/Makefile.in: Likewise. --- Makefile.in | 52 ++++++++++++++++++++++++++-------------- automake.in | 18 ++++++++++++- doc/Makefile.in | 38 +++++++++++++++++----------- doc/automake.texi | 13 +++++++-- lib/Automake/Makefile.in | 32 +++++++++++++++++------- lib/Automake/tests/Makefile.in | 2 + lib/Makefile.in | 43 +++++++++++++++++++++----------- lib/am/Makefile.in | 2 + lib/am/tags.am | 26 +++++++++++++++++++- m4/Makefile.in | 2 + tests/Makefile.in | 2 + 11 files changed, 166 insertions(+), 64 deletions(-) diff --git a/Makefile.in b/Makefile.in index 56a3126..ff7ae82 100644 --- a/Makefile.in +++ b/Makefile.in @@ -92,6 +92,7 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ distdir dist dist-all distcheck ETAGS = etags CTAGS = ctags +CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) @@ -438,6 +439,10 @@ ctags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ done +cscopelist-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -500,9 +505,20 @@ GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" +cscope: cscope.files + cd $(top_builddir) && $(CSCOPE) -b -R -q -i cscope.files $(CSCOPE_ARGS) + +cscope.files: cscopelist-recursive cscopelist + +cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + for i in $$list; do \ + echo $(abs_srcdir)/$$i >> $(top_builddir)/cscope.files; \ + done distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ + cscope.po.out cscope.files distdir: $(DISTFILES) $(am__remove_distdir) @@ -788,26 +804,26 @@ ps-am: uninstall-am: uninstall-binSCRIPTS @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) uninstall-hook -.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ - install-am install-exec-am install-strip tags-recursive \ - uninstall-am +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \ + cscopelist-recursive ctags-recursive install-am \ + install-exec-am install-strip tags-recursive uninstall-am .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ all all-am am--refresh check check-am clean clean-generic \ - ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \ - dist-hook dist-lzma dist-shar dist-tarZ dist-xz dist-zip \ - distcheck distclean distclean-generic distclean-tags \ - distcleancheck distdir distuninstallcheck dvi dvi-am html \ - html-am info info-am install install-am install-binSCRIPTS \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-exec-hook install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip installcheck installcheck-am installdirs \ - installdirs-am maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ - tags-recursive uninstall uninstall-am uninstall-binSCRIPTS \ - uninstall-hook + cscope cscopelist cscopelist-recursive ctags ctags-recursive \ + dist dist-all dist-bzip2 dist-gzip dist-hook dist-lzma \ + dist-shar dist-tarZ dist-xz dist-zip distcheck distclean \ + distclean-generic distclean-tags distcleancheck distdir \ + distuninstallcheck dvi dvi-am html html-am info info-am \ + install install-am install-binSCRIPTS install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-exec-hook install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am uninstall-binSCRIPTS uninstall-hook install-exec-hook: diff --git a/automake.in b/automake.in index 20ef3bd..b5133b1 100755 --- a/automake.in +++ b/automake.in @@ -3724,6 +3724,7 @@ sub handle_tags { my @tag_deps = (); my @ctag_deps = (); + my @cscope_deps = (); if (var ('SUBDIRS')) { $output_rules .= ("tags-recursive:\n" @@ -3747,6 +3748,17 @@ sub handle_tags push (@ctag_deps, 'ctags-recursive'); &depend ('.PHONY', 'ctags-recursive'); &depend ('.MAKE', 'ctags-recursive'); + + $output_rules .= ("cscopelist-recursive:\n" + . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n" + # Never fail here if a subdir fails; it + # isn't important. + . "\t test \"\$\$subdir\" = . || (cd \$\$subdir" + . " && \$(MAKE) \$(AM_MAKEFLAGS) cscopelist); \\\n" + . "\tdone\n"); + push (@cscope_deps, 'cscopelist-recursive'); + &depend ('.PHONY', 'cscopelist-recursive'); + &depend ('.MAKE', 'cscopelist-recursive'); } if (&saw_sources_p (1) @@ -3769,7 +3781,8 @@ sub handle_tags new Automake::Location, CONFIG => "@config", TAGSDIRS => "@tag_deps", - CTAGSDIRS => "@ctag_deps"); + CTAGSDIRS => "@ctag_deps", + CSCOPEDIRS => "@cscope_deps"); set_seen 'TAGS_DEPENDENCIES'; } @@ -3784,8 +3797,9 @@ sub handle_tags # Otherwise, it would be possible for a top-level "make TAGS" # to fail because some subdirectory failed. $output_rules .= "tags: TAGS\nTAGS:\n\n"; - # Ditto ctags. + # Ditto ctags and cscope. $output_rules .= "ctags: CTAGS\nCTAGS:\n\n"; + $output_rules .= "cscopelist:\n\n"; } } diff --git a/doc/Makefile.in b/doc/Makefile.in index 6433ad8..3b86a55 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -532,8 +532,15 @@ GTAGS: && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + for i in $$list; do \ + echo $(abs_srcdir)/$$i >> $(top_builddir)/cscope.files; \ + done + distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ + cscope.po.out cscope.files distdir: $(DISTFILES) @list='$(MANS)'; if test -n "$$list"; then \ @@ -764,20 +771,21 @@ uninstall-man: uninstall-man1 .MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-aminfo \ - clean-generic ctags dist-info distclean distclean-generic \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am \ - install-dist_docDATA install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-man1 install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-aminfo maintainer-clean-generic \ - maintainer-clean-vti mostlyclean mostlyclean-aminfo \ - mostlyclean-generic mostlyclean-vti pdf pdf-am ps ps-am tags \ - uninstall uninstall-am uninstall-dist_docDATA uninstall-dvi-am \ - uninstall-html-am uninstall-info-am uninstall-man \ - uninstall-man1 uninstall-pdf-am uninstall-ps-am + clean-generic cscopelist ctags dist-info distclean \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dist_docDATA install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-man1 install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-aminfo \ + maintainer-clean-generic maintainer-clean-vti mostlyclean \ + mostlyclean-aminfo mostlyclean-generic mostlyclean-vti pdf \ + pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-dist_docDATA uninstall-dvi-am uninstall-html-am \ + uninstall-info-am uninstall-man uninstall-man1 \ + uninstall-pdf-am uninstall-ps-am $(dist_man1_MANS): $(top_srcdir)/configure.ac $(srcdir)/aclocal.1 $(srcdir)/automake.1: diff --git a/doc/automake.texi b/doc/automake.texi index 09a5dd2..240fa84 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -312,7 +312,7 @@ Support for Test Suites Miscellaneous Rules -* Tags:: Interfacing to etags and mkid +* Tags:: Interfacing to cscope, etags and mkid * Suffixes:: Handling new file extensions * Multilibs:: Support for multilibs. @@ -9302,7 +9302,7 @@ the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}. There are a few rules and variables that didn't fit anywhere else. @menu -* Tags:: Interfacing to etags and mkid +* Tags:: Interfacing to cscope, etags and mkid * Suffixes:: Handling new file extensions * Multilibs:: Support for multilibs. @end menu @@ -9364,6 +9364,13 @@ Automake will also generate an @code{ID} rule that will run directory-by-directory basis. @trindex id +Similarly, the @code{cscope} rule will create a list of all the source +files in the tree and run @command{cscope} to build an inverted index +database. The variable @code{CSCOPE} is the name of the program to +invoke (by default @command{cscope}); and @code{CSCOPEFLAGS} and +...@code{am_cscopeflags} are similar in meaning to their CTAGS +counterparts. + Finally, Automake also emits rules to support the @uref{http://www.gnu.org/software/global/, GNU Global Tags program}. The @code{GTAGS} rule runs Global Tags and puts the @@ -12885,4 +12892,4 @@ parentheses is the number of generated test cases. @c LocalWords: LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO @c LocalWords: unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS @c LocalWords: LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS -...@c LocalWords: barexec Pinard's automatize initialize lzma xz +...@c LocalWords: barexec Pinard's automatize initialize lzma xz cscope diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in index 25c2843..352a13c 100644 --- a/lib/Automake/Makefile.in +++ b/lib/Automake/Makefile.in @@ -386,6 +386,10 @@ ctags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ done +cscopelist-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -449,8 +453,15 @@ GTAGS: && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + for i in $$list; do \ + echo $(abs_srcdir)/$$i >> $(top_builddir)/cscope.files; \ + done + distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ + cscope.po.out cscope.files distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -610,17 +621,18 @@ ps-am: uninstall-am: uninstall-dist_perllibDATA uninstall-nodist_perllibDATA -.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ - install-am install-strip tags-recursive +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \ + cscopelist-recursive ctags-recursive install-am install-strip \ + tags-recursive .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ - all all-am check check-am clean clean-generic ctags \ - ctags-recursive distclean distclean-generic distclean-tags \ - distdir dvi dvi-am html html-am info info-am install \ - install-am install-data install-data-am \ - install-dist_perllibDATA install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-man \ + all all-am check check-am clean clean-generic cscopelist \ + cscopelist-recursive ctags ctags-recursive distclean \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dist_perllibDATA install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ install-nodist_perllibDATA install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs installdirs-am maintainer-clean \ diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index 9f3a097..2103667 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -273,6 +273,8 @@ TAGS: ctags: CTAGS CTAGS: +cscopelist: + # To be appended to the command running the test. Handle the stdout # and stderr redirection, and catch the exit status. diff --git a/lib/Makefile.in b/lib/Makefile.in index 3773bd1..f382dcc 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -361,6 +361,10 @@ ctags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ done +cscopelist-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -424,8 +428,15 @@ GTAGS: && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + for i in $$list; do \ + echo $(abs_srcdir)/$$i >> $(top_builddir)/cscope.files; \ + done + distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ + cscope.po.out cscope.files distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -585,22 +596,24 @@ ps-am: uninstall-am: uninstall-dist_pkgvdataDATA uninstall-dist_scriptDATA -.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ - install-am install-data-am install-strip tags-recursive +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) \ + cscopelist-recursive ctags-recursive install-am \ + install-data-am install-strip tags-recursive .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ - all all-am check check-am clean clean-generic ctags \ - ctags-recursive distclean distclean-generic distclean-tags \ - distdir dvi dvi-am html html-am info info-am install \ - install-am install-data install-data-am install-data-hook \ - install-dist_pkgvdataDATA install-dist_scriptDATA install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip installcheck installcheck-am installcheck-local \ - installdirs installdirs-am maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ - pdf-am ps ps-am tags tags-recursive uninstall uninstall-am \ + all all-am check check-am clean clean-generic cscopelist \ + cscopelist-recursive ctags ctags-recursive distclean \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-data-hook install-dist_pkgvdataDATA \ + install-dist_scriptDATA install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installcheck-local installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am tags \ + tags-recursive uninstall uninstall-am \ uninstall-dist_pkgvdataDATA uninstall-dist_scriptDATA diff --git a/lib/am/Makefile.in b/lib/am/Makefile.in index 84d09f0..0ca8c9f 100644 --- a/lib/am/Makefile.in +++ b/lib/am/Makefile.in @@ -268,6 +268,8 @@ TAGS: ctags: CTAGS CTAGS: +cscopelist: + distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ diff --git a/lib/am/tags.am b/lib/am/tags.am index f6661e2..8c8fc52 100644 --- a/lib/am/tags.am +++ b/lib/am/tags.am @@ -134,6 +134,29 @@ GTAGS: && gtags -i $(GTAGS_ARGS) "$$here" +## ------- ## +## cscope ## +## ------- ## + +if %?TOPDIR_P% + +CSCOPE = cscope +.PHONY: cscope +cscope: cscope.files + cd $(top_builddir) && $(CSCOPE) -b -R -q -i cscope.files $(CSCOPE_ARGS) + +cscope.files: %CSCOPEDIRS% cscopelist + +endif %?TOPDIR_P% + +.PHONY: cscopelist +cscopelist: %CSCOPEDIRS% $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP)'; \ + for i in $$list; do \ + echo $(abs_srcdir)/$$i >> $(top_builddir)/cscope.files; \ + done + + ## ---------- ## ## Cleaning. ## ## ---------- ## @@ -141,4 +164,5 @@ GTAGS: .PHONY distclean-am: distclean-tags distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ + cscope.po.out cscope.files diff --git a/m4/Makefile.in b/m4/Makefile.in index bb7bbf9..c03eb14 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -265,6 +265,8 @@ TAGS: ctags: CTAGS CTAGS: +cscopelist: + distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ diff --git a/tests/Makefile.in b/tests/Makefile.in index ce8e779..5efcbfc 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1016,6 +1016,8 @@ TAGS: ctags: CTAGS CTAGS: +cscopelist: + # To be appended to the command running the test. Handle the stdout # and stderr redirection, and catch the exit status. -- 1.6.1 Happy hacking, Debarshi -- One reason that life is complex is that it has a real part and an imaginary part. -- Andrew Koenig