xref: /onnv-gate/usr/src/tools/scripts/xref.mk (revision 1839)
10Sstevel@tonic-gate#
2*1839Srscott# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate# Use is subject to license terms.
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# CDDL HEADER START
60Sstevel@tonic-gate#
70Sstevel@tonic-gate# The contents of this file are subject to the terms of the
8*1839Srscott# Common Development and Distribution License (the "License").
9*1839Srscott# You may not use this file except in compliance with the License.
100Sstevel@tonic-gate#
110Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
120Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
130Sstevel@tonic-gate# See the License for the specific language governing permissions
140Sstevel@tonic-gate# and limitations under the License.
150Sstevel@tonic-gate#
160Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
170Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
180Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
190Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
200Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
210Sstevel@tonic-gate#
220Sstevel@tonic-gate# CDDL HEADER END
230Sstevel@tonic-gate#
240Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
250Sstevel@tonic-gate#
260Sstevel@tonic-gate# This Makefile is used exclusively by `xref' to generate and maintain
270Sstevel@tonic-gate# cross-reference databases (right now: cscope, ctags, and etags).
280Sstevel@tonic-gate#
290Sstevel@tonic-gate# By default, the cross-reference is built for all files underneath the
300Sstevel@tonic-gate# currrent working directory that match the criteria specified in the
310Sstevel@tonic-gate# xref.files rule below, and any files that would also be hauled over as
320Sstevel@tonic-gate# part of a `bringover' of the working directory (though this can be
330Sstevel@tonic-gate# turned off via the -f flag to `xref').
340Sstevel@tonic-gate#
350Sstevel@tonic-gate# However, this behavior can be customized in each directory of the build
360Sstevel@tonic-gate# tree through the following Makefile macros, if necessary:
370Sstevel@tonic-gate#
380Sstevel@tonic-gate#   XRDIRS:	The list of directories to include; defaults to `.'.
390Sstevel@tonic-gate#		The more interesting directories should be listed earlier.
400Sstevel@tonic-gate#   XRPRUNE:	The list of directories to prune out.
410Sstevel@tonic-gate#   XRADD:	The list of additional filename globs to include.
420Sstevel@tonic-gate#   XRDEL:	The list of additional filename globs to exclude.
430Sstevel@tonic-gate#   XRINCDIRS:	The list of additional include paths, in "foo bar" format.
440Sstevel@tonic-gate#   XRINCS:	The list of additional include paths, in "-Ifoo -Ibar" format.
450Sstevel@tonic-gate#
460Sstevel@tonic-gate# Note that XRINCDIRS and XRINCS are for specifying header paths that are
470Sstevel@tonic-gate# not already included in CPPFLAGS and HDRDIR.
480Sstevel@tonic-gate#
490Sstevel@tonic-gate# These macros are assumed to be set in a file named `Makefile', but this
500Sstevel@tonic-gate# too can be overridden via the -m option to `xref'.
510Sstevel@tonic-gate#
520Sstevel@tonic-gate# This Makefile should *never* be included by other Makefiles.
530Sstevel@tonic-gate#
540Sstevel@tonic-gate
550Sstevel@tonic-gateXRMAKEFILE=Makefile
560Sstevel@tonic-gateinclude $(SRC)/Makefile.master
570Sstevel@tonic-gate
580Sstevel@tonic-gate#
590Sstevel@tonic-gate# Default values for the cross-reference tools; these can be overridden
600Sstevel@tonic-gate# either in the environment or in XRMAKEFILE.  To use regular cscope, set
610Sstevel@tonic-gate# CSCOPE to cscope and CSFLAGS to -b.
620Sstevel@tonic-gate#
630Sstevel@tonic-gateCSCOPE	= $(BUILD_TOOLS)/onbld/bin/$(MACH)/cscope-fast
640Sstevel@tonic-gateCSFLAGS	= -bq
650Sstevel@tonic-gateCTAGS	= /usr/bin/ctags
660Sstevel@tonic-gateCTFLAGS	= -wt
670Sstevel@tonic-gateETAGS	= $(SPRO_VROOT)/bin/etags
680Sstevel@tonic-gateETFLAGS	= -t
690Sstevel@tonic-gateFLGFLP	= $(BUILD_TOOLS)/onbld/bin/flg.flp
700Sstevel@tonic-gate
710Sstevel@tonic-gateXRDIRS	= .
720Sstevel@tonic-gateXRINCS	= $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS)
730Sstevel@tonic-gate
740Sstevel@tonic-gateinclude $(XRMAKEFILE)
750Sstevel@tonic-gate
76*1839SrscottXRADDDEF	= *.[Ccshlxy] Makefile* *.il* *.cc llib-* *.xml *.dtd.*
770Sstevel@tonic-gateXRDELDEF	= *.ln
780Sstevel@tonic-gateXRFINDADD	= $(XRADDDEF:%=-o -name '%') $(XRADD:%=-o -name '%')
790Sstevel@tonic-gateXRFINDDEL	= $(XRDELDEF:%=-a ! -name '%') $(XRDEL:%=-a ! -name '%')
800Sstevel@tonic-gateXRFINDPRUNE	= $(XRPRUNE:%=-o -name '%')
810Sstevel@tonic-gateXRSEDPRUNE	= $(XRPRUNE:%=/\/%\//d; /^%\//d;)
820Sstevel@tonic-gate
830Sstevel@tonic-gate.KEEP_STATE:
840Sstevel@tonic-gate.PRECIOUS: cscope.out cscope.in.out cscope.po.out tags TAGS
850Sstevel@tonic-gate
860Sstevel@tonic-gate#
870Sstevel@tonic-gate# Build the list of files to be included in the cross-reference database.
880Sstevel@tonic-gate#
890Sstevel@tonic-gate# Please note that:
900Sstevel@tonic-gate#
910Sstevel@tonic-gate#	* Any additional FLG-related source files are in xref.flg.
920Sstevel@tonic-gate#
930Sstevel@tonic-gate#	* We use relative pathnames for the file list; this makes it easier
940Sstevel@tonic-gate#	  to share the resulting cross-reference across machines.  We also
950Sstevel@tonic-gate#	  strip the leading './' off of pathnames (if necessary) so that we
960Sstevel@tonic-gate#	  don't trip up vi (since it thinks foo.c and ./foo.c are different
970Sstevel@tonic-gate#	  files).
980Sstevel@tonic-gate#
990Sstevel@tonic-gate#	* We strip out any duplicate file names, being careful not to
1000Sstevel@tonic-gate#	  disturb the order of the file list.
1010Sstevel@tonic-gate#
1020Sstevel@tonic-gate#	* We put all the Makefiles at the end of the file list, since they're
1030Sstevel@tonic-gate#	  not really source files and thus can cause problems.
1040Sstevel@tonic-gate#
1050Sstevel@tonic-gate#	* We otherwise do not sort the file list, since we assume that if
1060Sstevel@tonic-gate#	  the order matters, then XRDIRS would've been set so that the more
1070Sstevel@tonic-gate#	  important directories are first.
1080Sstevel@tonic-gate#
1090Sstevel@tonic-gatexref.files:
1100Sstevel@tonic-gate	$(TOUCH) xref.flg
1110Sstevel@tonic-gate	$(FIND) $(XRDIRS) `$(CAT) xref.flg` -name SCCS -prune		\
1120Sstevel@tonic-gate	    -o -type d \( -name '.del-*' $(XRFINDPRUNE) \) -prune	\
113*1839Srscott	    -o -type f \( \( -name '' $(XRFINDADD) \) $(XRFINDDEL) \) -print |\
1140Sstevel@tonic-gate	    $(PERL) -ne 's:^\./::; next if ($$seen{$$_}++); print' > xref.tmp
1150Sstevel@tonic-gate	> xref.files
1160Sstevel@tonic-gate	-$(GREP) -v Makefile xref.tmp >> xref.files
1170Sstevel@tonic-gate	-$(GREP) Makefile xref.tmp >> xref.files
1180Sstevel@tonic-gate	$(RM) xref.tmp
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate#
1210Sstevel@tonic-gate# Use the .flg files to assemble a list of other source files that are
1220Sstevel@tonic-gate# important for building the sources in XRDIRS.  So that the list can be
1230Sstevel@tonic-gate# fed to the $(FIND) in xref.files, we tell $(FLGFLP) to generate relative
1240Sstevel@tonic-gate# pathnames.  We filter out any files that are along paths that are being
1250Sstevel@tonic-gate# pruned.
1260Sstevel@tonic-gate#
1270Sstevel@tonic-gatexref.flg:
1280Sstevel@tonic-gate	> xref.tmp
1290Sstevel@tonic-gate	for dir in $(XRDIRS); do					\
1300Sstevel@tonic-gate		$(FLGFLP) -r $$dir >> xref.tmp;				\
1310Sstevel@tonic-gate	done
1320Sstevel@tonic-gate	$(SED) '$(XRSEDPRUNE)' < xref.tmp | $(SORT) -u > xref.flg
1330Sstevel@tonic-gate	$(RM) xref.tmp
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate#
1360Sstevel@tonic-gate# Note that we don't remove the old cscope.out since cscope is smart enough
1370Sstevel@tonic-gate# to rebuild only what has changed.  It can become confused, however, if files
1380Sstevel@tonic-gate# are renamed or removed, so it may be necessary to do an `xref -c' if
1390Sstevel@tonic-gate# a lot of reorganization has occured.
1400Sstevel@tonic-gate#
1410Sstevel@tonic-gatexref.cscope: xref.files
1420Sstevel@tonic-gate	-$(ECHO) $(XRINCS) | $(XARGS) -n1 | $(GREP) '^-I' | 		\
1430Sstevel@tonic-gate	    $(CAT) - xref.files > cscope.files
1440Sstevel@tonic-gate	$(CSCOPE) $(CSFLAGS)
1450Sstevel@tonic-gate
1460Sstevel@tonic-gatexref.cscope.clobber: xref.clean
1470Sstevel@tonic-gate	-$(RM) cscope.out cscope.in.out cscope.po.out cscope.files
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate#
1500Sstevel@tonic-gate# Create tags databases, similar to above.
1510Sstevel@tonic-gate#
1520Sstevel@tonic-gate# Since assembler files contain C fragments for lint, the lint fragments will
1530Sstevel@tonic-gate# allow tags to "work" on assembler.  Please note that:
1540Sstevel@tonic-gate#
1550Sstevel@tonic-gate#	* We order the tags file such that source files that tags seems to
1560Sstevel@tonic-gate#	  get along with best are earlier in the list, and so that structure
1570Sstevel@tonic-gate#	  definitions are ordered before their uses.
1580Sstevel@tonic-gate#
1590Sstevel@tonic-gate#	* We *don't* sort the file list within a given suffix, since we
1600Sstevel@tonic-gate#	  assume that if someone cared about ordering, they would've already
1610Sstevel@tonic-gate#	  set XRDIRS so that the more important directories are first.
1620Sstevel@tonic-gate#
1630Sstevel@tonic-gate#	* We include "/dev/null" in the xref.ctags rule to prevent ctags
1640Sstevel@tonic-gate#	  from barfing if "xref.tfiles" ends up empty (alas, ctags is
1650Sstevel@tonic-gate#	  too lame to read its file list from stdin like etags does).
1660Sstevel@tonic-gate#
1670Sstevel@tonic-gate
1680Sstevel@tonic-gatexref.ctags: xref.tfiles
1690Sstevel@tonic-gate	$(CTAGS) $(CTFLAGS) /dev/null `$(CAT) xref.tfiles`
1700Sstevel@tonic-gate
1710Sstevel@tonic-gatexref.ctags.clobber: xref.clean
1720Sstevel@tonic-gate	-$(RM) tags
1730Sstevel@tonic-gate
1740Sstevel@tonic-gatexref.etags: xref.tfiles
1750Sstevel@tonic-gate	$(CAT) xref.tfiles | $(ETAGS) $(ETFLAGS) -
1760Sstevel@tonic-gate
1770Sstevel@tonic-gatexref.etags.check:
1780Sstevel@tonic-gate	@$(CAT) /dev/null | $(ETAGS) -
1790Sstevel@tonic-gate
1800Sstevel@tonic-gatexref.etags.clobber: xref.clean
1810Sstevel@tonic-gate	-$(RM) TAGS
1820Sstevel@tonic-gate
1830Sstevel@tonic-gatexref.tfiles: xref.files
1840Sstevel@tonic-gate	> xref.tfiles
1850Sstevel@tonic-gate	-for suffix in h c C cc l y s; do				\
1860Sstevel@tonic-gate		$(GREP) "\.$${suffix}$$" xref.files >> xref.tfiles;	\
1870Sstevel@tonic-gate	done
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate#
1900Sstevel@tonic-gate# Note that we put `cscope.files' in clobber rather than clean because
1910Sstevel@tonic-gate# cscope will whine if it doesn't exist (unless it's passed -d).
1920Sstevel@tonic-gate#
1930Sstevel@tonic-gatexref.clean:
1940Sstevel@tonic-gate	-$(RM) xref.tfiles xref.files xref.tmp xref.flg ncscope.*
195