xref: /titanic_50/usr/src/tools/scripts/xref.mk (revision 134a1f4e3289b54e0f980e9cf05352e419a60bee)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
22# Use is subject to license terms.
23#
24# This Makefile is used exclusively by `xref' to generate and maintain
25# cross-reference databases (right now: cscope, ctags, and etags).
26#
27# By default, the cross-reference is built for all files underneath the
28# currrent working directory that match the criteria specified in the
29# xref.files rule below, and any files that would also be hauled over as
30# part of a `bringover' of the working directory (though this can be
31# turned off via the -f flag to `xref').
32#
33# However, this behavior can be customized in each directory of the build
34# tree through the following Makefile macros, if necessary:
35#
36#   XRDIRS:	The list of directories to include; defaults to `.'.
37#		The more interesting directories should be listed earlier.
38#   XRPRUNE:	The list of directories to prune out.
39#   XRADD:	The list of additional filename globs to include.
40#   XRDEL:	The list of additional filename globs to exclude.
41#   XRINCDIRS:	The list of additional include paths, in "foo bar" format.
42#   XRINCS:	The list of additional include paths, in "-Ifoo -Ibar" format.
43#
44# Note that XRINCDIRS and XRINCS are for specifying header paths that are
45# not already included in CPPFLAGS and HDRDIR.
46#
47# These macros are assumed to be set in a file named `Makefile', but this
48# too can be overridden via the -m option to `xref'.
49#
50# This Makefile should *never* be included by other Makefiles.
51#
52
53XRMAKEFILE=Makefile
54include $(SRC)/Makefile.master
55
56#
57# Default values for the cross-reference tools; these can be overridden
58# either in the environment or in XRMAKEFILE.  To use regular cscope, set
59# CSCOPE to cscope and CSFLAGS to -b.
60#
61CSCOPE	= $(BUILD_TOOLS)/onbld/bin/$(MACH)/cscope-fast
62CSFLAGS	= -bq
63CTAGS	= /usr/bin/ctags
64CTFLAGS	= -wt
65ETAGS	= $(SPRO_VROOT)/bin/etags
66ETFLAGS	= -t
67FLGFLP	= $(BUILD_TOOLS)/onbld/bin/flg.flp
68
69XRDIRS	= .
70XRINCS	= $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS)
71
72include $(XRMAKEFILE)
73
74XRADDLIST	= $(XRADD) *.[Ccdshlxy] Makefile* *.il* *.cc llib-* *.xml \
75		  *.dtd.* *.ndl
76XRDELLIST	= $(XRDEL) *.ln
77XRPRUNELIST	= $(XRPRUNE) .hg
78XRFINDADD	= $(XRADDLIST:%=-o -name '%')
79XRFINDDEL	= $(XRDELLIST:%=-a ! -name '%')
80XRFINDPRUNE	= $(XRPRUNELIST:%=-o -name '%')
81XRSEDPRUNE	= $(XRPRUNELIST:%=/\/%\//d; /^%\//d;)
82
83.KEEP_STATE:
84.PRECIOUS: cscope.out cscope.in.out cscope.po.out tags TAGS
85
86#
87# Build the list of files to be included in the cross-reference database.
88#
89# Please note that:
90#
91#	* Any additional FLG-related source files are in xref.flg.
92#
93#	* We use relative pathnames for the file list; this makes it easier
94#	  to share the resulting cross-reference across machines.  We also
95#	  strip the leading './' off of pathnames (if necessary) so that we
96#	  don't trip up vi (since it thinks foo.c and ./foo.c are different
97#	  files).
98#
99#	* We strip out any duplicate file names, being careful not to
100#	  disturb the order of the file list.
101#
102#	* We put all the Makefiles at the end of the file list, since they're
103#	  not really source files and thus can cause problems.
104#
105#	* We otherwise do not sort the file list, since we assume that if
106#	  the order matters, then XRDIRS would've been set so that the more
107#	  important directories are first.
108#
109xref.files:
110	$(TOUCH) xref.flg
111	$(FIND) $(XRDIRS) `$(CAT) xref.flg` 			\
112	    -type d \( -name SCCS $(XRFINDPRUNE) \) -prune -o	\
113	    -type f \( \( -name '' $(XRFINDADD) \) $(XRFINDDEL) \) -print |\
114	    $(PERL) -ne 's:^\./::; next if ($$seen{$$_}++); print' > xref.tmp
115	> xref.files
116	-$(GREP) -v Makefile xref.tmp >> xref.files
117	-$(GREP) Makefile xref.tmp >> xref.files
118	$(RM) xref.tmp
119
120#
121# Use the .flg files to assemble a list of other source files that are
122# important for building the sources in XRDIRS.  So that the list can be
123# fed to the $(FIND) in xref.files, we tell $(FLGFLP) to generate relative
124# pathnames.  We filter out any files that are along paths that are being
125# pruned.
126#
127xref.flg:
128	> xref.tmp
129	for dir in $(XRDIRS); do					\
130		$(FLGFLP) -r $$dir >> xref.tmp;				\
131	done
132	$(SED) '$(XRSEDPRUNE)' < xref.tmp | $(SORT) -u > xref.flg
133	$(RM) xref.tmp
134
135#
136# Note that we don't remove the old cscope.out since cscope is smart enough
137# to rebuild only what has changed.  It can become confused, however, if files
138# are renamed or removed, so it may be necessary to do an `xref -c' if
139# a lot of reorganization has occured.
140#
141xref.cscope: xref.files
142	-$(ECHO) $(XRINCS) | $(XARGS) -n1 | $(GREP) '^-I' | 		\
143	    $(CAT) - xref.files > cscope.files
144	$(CSCOPE) $(CSFLAGS)
145
146xref.cscope.clobber: xref.clean
147	-$(RM) cscope.out cscope.in.out cscope.po.out cscope.files
148
149#
150# Create tags databases, similar to above.
151#
152# Since assembler files contain C fragments for lint, the lint fragments will
153# allow tags to "work" on assembler.  Please note that:
154#
155#	* We order the tags file such that source files that tags seems to
156#	  get along with best are earlier in the list, and so that structure
157#	  definitions are ordered before their uses.
158#
159#	* We *don't* sort the file list within a given suffix, since we
160#	  assume that if someone cared about ordering, they would've already
161#	  set XRDIRS so that the more important directories are first.
162#
163#	* We include "/dev/null" in the xref.ctags rule to prevent ctags
164#	  from barfing if "xref.tfiles" ends up empty (alas, ctags is
165#	  too lame to read its file list from stdin like etags does).
166#
167
168xref.ctags: xref.tfiles
169	$(CTAGS) $(CTFLAGS) /dev/null `$(CAT) xref.tfiles`
170
171xref.ctags.clobber: xref.clean
172	-$(RM) tags
173
174xref.etags: xref.tfiles
175	$(CAT) xref.tfiles | $(ETAGS) $(ETFLAGS) -
176
177xref.etags.check:
178	@$(CAT) /dev/null | $(ETAGS) -
179
180xref.etags.clobber: xref.clean
181	-$(RM) TAGS
182
183xref.tfiles: xref.files
184	> xref.tfiles
185	-for suffix in h c C cc l y s; do				\
186		$(GREP) "\.$${suffix}$$" xref.files >> xref.tfiles;	\
187	done
188
189#
190# Note that we put `cscope.files' in clobber rather than clean because
191# cscope will whine if it doesn't exist (unless it's passed -d).
192#
193xref.clean:
194	-$(RM) xref.tfiles xref.files xref.tmp xref.flg ncscope.*
195