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