#! /bin/ksh -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # xref: build and maintain source cross-reference databases. # setvar ONBLDDIR = $(dirname $(whence $0)) setvar PROG = $(basename $0) setvar XREFMK = "$(dirname $0)/xref.mk"' XRMAKEFILE=Makefile' export XRMAKEFILE setvar MAKE = ""dmake -m serial"" # # The CSCOPEOPTIONS variable can cause problems if it's set in the environment # when using cscope; remove it. # unset CSCOPEOPTIONS # # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout # under certain circumstances, which can really screw things up; unset it. # unset CDPATH # # Print the provided failure message and exit with an error. # proc fail { echo $PROG: $ifsjoin(ARGV) > /dev/stderr exit 1 } # # Print the provided warning message. # proc warn { echo $PROG: warning: $ifsjoin(ARGV) > /dev/stderr } # # Print the provided informational message. # proc info { echo $PROG: $ifsjoin(ARGV) } # # Print the provided informational message, and the current value of $SECONDS # in a user-friendly format. # proc timeinfo { typeset -Z2 sec typeset -i min seconds ((seconds = SECONDS)) ((min = seconds / 60)) ((sec = seconds % 60)) info "$1 in ${min}m${sec}s" } which_scm | read SCM_MODE CODEMGR_WS || exit 1 if [[ $SCM_MODE == "unknown" ]]{ print -u2 "Unable to determine SCM type currently in use." exit 1 } export CODEMGR_WS" SRC=$CODEMGR_WS/usr/src" export SRC MACH=$(uname -p) export MACH test -f $XREFMK || fail "cannot locate xref.mk" setvar clobber = '' setvar noflg = '' setvar xrefs = '' while getopts cfm:px: flag { match $flag { with c setvar clobber = 'y' with f setvar noflg = 'y' with m setvar XRMAKEFILE = "$OPTARG" with p # # The ENVCPPFLAGS* environment variables contain the include # paths to our proto areas; clear 'em so that they don't end # up in CPPFLAGS, and thus don't end up in XRINCS in xref.mk. # setvar ENVCPPFLAGS1 = '' setvar ENVCPPFLAGS2 = '' setvar ENVCPPFLAGS3 = '' setvar ENVCPPFLAGS4 = '' with x setvar xrefs = "$OPTARG" with \? echo "usage: $PROG [-cfp] [-m ]"\ "[-x cscope|ctags|etags[,...]] [ ...]"\ > /dev/stderr exit 1 } } shift $((OPTIND - 1)) # # Get the list of directories before we reset $@. # setvar dirs = "$ifsjoin(ARGV)" test -z $dirs && setvar dirs = '.' # # Get the canonical path to the workspace. This allows xref to work # even in the presence of lofs(7FS). # cd $CODEMGR_WS setvar CODEMGR_WS = $(/bin/pwd) cd - > /dev/null # # Process the xref format list. For convenience, support common synonyms # for the xref formats. # if test -z $xrefs { # # Disable etags if we can't find it. # setvar xrefs = ""cscope ctags"" $MAKE -e -f $XREFMK xref.etags.check 2>/dev/null 1>&2 && \ setvar xrefs = ""$xrefs etags"" } else { setvar oldifs = "$IFS" setvar IFS = ',' set -- $xrefs setvar IFS = "$oldifs" setvar xrefs = ''for xref in @ARGV { match $xref { with cscope|cscope.out setvar xrefs = ""$xrefs cscope"" with ctags|tags setvar xrefs = ""$xrefs ctags"" with etags|TAGS setvar xrefs = ""$xrefs etags"" with * warn "ignoring unknown cross-reference \"$xref\"" } } test -z $xrefs && fail "no known cross-reference formats specified" } # # Process the requested list of directories. # for dir in [$dirs] { if test ! -d $dir { warn "directory \"$dir\" does not exist; skipping" continue } # # NOTE: we cannot use $PWD because it will mislead in the presence # of lofs(7FS). # cd $dir || fail "cannot change to directory $dir" setvar pwd = $(/bin/pwd) setvar reldir = ${pwd##${CODEMGR_WS}/} if test $reldir = $pwd { warn "directory \"$pwd\" is not beneath \$CODEMGR_WS; skipping" cd - > /dev/null continue } # # If we're building cross-references, then run `xref.clean' first # to purge any crud that may be lying around from previous aborted runs. # if test -z $clobber { $MAKE -e -f $XREFMK xref.clean > /dev/null } # # Find flg-related source files, if requested. # if test -z $noflg -a -z $clobber { setvar SECONDS = '0' info "$reldir: finding flg-related source files" $MAKE -e -f $XREFMK xref.flg > /dev/null if test $Status -ne 0 { warn "$reldir: unable to find flg-related source files" } else { setvar nfiles = $(wc -l ) if test $nfiles -eq 1 { setvar msg = ""found 1 flg-related source file"" } else { setvar msg = ""found $nfiles flg-related source files"" } timeinfo "$reldir: $msg" } } # # Build or clobber all of the requested cross-references. # for xref in [$xrefs] { if test -n $clobber { info "$reldir: clobbering $xref cross-reference" $MAKE -e -f $XREFMK xref.${xref}.clobber > /dev/null || warn "$reldir: cannot clobber $xref cross-reference" continue } setvar SECONDS = '0' info "$reldir: building $xref cross-reference" $MAKE -e -f $XREFMK xref.${xref} > /dev/null || fail "$reldir: cannot build $xref cross-reference" timeinfo "$reldir: built $xref cross-reference" } $MAKE -e -f $XREFMK xref.clean > /dev/null || warn "$reldir: cannot clean up temporary files" cd - > /dev/null } exit 0