10Sstevel@tonic-gate#! /bin/ksh -p 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 67078Smjnelson# Common Development and Distribution License (the "License"). 77078Smjnelson# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 220Sstevel@tonic-gate# 23*9394SPeter.Memishian@Sun.COM# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate# Use is subject to license terms. 250Sstevel@tonic-gate# 260Sstevel@tonic-gate# xref: build and maintain source cross-reference databases. 270Sstevel@tonic-gate# 280Sstevel@tonic-gate 297078SmjnelsonONBLDDIR=$(dirname $(whence $0)) 307078Smjnelson 317078SmjnelsonPATH=/usr/bin:/usr/ccs/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR 327078Smjnelsonexport PATH 330Sstevel@tonic-gatePROG=`basename $0` 340Sstevel@tonic-gateXREFMK=`dirname $0`/xref.mk 350Sstevel@tonic-gateXRMAKEFILE=Makefile export XRMAKEFILE 360Sstevel@tonic-gate 370Sstevel@tonic-gate# 380Sstevel@tonic-gate# The CSCOPEOPTIONS variable can cause problems if it's set in the environment 390Sstevel@tonic-gate# when using cscope; remove it. 400Sstevel@tonic-gate# 410Sstevel@tonic-gateunset CSCOPEOPTIONS 420Sstevel@tonic-gate 430Sstevel@tonic-gate# 440Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout 450Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it. 460Sstevel@tonic-gate# 470Sstevel@tonic-gateunset CDPATH 480Sstevel@tonic-gate 490Sstevel@tonic-gate# 500Sstevel@tonic-gate# Print the provided failure message and exit with an error. 510Sstevel@tonic-gate# 520Sstevel@tonic-gatefail() 530Sstevel@tonic-gate{ 540Sstevel@tonic-gate echo $PROG: $@ > /dev/stderr 550Sstevel@tonic-gate exit 1 560Sstevel@tonic-gate} 570Sstevel@tonic-gate 580Sstevel@tonic-gate# 590Sstevel@tonic-gate# Print the provided warning message. 600Sstevel@tonic-gate# 610Sstevel@tonic-gatewarn() 620Sstevel@tonic-gate{ 630Sstevel@tonic-gate echo $PROG: warning: $@ > /dev/stderr 640Sstevel@tonic-gate} 650Sstevel@tonic-gate 660Sstevel@tonic-gate# 670Sstevel@tonic-gate# Print the provided informational message. 680Sstevel@tonic-gate# 690Sstevel@tonic-gateinfo() 700Sstevel@tonic-gate{ 710Sstevel@tonic-gate echo $PROG: $@ 720Sstevel@tonic-gate} 730Sstevel@tonic-gate 740Sstevel@tonic-gate# 750Sstevel@tonic-gate# Print the provided informational message, and the current value of $SECONDS 760Sstevel@tonic-gate# in a user-friendly format. 770Sstevel@tonic-gate# 780Sstevel@tonic-gatetimeinfo() 790Sstevel@tonic-gate{ 800Sstevel@tonic-gate typeset -Z2 sec 81*9394SPeter.Memishian@Sun.COM typeset -i min seconds 820Sstevel@tonic-gate 830Sstevel@tonic-gate ((seconds = SECONDS)) 840Sstevel@tonic-gate ((min = seconds / 60)) 850Sstevel@tonic-gate ((sec = seconds % 60)) 860Sstevel@tonic-gate 870Sstevel@tonic-gate info "$1 in ${min}m${sec}s" 880Sstevel@tonic-gate} 890Sstevel@tonic-gate 907078Smjnelsonwhich_scm | read SCM_MODE CODEMGR_WS || exit 1 917078Smjnelson 927078Smjnelsonif [[ $SCM_MODE == "unknown" ]];then 937078Smjnelson print -u2 "Unable to determine SCM type currently in use." 947078Smjnelson exit 1 950Sstevel@tonic-gatefi 960Sstevel@tonic-gate 977078Smjnelsonexport CODEMGR_WS 987078SmjnelsonSRC=$CODEMGR_WS/usr/src export SRC 997078SmjnelsonMACH=`uname -p` export MACH 1007078Smjnelson 1010Sstevel@tonic-gate[ -f $XREFMK ] || fail "cannot locate xref.mk" 1020Sstevel@tonic-gate 1030Sstevel@tonic-gateclobber= 1040Sstevel@tonic-gatenoflg= 1050Sstevel@tonic-gatexrefs= 1060Sstevel@tonic-gate 1070Sstevel@tonic-gatewhile getopts cfm:px: flag; do 1080Sstevel@tonic-gate case $flag in 1090Sstevel@tonic-gate c) 1100Sstevel@tonic-gate clobber=y 1110Sstevel@tonic-gate ;; 1120Sstevel@tonic-gate f) 1130Sstevel@tonic-gate noflg=y 1140Sstevel@tonic-gate ;; 1150Sstevel@tonic-gate m) 1160Sstevel@tonic-gate XRMAKEFILE=$OPTARG 1170Sstevel@tonic-gate ;; 1180Sstevel@tonic-gate p) 1190Sstevel@tonic-gate # 1200Sstevel@tonic-gate # The ENVCPPFLAGS* environment variables contain the include 1210Sstevel@tonic-gate # paths to our proto areas; clear 'em so that they don't end 1220Sstevel@tonic-gate # up in CPPFLAGS, and thus don't end up in XRINCS in xref.mk. 1230Sstevel@tonic-gate # 1240Sstevel@tonic-gate ENVCPPFLAGS1= 1250Sstevel@tonic-gate ENVCPPFLAGS2= 1260Sstevel@tonic-gate ENVCPPFLAGS3= 1270Sstevel@tonic-gate ENVCPPFLAGS4= 1280Sstevel@tonic-gate ;; 1290Sstevel@tonic-gate x) 1300Sstevel@tonic-gate xrefs=$OPTARG 1310Sstevel@tonic-gate ;; 1320Sstevel@tonic-gate \?) 1330Sstevel@tonic-gate echo "usage: $PROG [-cfp] [-m <makefile>]"\ 1340Sstevel@tonic-gate "[-x cscope|ctags|etags[,...]] [<subtree> ...]"\ 1350Sstevel@tonic-gate > /dev/stderr 1360Sstevel@tonic-gate exit 1 1370Sstevel@tonic-gate ;; 1380Sstevel@tonic-gate esac 1390Sstevel@tonic-gatedone 1400Sstevel@tonic-gate 1410Sstevel@tonic-gateshift $((OPTIND - 1)) 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate# 1440Sstevel@tonic-gate# Get the list of directories before we reset $@. 1450Sstevel@tonic-gate# 1460Sstevel@tonic-gatedirs=$@ 1470Sstevel@tonic-gate[ -z "$dirs" ] && dirs=. 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate# 1500Sstevel@tonic-gate# Get the canonical path to the workspace. This allows xref to work 1510Sstevel@tonic-gate# even in the presence of lofs(7FS). 1520Sstevel@tonic-gate# 1530Sstevel@tonic-gatecd $CODEMGR_WS 1540Sstevel@tonic-gateCODEMGR_WS=`/bin/pwd` 1550Sstevel@tonic-gatecd - > /dev/null 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate# 1580Sstevel@tonic-gate# Process the xref format list. For convenience, support common synonyms 1590Sstevel@tonic-gate# for the xref formats. 1600Sstevel@tonic-gate# 1610Sstevel@tonic-gateif [ -z "$xrefs" ]; then 1620Sstevel@tonic-gate # 1630Sstevel@tonic-gate # Disable etags if we can't find it. 1640Sstevel@tonic-gate # 1650Sstevel@tonic-gate xrefs="cscope ctags" 1660Sstevel@tonic-gate make -e -f $XREFMK xref.etags.check 2>/dev/null 1>&2 && \ 1670Sstevel@tonic-gate xrefs="$xrefs etags" 1680Sstevel@tonic-gateelse 1690Sstevel@tonic-gate oldifs=$IFS 1700Sstevel@tonic-gate IFS=, 1710Sstevel@tonic-gate set -- $xrefs 1720Sstevel@tonic-gate IFS=$oldifs 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate xrefs= 1750Sstevel@tonic-gate for xref; do 1760Sstevel@tonic-gate case $xref in 1770Sstevel@tonic-gate cscope|cscope.out) 1780Sstevel@tonic-gate xrefs="$xrefs cscope" 1790Sstevel@tonic-gate ;; 1800Sstevel@tonic-gate ctags|tags) 1810Sstevel@tonic-gate xrefs="$xrefs ctags" 1820Sstevel@tonic-gate ;; 1830Sstevel@tonic-gate etags|TAGS) 1840Sstevel@tonic-gate xrefs="$xrefs etags" 1850Sstevel@tonic-gate ;; 1860Sstevel@tonic-gate *) 1870Sstevel@tonic-gate warn "ignoring unknown cross-reference \"$xref\"" 1880Sstevel@tonic-gate ;; 1890Sstevel@tonic-gate esac 1900Sstevel@tonic-gate done 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate [ -z "$xrefs" ] && fail "no known cross-reference formats specified" 1930Sstevel@tonic-gatefi 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate# 1960Sstevel@tonic-gate# Process the requested list of directories. 1970Sstevel@tonic-gate# 1980Sstevel@tonic-gatefor dir in $dirs; do 1990Sstevel@tonic-gate if [ ! -d $dir ]; then 2000Sstevel@tonic-gate warn "directory \"$dir\" does not exist; skipping" 2010Sstevel@tonic-gate continue 2020Sstevel@tonic-gate fi 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate # 2050Sstevel@tonic-gate # NOTE: we cannot use $PWD because it will mislead in the presence 2060Sstevel@tonic-gate # of lofs(7FS). 2070Sstevel@tonic-gate # 2080Sstevel@tonic-gate cd $dir || fail "cannot change to directory $dir" 2090Sstevel@tonic-gate pwd=`/bin/pwd` 2100Sstevel@tonic-gate reldir=${pwd##${CODEMGR_WS}/} 2110Sstevel@tonic-gate if [ "$reldir" = "$pwd" ]; then 2120Sstevel@tonic-gate warn "directory \"$pwd\" is not beneath \$CODEMGR_WS; skipping" 2130Sstevel@tonic-gate cd - > /dev/null 2140Sstevel@tonic-gate continue 2150Sstevel@tonic-gate fi 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate # 2180Sstevel@tonic-gate # If we're building cross-references, then run `xref.clean' first 2190Sstevel@tonic-gate # to purge any crud that may be lying around from previous aborted runs. 2200Sstevel@tonic-gate # 2210Sstevel@tonic-gate if [ -z "$clobber" ]; then 2220Sstevel@tonic-gate make -e -f $XREFMK xref.clean > /dev/null 2230Sstevel@tonic-gate fi 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate # 2260Sstevel@tonic-gate # Find flg-related source files, if requested. 2270Sstevel@tonic-gate # 2280Sstevel@tonic-gate if [ -z "$noflg" -a -z "$clobber" ]; then 2290Sstevel@tonic-gate SECONDS=0 2300Sstevel@tonic-gate info "$reldir: finding flg-related source files" 2310Sstevel@tonic-gate make -e -f $XREFMK xref.flg > /dev/null 2320Sstevel@tonic-gate if [ $? -ne 0 ]; then 2330Sstevel@tonic-gate warn "$reldir: unable to find flg-related source files" 2340Sstevel@tonic-gate else 2350Sstevel@tonic-gate nfiles=`wc -l < xref.flg` 2360Sstevel@tonic-gate if [ "$nfiles" -eq 1 ]; then 2370Sstevel@tonic-gate msg="found 1 flg-related source file" 2380Sstevel@tonic-gate else 2390Sstevel@tonic-gate msg="found $nfiles flg-related source files" 2400Sstevel@tonic-gate fi 2410Sstevel@tonic-gate timeinfo "$reldir: $msg" 2420Sstevel@tonic-gate fi 2430Sstevel@tonic-gate fi 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate # 2460Sstevel@tonic-gate # Build or clobber all of the requested cross-references. 2470Sstevel@tonic-gate # 2480Sstevel@tonic-gate for xref in $xrefs; do 2490Sstevel@tonic-gate if [ -n "$clobber" ]; then 2500Sstevel@tonic-gate info "$reldir: clobbering $xref cross-reference" 2510Sstevel@tonic-gate make -e -f $XREFMK xref.${xref}.clobber > /dev/null || 2520Sstevel@tonic-gate warn "$reldir: cannot clobber $xref cross-reference" 2530Sstevel@tonic-gate continue 2540Sstevel@tonic-gate fi 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate SECONDS=0 2570Sstevel@tonic-gate info "$reldir: building $xref cross-reference" 2580Sstevel@tonic-gate make -e -f $XREFMK xref.${xref} > /dev/null || 2590Sstevel@tonic-gate fail "$reldir: cannot build $xref cross-reference" 2600Sstevel@tonic-gate timeinfo "$reldir: built $xref cross-reference" 2610Sstevel@tonic-gate done 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate make -e -f $XREFMK xref.clean > /dev/null || 2640Sstevel@tonic-gate warn "$reldir: cannot clean up temporary files" 2650Sstevel@tonic-gate cd - > /dev/null 2660Sstevel@tonic-gatedone 2670Sstevel@tonic-gateexit 0 268