tags (ID, cscope): also process config header (if any)
[platform/upstream/automake.git] / lib / am / tags.am
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 1994-2012 Free Software Foundation, Inc.
3
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
7 ## any later version.
8
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ## GNU General Public License for more details.
13
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 ## ---- ##
18 ## ID.  ##
19 ## ---- ##
20
21 ID: $(HEADERS) $(SOURCES) %CONFIG% $(TAGS_FILES) $(LISP)
22 ## Make sure the list of sources is unique.
23         list='$(SOURCES) %CONFIG% $(HEADERS) $(LISP) $(TAGS_FILES)'; \
24         unique=`for i in $$list; do \
25 ## Handle VPATH correctly.
26             if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
27           done | \
28           $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
29               END { if (nonempty) { for (i in files) print i; }; }'`; \
30         mkid -fID $$unique
31
32
33 ## ------ ##
34 ## TAGS.  ##
35 ## ------ ##
36
37 ETAGS = etags
38 .PHONY: tags
39 if %?SUBDIRS%
40 AM_RECURSIVE_TARGETS += tags TAGS
41 endif %?SUBDIRS%
42 tags: TAGS
43
44 TAGS: %TAGSDIRS% $(HEADERS) $(SOURCES) %CONFIG% $(TAGS_DEPENDENCIES) \
45                 $(TAGS_FILES) $(LISP)
46 ## We use the positional parameters to build the subdir list with
47 ## absolute names, without the need to worry about white space in `pwd`.
48         set x; \
49         here=`pwd`; \
50 ## Exuberant Ctags wants --etags-include,
51 ## GNU Etags             --include
52 ## Furthermore Exuberant Ctags 5.5.4 fails to create TAGS files
53 ## when no files are supplied, despite any --etags-include option.
54 ## A workaround is to pass '.' as a file.  This is what $empty_fix is for.
55 ?SUBDIRS?       if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
56 ?SUBDIRS?         include_option=--etags-include; \
57 ?SUBDIRS?         empty_fix=.; \
58 ?SUBDIRS?       else \
59 ?SUBDIRS?         include_option=--include; \
60 ?SUBDIRS?         empty_fix=; \
61 ?SUBDIRS?       fi; \
62 ?SUBDIRS?       list='$(SUBDIRS)'; for subdir in $$list; do \
63 ## Do nothing if we're trying to look in '.'.
64 ?SUBDIRS?         if test "$$subdir" = .; then :; else \
65 ?SUBDIRS?           test ! -f $$subdir/TAGS || \
66 ## Note that the = is mandatory for --etags-include.
67 ?SUBDIRS?             set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
68 ?SUBDIRS?         fi; \
69 ?SUBDIRS?       done; \
70 ## Make sure the list of sources is unique.
71         list='$(SOURCES) $(HEADERS) %CONFIG% $(LISP) $(TAGS_FILES)'; \
72         unique=`for i in $$list; do \
73 ## Handle VPATH correctly.
74             if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
75           done | \
76           $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
77               END { if (nonempty) { for (i in files) print i; }; }'`; \
78 ## Remove the 'x' we added first:
79         shift; \
80 ## Make sure we have something to run etags on.
81         if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
82           test -n "$$unique" || unique=$$empty_fix; \
83           if test $$# -gt 0; then \
84             $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
85               "$$@" $$unique; \
86           else \
87             $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
88               $$unique; \
89           fi; \
90         fi
91
92
93 ## --------------- ##
94 ## vi-style tags.  ##
95 ## --------------- ##
96
97 CTAGS = ctags
98 .PHONY: CTAGS ctags
99 if %?SUBDIRS%
100 AM_RECURSIVE_TARGETS += ctags CTAGS
101 endif %?SUBDIRS%
102 ctags: CTAGS
103
104 ## We have a dummy name here because 'tags' has already been in use
105 ## for a long time to mean Emacs-style tags.  Oops.  This means the
106 ## dependencies here are useless.
107 CTAGS: %CTAGSDIRS% $(HEADERS) $(SOURCES) %CONFIG% $(TAGS_DEPENDENCIES) \
108                 $(TAGS_FILES) $(LISP)
109 ## Make sure the list of sources is unique.
110         list='$(SOURCES) $(HEADERS) %CONFIG% $(LISP) $(TAGS_FILES)'; \
111         unique=`for i in $$list; do \
112 ## Handle VPATH correctly.
113             if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
114           done | \
115           $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
116               END { if (nonempty) { for (i in files) print i; }; }'`; \
117 ## Make sure we have something to run ctags on.
118         test -z "$(CTAGS_ARGS)$$unique" \
119           || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
120              $$unique
121
122
123 ## --------------- ##
124 ## "Global tags".  ##
125 ## --------------- ##
126
127 .PHONY: GTAGS
128 GTAGS:
129         here=`$(am__cd) $(top_builddir) && pwd` \
130           && $(am__cd) $(top_srcdir) \
131           && gtags -i $(GTAGS_ARGS) "$$here"
132
133
134 ## ------- ##
135 ## cscope  ##
136 ## ------- ##
137
138 if %?TOPDIR_P%
139
140 CSCOPE = cscope
141 .PHONY: cscope clean-cscope
142 AM_RECURSIVE_TARGETS += cscope
143
144 cscope: cscope.files
145         test ! -s cscope.files \
146           || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS)
147
148 clean-cscope:
149         -rm -f cscope.files
150
151 cscope.files: clean-cscope %CSCOPEDIRS% cscopelist
152
153 endif %?TOPDIR_P%
154
155 .PHONY: cscopelist
156 cscopelist: %CSCOPEDIRS% $(HEADERS) $(SOURCES) %CONFIG% $(LISP)
157         list='$(HEADERS) $(SOURCES) %CONFIG% $(LISP)'; \
158         case "$(srcdir)" in \
159           [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
160           *) sdir=$(subdir)/$(srcdir) ;; \
161         esac; \
162         for i in $$list; do \
163           if test -f "$$i"; then \
164             echo "$(subdir)/$$i"; \
165           else \
166             echo "$$sdir/$$i"; \
167           fi; \
168         done >> $(top_builddir)/cscope.files
169
170
171 ## ---------- ##
172 ## Cleaning.  ##
173 ## ---------- ##
174
175 .PHONY distclean-am: distclean-tags
176
177 distclean-tags:
178         -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
179 if %?TOPDIR_P%
180         -rm -f cscope.out cscope.in.out cscope.po.out cscope.files
181 endif %?TOPDIR_P%