17c478bd9Sstevel@tonic-gate# 27c478bd9Sstevel@tonic-gate# CDDL HEADER START 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 5e82f9cedSrscott# Common Development and Distribution License (the "License"). 6e82f9cedSrscott# You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate# 87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate# and limitations under the License. 127c478bd9Sstevel@tonic-gate# 137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# CDDL HEADER END 207c478bd9Sstevel@tonic-gate# 21*fa116a1bSmeem# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 22697b2d24Sraf# Use is subject to license terms. 23697b2d24Sraf# 247c478bd9Sstevel@tonic-gate# This Makefile is used exclusively by `xref' to generate and maintain 257c478bd9Sstevel@tonic-gate# cross-reference databases (right now: cscope, ctags, and etags). 267c478bd9Sstevel@tonic-gate# 277c478bd9Sstevel@tonic-gate# By default, the cross-reference is built for all files underneath the 287c478bd9Sstevel@tonic-gate# currrent working directory that match the criteria specified in the 297c478bd9Sstevel@tonic-gate# xref.files rule below, and any files that would also be hauled over as 307c478bd9Sstevel@tonic-gate# part of a `bringover' of the working directory (though this can be 317c478bd9Sstevel@tonic-gate# turned off via the -f flag to `xref'). 327c478bd9Sstevel@tonic-gate# 337c478bd9Sstevel@tonic-gate# However, this behavior can be customized in each directory of the build 347c478bd9Sstevel@tonic-gate# tree through the following Makefile macros, if necessary: 357c478bd9Sstevel@tonic-gate# 367c478bd9Sstevel@tonic-gate# XRDIRS: The list of directories to include; defaults to `.'. 377c478bd9Sstevel@tonic-gate# The more interesting directories should be listed earlier. 387c478bd9Sstevel@tonic-gate# XRPRUNE: The list of directories to prune out. 397c478bd9Sstevel@tonic-gate# XRADD: The list of additional filename globs to include. 407c478bd9Sstevel@tonic-gate# XRDEL: The list of additional filename globs to exclude. 417c478bd9Sstevel@tonic-gate# XRINCDIRS: The list of additional include paths, in "foo bar" format. 427c478bd9Sstevel@tonic-gate# XRINCS: The list of additional include paths, in "-Ifoo -Ibar" format. 437c478bd9Sstevel@tonic-gate# 447c478bd9Sstevel@tonic-gate# Note that XRINCDIRS and XRINCS are for specifying header paths that are 457c478bd9Sstevel@tonic-gate# not already included in CPPFLAGS and HDRDIR. 467c478bd9Sstevel@tonic-gate# 477c478bd9Sstevel@tonic-gate# These macros are assumed to be set in a file named `Makefile', but this 487c478bd9Sstevel@tonic-gate# too can be overridden via the -m option to `xref'. 497c478bd9Sstevel@tonic-gate# 507c478bd9Sstevel@tonic-gate# This Makefile should *never* be included by other Makefiles. 517c478bd9Sstevel@tonic-gate# 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gateXRMAKEFILE=Makefile 547c478bd9Sstevel@tonic-gateinclude $(SRC)/Makefile.master 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate# 577c478bd9Sstevel@tonic-gate# Default values for the cross-reference tools; these can be overridden 587c478bd9Sstevel@tonic-gate# either in the environment or in XRMAKEFILE. To use regular cscope, set 597c478bd9Sstevel@tonic-gate# CSCOPE to cscope and CSFLAGS to -b. 607c478bd9Sstevel@tonic-gate# 617c478bd9Sstevel@tonic-gateCSCOPE = $(BUILD_TOOLS)/onbld/bin/$(MACH)/cscope-fast 627c478bd9Sstevel@tonic-gateCSFLAGS = -bq 637c478bd9Sstevel@tonic-gateCTAGS = /usr/bin/ctags 647c478bd9Sstevel@tonic-gateCTFLAGS = -wt 657c478bd9Sstevel@tonic-gateETAGS = $(SPRO_VROOT)/bin/etags 667c478bd9Sstevel@tonic-gateETFLAGS = -t 677c478bd9Sstevel@tonic-gateFLGFLP = $(BUILD_TOOLS)/onbld/bin/flg.flp 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gateXRDIRS = . 707c478bd9Sstevel@tonic-gateXRINCS = $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS) 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gateinclude $(XRMAKEFILE) 737c478bd9Sstevel@tonic-gate 74*fa116a1bSmeemXRADDLIST = $(XRADD) *.[Ccdshlxy] Makefile* *.il* *.cc llib-* *.xml \ 75*fa116a1bSmeem *.dtd.* *.ndl 76*fa116a1bSmeemXRDELLIST = $(XRDEL) *.ln 77*fa116a1bSmeemXRPRUNELIST = $(XRPRUNE) .hg 78*fa116a1bSmeemXRFINDADD = $(XRADDLIST:%=-o -name '%') 79*fa116a1bSmeemXRFINDDEL = $(XRDELLIST:%=-a ! -name '%') 80*fa116a1bSmeemXRFINDPRUNE = $(XRPRUNELIST:%=-o -name '%') 81*fa116a1bSmeemXRSEDPRUNE = $(XRPRUNELIST:%=/\/%\//d; /^%\//d;) 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate.KEEP_STATE: 847c478bd9Sstevel@tonic-gate.PRECIOUS: cscope.out cscope.in.out cscope.po.out tags TAGS 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate# 877c478bd9Sstevel@tonic-gate# Build the list of files to be included in the cross-reference database. 887c478bd9Sstevel@tonic-gate# 897c478bd9Sstevel@tonic-gate# Please note that: 907c478bd9Sstevel@tonic-gate# 917c478bd9Sstevel@tonic-gate# * Any additional FLG-related source files are in xref.flg. 927c478bd9Sstevel@tonic-gate# 937c478bd9Sstevel@tonic-gate# * We use relative pathnames for the file list; this makes it easier 947c478bd9Sstevel@tonic-gate# to share the resulting cross-reference across machines. We also 957c478bd9Sstevel@tonic-gate# strip the leading './' off of pathnames (if necessary) so that we 967c478bd9Sstevel@tonic-gate# don't trip up vi (since it thinks foo.c and ./foo.c are different 977c478bd9Sstevel@tonic-gate# files). 987c478bd9Sstevel@tonic-gate# 997c478bd9Sstevel@tonic-gate# * We strip out any duplicate file names, being careful not to 1007c478bd9Sstevel@tonic-gate# disturb the order of the file list. 1017c478bd9Sstevel@tonic-gate# 1027c478bd9Sstevel@tonic-gate# * We put all the Makefiles at the end of the file list, since they're 1037c478bd9Sstevel@tonic-gate# not really source files and thus can cause problems. 1047c478bd9Sstevel@tonic-gate# 1057c478bd9Sstevel@tonic-gate# * We otherwise do not sort the file list, since we assume that if 1067c478bd9Sstevel@tonic-gate# the order matters, then XRDIRS would've been set so that the more 1077c478bd9Sstevel@tonic-gate# important directories are first. 1087c478bd9Sstevel@tonic-gate# 1097c478bd9Sstevel@tonic-gatexref.files: 1107c478bd9Sstevel@tonic-gate $(TOUCH) xref.flg 111*fa116a1bSmeem $(FIND) $(XRDIRS) `$(CAT) xref.flg` \ 112*fa116a1bSmeem -type d \( -name SCCS $(XRFINDPRUNE) \) -prune -o \ 113*fa116a1bSmeem -type f \( \( -name '' $(XRFINDADD) \) $(XRFINDDEL) \) -print |\ 1147c478bd9Sstevel@tonic-gate $(PERL) -ne 's:^\./::; next if ($$seen{$$_}++); print' > xref.tmp 1157c478bd9Sstevel@tonic-gate > xref.files 1167c478bd9Sstevel@tonic-gate -$(GREP) -v Makefile xref.tmp >> xref.files 1177c478bd9Sstevel@tonic-gate -$(GREP) Makefile xref.tmp >> xref.files 1187c478bd9Sstevel@tonic-gate $(RM) xref.tmp 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate# 1217c478bd9Sstevel@tonic-gate# Use the .flg files to assemble a list of other source files that are 1227c478bd9Sstevel@tonic-gate# important for building the sources in XRDIRS. So that the list can be 1237c478bd9Sstevel@tonic-gate# fed to the $(FIND) in xref.files, we tell $(FLGFLP) to generate relative 1247c478bd9Sstevel@tonic-gate# pathnames. We filter out any files that are along paths that are being 1257c478bd9Sstevel@tonic-gate# pruned. 1267c478bd9Sstevel@tonic-gate# 1277c478bd9Sstevel@tonic-gatexref.flg: 1287c478bd9Sstevel@tonic-gate > xref.tmp 1297c478bd9Sstevel@tonic-gate for dir in $(XRDIRS); do \ 1307c478bd9Sstevel@tonic-gate $(FLGFLP) -r $$dir >> xref.tmp; \ 1317c478bd9Sstevel@tonic-gate done 1327c478bd9Sstevel@tonic-gate $(SED) '$(XRSEDPRUNE)' < xref.tmp | $(SORT) -u > xref.flg 1337c478bd9Sstevel@tonic-gate $(RM) xref.tmp 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate# 1367c478bd9Sstevel@tonic-gate# Note that we don't remove the old cscope.out since cscope is smart enough 1377c478bd9Sstevel@tonic-gate# to rebuild only what has changed. It can become confused, however, if files 1387c478bd9Sstevel@tonic-gate# are renamed or removed, so it may be necessary to do an `xref -c' if 1397c478bd9Sstevel@tonic-gate# a lot of reorganization has occured. 1407c478bd9Sstevel@tonic-gate# 1417c478bd9Sstevel@tonic-gatexref.cscope: xref.files 1427c478bd9Sstevel@tonic-gate -$(ECHO) $(XRINCS) | $(XARGS) -n1 | $(GREP) '^-I' | \ 1437c478bd9Sstevel@tonic-gate $(CAT) - xref.files > cscope.files 1447c478bd9Sstevel@tonic-gate $(CSCOPE) $(CSFLAGS) 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gatexref.cscope.clobber: xref.clean 1477c478bd9Sstevel@tonic-gate -$(RM) cscope.out cscope.in.out cscope.po.out cscope.files 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate# 1507c478bd9Sstevel@tonic-gate# Create tags databases, similar to above. 1517c478bd9Sstevel@tonic-gate# 1527c478bd9Sstevel@tonic-gate# Since assembler files contain C fragments for lint, the lint fragments will 1537c478bd9Sstevel@tonic-gate# allow tags to "work" on assembler. Please note that: 1547c478bd9Sstevel@tonic-gate# 1557c478bd9Sstevel@tonic-gate# * We order the tags file such that source files that tags seems to 1567c478bd9Sstevel@tonic-gate# get along with best are earlier in the list, and so that structure 1577c478bd9Sstevel@tonic-gate# definitions are ordered before their uses. 1587c478bd9Sstevel@tonic-gate# 1597c478bd9Sstevel@tonic-gate# * We *don't* sort the file list within a given suffix, since we 1607c478bd9Sstevel@tonic-gate# assume that if someone cared about ordering, they would've already 1617c478bd9Sstevel@tonic-gate# set XRDIRS so that the more important directories are first. 1627c478bd9Sstevel@tonic-gate# 1637c478bd9Sstevel@tonic-gate# * We include "/dev/null" in the xref.ctags rule to prevent ctags 1647c478bd9Sstevel@tonic-gate# from barfing if "xref.tfiles" ends up empty (alas, ctags is 1657c478bd9Sstevel@tonic-gate# too lame to read its file list from stdin like etags does). 1667c478bd9Sstevel@tonic-gate# 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gatexref.ctags: xref.tfiles 1697c478bd9Sstevel@tonic-gate $(CTAGS) $(CTFLAGS) /dev/null `$(CAT) xref.tfiles` 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gatexref.ctags.clobber: xref.clean 1727c478bd9Sstevel@tonic-gate -$(RM) tags 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gatexref.etags: xref.tfiles 1757c478bd9Sstevel@tonic-gate $(CAT) xref.tfiles | $(ETAGS) $(ETFLAGS) - 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gatexref.etags.check: 1787c478bd9Sstevel@tonic-gate @$(CAT) /dev/null | $(ETAGS) - 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gatexref.etags.clobber: xref.clean 1817c478bd9Sstevel@tonic-gate -$(RM) TAGS 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gatexref.tfiles: xref.files 1847c478bd9Sstevel@tonic-gate > xref.tfiles 1857c478bd9Sstevel@tonic-gate -for suffix in h c C cc l y s; do \ 1867c478bd9Sstevel@tonic-gate $(GREP) "\.$${suffix}$$" xref.files >> xref.tfiles; \ 1877c478bd9Sstevel@tonic-gate done 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate# 1907c478bd9Sstevel@tonic-gate# Note that we put `cscope.files' in clobber rather than clean because 1917c478bd9Sstevel@tonic-gate# cscope will whine if it doesn't exist (unless it's passed -d). 1927c478bd9Sstevel@tonic-gate# 1937c478bd9Sstevel@tonic-gatexref.clean: 1947c478bd9Sstevel@tonic-gate -$(RM) xref.tfiles xref.files xref.tmp xref.flg ncscope.* 195