8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / tools / scripts / xref.sh
blobd69a364fdac7f602754dac5690623b24b51a690a
1 #! /bin/ksh -p
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 # xref: build and maintain source cross-reference databases.
29 ONBLDDIR=$(dirname $(whence $0))
31 PROG=`basename $0`
32 XREFMK=`dirname $0`/xref.mk
33 XRMAKEFILE=Makefile export XRMAKEFILE
34 MAKE="dmake -m serial"
37 # The CSCOPEOPTIONS variable can cause problems if it's set in the environment
38 # when using cscope; remove it.
40 unset CSCOPEOPTIONS
43 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
44 # under certain circumstances, which can really screw things up; unset it.
46 unset CDPATH
49 # Print the provided failure message and exit with an error.
51 fail()
53 echo $PROG: $@ > /dev/stderr
54 exit 1
58 # Print the provided warning message.
60 warn()
62 echo $PROG: warning: $@ > /dev/stderr
66 # Print the provided informational message.
68 info()
70 echo $PROG: $@
74 # Print the provided informational message, and the current value of $SECONDS
75 # in a user-friendly format.
77 timeinfo()
79 typeset -Z2 sec
80 typeset -i min seconds
82 ((seconds = SECONDS))
83 ((min = seconds / 60))
84 ((sec = seconds % 60))
86 info "$1 in ${min}m${sec}s"
89 which_scm | read SCM_MODE CODEMGR_WS || exit 1
91 if [[ $SCM_MODE == "unknown" ]];then
92 print -u2 "Unable to determine SCM type currently in use."
93 exit 1
96 export CODEMGR_WS
97 SRC=$CODEMGR_WS/usr/src export SRC
98 MACH=`uname -p` export MACH
100 [ -f $XREFMK ] || fail "cannot locate xref.mk"
102 clobber=
103 noflg=
104 xrefs=
106 while getopts cfm:px: flag; do
107 case $flag in
109 clobber=y
112 noflg=y
115 XRMAKEFILE=$OPTARG
119 # The ENVCPPFLAGS* environment variables contain the include
120 # paths to our proto areas; clear 'em so that they don't end
121 # up in CPPFLAGS, and thus don't end up in XRINCS in xref.mk.
123 ENVCPPFLAGS1=
124 ENVCPPFLAGS2=
125 ENVCPPFLAGS3=
126 ENVCPPFLAGS4=
129 xrefs=$OPTARG
132 echo "usage: $PROG [-cfp] [-m <makefile>]"\
133 "[-x cscope|ctags|etags[,...]] [<subtree> ...]"\
134 > /dev/stderr
135 exit 1
137 esac
138 done
140 shift $((OPTIND - 1))
143 # Get the list of directories before we reset $@.
145 dirs=$@
146 [ -z "$dirs" ] && dirs=.
149 # Get the canonical path to the workspace. This allows xref to work
150 # even in the presence of lofs(7FS).
152 cd $CODEMGR_WS
153 CODEMGR_WS=`/bin/pwd`
154 cd - > /dev/null
157 # Process the xref format list. For convenience, support common synonyms
158 # for the xref formats.
160 if [ -z "$xrefs" ]; then
162 # Disable etags if we can't find it.
164 xrefs="cscope ctags"
165 $MAKE -e -f $XREFMK xref.etags.check 2>/dev/null 1>&2 && \
166 xrefs="$xrefs etags"
167 else
168 oldifs=$IFS
169 IFS=,
170 set -- $xrefs
171 IFS=$oldifs
173 xrefs=
174 for xref; do
175 case $xref in
176 cscope|cscope.out)
177 xrefs="$xrefs cscope"
179 ctags|tags)
180 xrefs="$xrefs ctags"
182 etags|TAGS)
183 xrefs="$xrefs etags"
186 warn "ignoring unknown cross-reference \"$xref\""
188 esac
189 done
191 [ -z "$xrefs" ] && fail "no known cross-reference formats specified"
195 # Process the requested list of directories.
197 for dir in $dirs; do
198 if [ ! -d $dir ]; then
199 warn "directory \"$dir\" does not exist; skipping"
200 continue
204 # NOTE: we cannot use $PWD because it will mislead in the presence
205 # of lofs(7FS).
207 cd $dir || fail "cannot change to directory $dir"
208 pwd=`/bin/pwd`
209 reldir=${pwd##${CODEMGR_WS}/}
210 if [ "$reldir" = "$pwd" ]; then
211 warn "directory \"$pwd\" is not beneath \$CODEMGR_WS; skipping"
212 cd - > /dev/null
213 continue
217 # If we're building cross-references, then run `xref.clean' first
218 # to purge any crud that may be lying around from previous aborted runs.
220 if [ -z "$clobber" ]; then
221 $MAKE -e -f $XREFMK xref.clean > /dev/null
225 # Find flg-related source files, if requested.
227 if [ -z "$noflg" -a -z "$clobber" ]; then
228 SECONDS=0
229 info "$reldir: finding flg-related source files"
230 $MAKE -e -f $XREFMK xref.flg > /dev/null
231 if [ $? -ne 0 ]; then
232 warn "$reldir: unable to find flg-related source files"
233 else
234 nfiles=`wc -l < xref.flg`
235 if [ "$nfiles" -eq 1 ]; then
236 msg="found 1 flg-related source file"
237 else
238 msg="found $nfiles flg-related source files"
240 timeinfo "$reldir: $msg"
245 # Build or clobber all of the requested cross-references.
247 for xref in $xrefs; do
248 if [ -n "$clobber" ]; then
249 info "$reldir: clobbering $xref cross-reference"
250 $MAKE -e -f $XREFMK xref.${xref}.clobber > /dev/null ||
251 warn "$reldir: cannot clobber $xref cross-reference"
252 continue
255 SECONDS=0
256 info "$reldir: building $xref cross-reference"
257 $MAKE -e -f $XREFMK xref.${xref} > /dev/null ||
258 fail "$reldir: cannot build $xref cross-reference"
259 timeinfo "$reldir: built $xref cross-reference"
260 done
262 $MAKE -e -f $XREFMK xref.clean > /dev/null ||
263 warn "$reldir: cannot clean up temporary files"
264 cd - > /dev/null
265 done
266 exit 0