6324 Add an `ndp' tool for manipulating the neighbors table
[illumos-gate.git] / usr / src / tools / scripts / xref.mk
bloba8b07d58596588b41d48349c3a841f622401c048
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
21 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
22 # Use is subject to license terms.
24 # This Makefile is used exclusively by `xref' to generate and maintain
25 # cross-reference databases (right now: cscope, ctags, and etags).
27 # By default, the cross-reference is built for all files underneath the
28 # currrent working directory that match the criteria specified in the
29 # xref.files rule below, and any files that would also be hauled over as
30 # part of a `bringover' of the working directory (though this can be
31 # turned off via the -f flag to `xref').
33 # However, this behavior can be customized in each directory of the build
34 # tree through the following Makefile macros, if necessary:
36 # XRDIRS: The list of directories to include; defaults to `.'.
37 # The more interesting directories should be listed earlier.
38 # XRPRUNE: The list of directories to prune out.
39 # XRADD: The list of additional filename globs to include.
40 # XRDEL: The list of additional filename globs to exclude.
41 # XRINCDIRS: The list of additional include paths, in "foo bar" format.
42 # XRINCS: The list of additional include paths, in "-Ifoo -Ibar" format.
44 # Note that XRINCDIRS and XRINCS are for specifying header paths that are
45 # not already included in CPPFLAGS and HDRDIR.
47 # These macros are assumed to be set in a file named `Makefile', but this
48 # too can be overridden via the -m option to `xref'.
50 # This Makefile should *never* be included by other Makefiles.
53 XRMAKEFILE=Makefile
54 include $(SRC)/Makefile.master
57 # Default values for the cross-reference tools; these can be overridden
58 # either in the environment or in XRMAKEFILE. To use regular cscope, set
59 # CSCOPE to cscope and CSFLAGS to -b.
61 CSCOPE = $(BUILD_TOOLS)/onbld/bin/$(MACH)/cscope-fast
62 CSFLAGS = -bq
63 CTAGS = /usr/bin/ctags
64 CTFLAGS = -wt
65 ETAGS = $(SPRO_VROOT)/bin/etags
66 ETFLAGS = -t
67 FLGFLP = $(BUILD_TOOLS)/onbld/bin/flg.flp
69 XRDIRS = .
70 XRINCS = $(XRINCDIRS:%=-I%) $(HDRDIR:%=-I%) $(CPPFLAGS)
72 include $(XRMAKEFILE)
74 XRADDLIST = $(XRADD) *.[Ccdshlxy] Makefile* *.il* *.cc llib-* *.xml \
75 *.dtd.* *.ndl
76 XRDELLIST = $(XRDEL) *.ln
77 XRPRUNELIST = $(XRPRUNE) .hg
78 XRFINDADD = $(XRADDLIST:%=-o -name '%')
79 XRFINDDEL = $(XRDELLIST:%=-a ! -name '%')
80 XRFINDPRUNE = $(XRPRUNELIST:%=-o -name '%')
81 XRSEDPRUNE = $(XRPRUNELIST:%=/\/%\//d; /^%\//d;)
83 .KEEP_STATE:
84 .PRECIOUS: cscope.out cscope.in.out cscope.po.out tags TAGS
87 # Build the list of files to be included in the cross-reference database.
89 # Please note that:
91 # * Any additional FLG-related source files are in xref.flg.
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).
99 # * We strip out any duplicate file names, being careful not to
100 # disturb the order of the file list.
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.
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.
109 xref.files:
110 $(TOUCH) xref.flg
111 $(FIND) $(XRDIRS) `$(CAT) xref.flg` \
112 -type d \( -name SCCS $(XRFINDPRUNE) \) -prune -o \
113 -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
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.
127 xref.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
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.
141 xref.cscope: xref.files
142 -$(ECHO) $(XRINCS) | $(XARGS) -n1 | $(GREP) '^-I' | \
143 $(CAT) - xref.files > cscope.files
144 $(CSCOPE) $(CSFLAGS)
146 xref.cscope.clobber: xref.clean
147 -$(RM) cscope.out cscope.in.out cscope.po.out cscope.files
150 # Create tags databases, similar to above.
152 # Since assembler files contain C fragments for lint, the lint fragments will
153 # allow tags to "work" on assembler. Please note that:
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.
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.
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).
168 xref.ctags: xref.tfiles
169 $(CTAGS) $(CTFLAGS) /dev/null `$(CAT) xref.tfiles`
171 xref.ctags.clobber: xref.clean
172 -$(RM) tags
174 xref.etags: xref.tfiles
175 $(CAT) xref.tfiles | $(ETAGS) $(ETFLAGS) -
177 xref.etags.check:
178 @$(CAT) /dev/null | $(ETAGS) -
180 xref.etags.clobber: xref.clean
181 -$(RM) TAGS
183 xref.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
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).
193 xref.clean:
194 -$(RM) xref.tfiles xref.files xref.tmp xref.flg ncscope.*