xref: /titanic_52/usr/src/tools/scripts/xref.mk (revision ab9a77c71b58e388d02c6199c8bfbcb998aae845)
1#
2# Copyright 2006 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 (the "License").
9# You may not use this file except in compliance with the License.
10#
11# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12# or http://www.opensolaris.org/os/licensing.
13# See the License for the specific language governing permissions
14# and limitations under the License.
15#
16# When distributing Covered Code, include this CDDL HEADER in each
17# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18# If applicable, add the following below this CDDL HEADER, with the
19# fields enclosed by brackets "[]" replaced with your own identifying
20# information: Portions Copyright [yyyy] [name of copyright owner]
21#
22# CDDL HEADER END
23#
24# ident	"%Z%%M%	%I%	%E% SMI"
25#
26# This Makefile is used exclusively by `xref' to generate and maintain
27# cross-reference databases (right now: cscope, ctags, and etags).
28#
29# By default, the cross-reference is built for all files underneath the
30# currrent working directory that match the criteria specified in the
31# xref.files rule below, and any files that would also be hauled over as
32# part of a `bringover' of the working directory (though this can be
33# turned off via the -f flag to `xref').
34#
35# However, this behavior can be customized in each directory of the build
36# tree through the following Makefile macros, if necessary:
37#
38#   XRDIRS:	The list of directories to include; defaults to `.'.
39#		The more interesting directories should be listed earlier.
40#   XRPRUNE:	The list of directories to prune out.
41#   XRADD:	The list of additional filename globs to include.
42#   XRDEL:	The list of additional filename globs to exclude.
43#   XRINCDIRS:	The list of additional include paths, in "foo bar" format.
44#   XRINCS:	The list of additional include paths, in "-Ifoo -Ibar" format.
45#
46# Note that XRINCDIRS and XRINCS are for specifying header paths that are
47# not already included in CPPFLAGS and HDRDIR.
48#
49# These macros are assumed to be set in a file named `Makefile', but this
50# too can be overridden via the -m option to `xref'.
51#
52# This Makefile should *never* be included by other Makefiles.
53#
54
55XRMAKEFILE=Makefile
56include $(SRC)/Makefile.master
57
58#
59# Default values for the cross-reference tools; these can be overridden
60# either in the environment or in XRMAKEFILE.  To use regular cscope, set
61# CSCOPE to cscope and CSFLAGS to -b.
62#
63CSCOPE	= $(BUILD_TOOLS)/onbld/bin/$(MACH)/cscope-fast
64CSFLAGS	= -bq
65CTAGS	= /usr/bin/ctags
66CTFLAGS	= -wt
67ETAGS	= $(SPRO_VROOT)/bin/etags
68ETFLAGS	= -t
69FLGFLP	= $(BUILD_TOOLS)/onbld/bin/flg.flp
70
71XRDIRS	= .
72XRINCS	= $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS)
73
74include $(XRMAKEFILE)
75
76XRADDDEF	= *.[Ccshlxy] Makefile* *.il* *.cc llib-* *.xml *.dtd.*
77XRDELDEF	= *.ln
78XRFINDADD	= $(XRADDDEF:%=-o -name '%') $(XRADD:%=-o -name '%')
79XRFINDDEL	= $(XRDELDEF:%=-a ! -name '%') $(XRDEL:%=-a ! -name '%')
80XRFINDPRUNE	= $(XRPRUNE:%=-o -name '%')
81XRSEDPRUNE	= $(XRPRUNE:%=/\/%\//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` -name SCCS -prune		\
112	    -o -type d \( -name '.del-*' $(XRFINDPRUNE) \) -prune	\
113	    -o -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