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# 21fa116a1bSmeem# 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 65*8c426718SRichard Lowe 66*8c426718SRichard Lowe# etags was historically part of the Sun compiler distribution and is now 67*8c426718SRichard Lowe# distributed in various ways for illumos, we do a path search lacking better 68*8c426718SRichard Lowe# options. 69*8c426718SRichard LoweETAGS = etags 70*8c426718SRichard LoweETFLAGS = 71*8c426718SRichard Lowe 727c478bd9Sstevel@tonic-gateFLGFLP = $(BUILD_TOOLS)/onbld/bin/flg.flp 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gateXRDIRS = . 757c478bd9Sstevel@tonic-gateXRINCS = $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS) 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gateinclude $(XRMAKEFILE) 787c478bd9Sstevel@tonic-gate 79ce09a0a6SRichard LoweXRADDLIST = $(XRADD) *.[CcdSshlxy] Makefile* *.cc *.xml \ 80fa116a1bSmeem *.dtd.* *.ndl 81ce09a0a6SRichard LoweXRDELLIST = $(XRDEL) 82ce09a0a6SRichard LoweXRPRUNELIST = $(XRPRUNE) .hg .git 83fa116a1bSmeemXRFINDADD = $(XRADDLIST:%=-o -name '%') 84fa116a1bSmeemXRFINDDEL = $(XRDELLIST:%=-a ! -name '%') 85fa116a1bSmeemXRFINDPRUNE = $(XRPRUNELIST:%=-o -name '%') 86fa116a1bSmeemXRSEDPRUNE = $(XRPRUNELIST:%=/\/%\//d; /^%\//d;) 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate.KEEP_STATE: 897c478bd9Sstevel@tonic-gate.PRECIOUS: cscope.out cscope.in.out cscope.po.out tags TAGS 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate# 927c478bd9Sstevel@tonic-gate# Build the list of files to be included in the cross-reference database. 937c478bd9Sstevel@tonic-gate# 947c478bd9Sstevel@tonic-gate# Please note that: 957c478bd9Sstevel@tonic-gate# 967c478bd9Sstevel@tonic-gate# * Any additional FLG-related source files are in xref.flg. 977c478bd9Sstevel@tonic-gate# 987c478bd9Sstevel@tonic-gate# * We use relative pathnames for the file list; this makes it easier 997c478bd9Sstevel@tonic-gate# to share the resulting cross-reference across machines. We also 1007c478bd9Sstevel@tonic-gate# strip the leading './' off of pathnames (if necessary) so that we 1017c478bd9Sstevel@tonic-gate# don't trip up vi (since it thinks foo.c and ./foo.c are different 1027c478bd9Sstevel@tonic-gate# files). 1037c478bd9Sstevel@tonic-gate# 1047c478bd9Sstevel@tonic-gate# * We strip out any duplicate file names, being careful not to 1057c478bd9Sstevel@tonic-gate# disturb the order of the file list. 1067c478bd9Sstevel@tonic-gate# 1077c478bd9Sstevel@tonic-gate# * We put all the Makefiles at the end of the file list, since they're 1087c478bd9Sstevel@tonic-gate# not really source files and thus can cause problems. 1097c478bd9Sstevel@tonic-gate# 1107c478bd9Sstevel@tonic-gate# * We otherwise do not sort the file list, since we assume that if 1117c478bd9Sstevel@tonic-gate# the order matters, then XRDIRS would've been set so that the more 1127c478bd9Sstevel@tonic-gate# important directories are first. 1137c478bd9Sstevel@tonic-gate# 1147c478bd9Sstevel@tonic-gatexref.files: 1157c478bd9Sstevel@tonic-gate $(TOUCH) xref.flg 116fa116a1bSmeem $(FIND) $(XRDIRS) `$(CAT) xref.flg` \ 117fa116a1bSmeem -type d \( -name SCCS $(XRFINDPRUNE) \) -prune -o \ 118fa116a1bSmeem -type f \( \( -name '' $(XRFINDADD) \) $(XRFINDDEL) \) -print |\ 1197c478bd9Sstevel@tonic-gate $(PERL) -ne 's:^\./::; next if ($$seen{$$_}++); print' > xref.tmp 1207c478bd9Sstevel@tonic-gate > xref.files 1217c478bd9Sstevel@tonic-gate -$(GREP) -v Makefile xref.tmp >> xref.files 1227c478bd9Sstevel@tonic-gate -$(GREP) Makefile xref.tmp >> xref.files 1237c478bd9Sstevel@tonic-gate $(RM) xref.tmp 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate# 1267c478bd9Sstevel@tonic-gate# Use the .flg files to assemble a list of other source files that are 1277c478bd9Sstevel@tonic-gate# important for building the sources in XRDIRS. So that the list can be 1287c478bd9Sstevel@tonic-gate# fed to the $(FIND) in xref.files, we tell $(FLGFLP) to generate relative 1297c478bd9Sstevel@tonic-gate# pathnames. We filter out any files that are along paths that are being 1307c478bd9Sstevel@tonic-gate# pruned. 1317c478bd9Sstevel@tonic-gate# 1327c478bd9Sstevel@tonic-gatexref.flg: 1337c478bd9Sstevel@tonic-gate > xref.tmp 1347c478bd9Sstevel@tonic-gate for dir in $(XRDIRS); do \ 1357c478bd9Sstevel@tonic-gate $(FLGFLP) -r $$dir >> xref.tmp; \ 1367c478bd9Sstevel@tonic-gate done 1377c478bd9Sstevel@tonic-gate $(SED) '$(XRSEDPRUNE)' < xref.tmp | $(SORT) -u > xref.flg 1387c478bd9Sstevel@tonic-gate $(RM) xref.tmp 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate# 1417c478bd9Sstevel@tonic-gate# Note that we don't remove the old cscope.out since cscope is smart enough 1427c478bd9Sstevel@tonic-gate# to rebuild only what has changed. It can become confused, however, if files 1437c478bd9Sstevel@tonic-gate# are renamed or removed, so it may be necessary to do an `xref -c' if 1447c478bd9Sstevel@tonic-gate# a lot of reorganization has occured. 1457c478bd9Sstevel@tonic-gate# 1467c478bd9Sstevel@tonic-gatexref.cscope: xref.files 1477c478bd9Sstevel@tonic-gate -$(ECHO) $(XRINCS) | $(XARGS) -n1 | $(GREP) '^-I' | \ 1487c478bd9Sstevel@tonic-gate $(CAT) - xref.files > cscope.files 1497c478bd9Sstevel@tonic-gate $(CSCOPE) $(CSFLAGS) 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gatexref.cscope.clobber: xref.clean 1527c478bd9Sstevel@tonic-gate -$(RM) cscope.out cscope.in.out cscope.po.out cscope.files 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate# 1557c478bd9Sstevel@tonic-gate# Create tags databases, similar to above. 1567c478bd9Sstevel@tonic-gate# 1577c478bd9Sstevel@tonic-gate# Since assembler files contain C fragments for lint, the lint fragments will 1587c478bd9Sstevel@tonic-gate# allow tags to "work" on assembler. Please note that: 1597c478bd9Sstevel@tonic-gate# 1607c478bd9Sstevel@tonic-gate# * We order the tags file such that source files that tags seems to 1617c478bd9Sstevel@tonic-gate# get along with best are earlier in the list, and so that structure 1627c478bd9Sstevel@tonic-gate# definitions are ordered before their uses. 1637c478bd9Sstevel@tonic-gate# 1647c478bd9Sstevel@tonic-gate# * We *don't* sort the file list within a given suffix, since we 1657c478bd9Sstevel@tonic-gate# assume that if someone cared about ordering, they would've already 1667c478bd9Sstevel@tonic-gate# set XRDIRS so that the more important directories are first. 1677c478bd9Sstevel@tonic-gate# 1687c478bd9Sstevel@tonic-gate# * We include "/dev/null" in the xref.ctags rule to prevent ctags 1697c478bd9Sstevel@tonic-gate# from barfing if "xref.tfiles" ends up empty (alas, ctags is 1707c478bd9Sstevel@tonic-gate# too lame to read its file list from stdin like etags does). 1717c478bd9Sstevel@tonic-gate# 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gatexref.ctags: xref.tfiles 1747c478bd9Sstevel@tonic-gate $(CTAGS) $(CTFLAGS) /dev/null `$(CAT) xref.tfiles` 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gatexref.ctags.clobber: xref.clean 1777c478bd9Sstevel@tonic-gate -$(RM) tags 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gatexref.etags: xref.tfiles 1807c478bd9Sstevel@tonic-gate $(CAT) xref.tfiles | $(ETAGS) $(ETFLAGS) - 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gatexref.etags.check: 1837c478bd9Sstevel@tonic-gate @$(CAT) /dev/null | $(ETAGS) - 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gatexref.etags.clobber: xref.clean 1867c478bd9Sstevel@tonic-gate -$(RM) TAGS 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gatexref.tfiles: xref.files 1897c478bd9Sstevel@tonic-gate > xref.tfiles 1907c478bd9Sstevel@tonic-gate -for suffix in h c C cc l y s; do \ 1917c478bd9Sstevel@tonic-gate $(GREP) "\.$${suffix}$$" xref.files >> xref.tfiles; \ 1927c478bd9Sstevel@tonic-gate done 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate# 1957c478bd9Sstevel@tonic-gate# Note that we put `cscope.files' in clobber rather than clean because 1967c478bd9Sstevel@tonic-gate# cscope will whine if it doesn't exist (unless it's passed -d). 1977c478bd9Sstevel@tonic-gate# 1987c478bd9Sstevel@tonic-gatexref.clean: 1997c478bd9Sstevel@tonic-gate -$(RM) xref.tfiles xref.files xref.tmp xref.flg ncscope.* 200