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