17c478bd9Sstevel@tonic-gate#! /bin/ksh -p 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*cdf0c1d5Smjnelson# Common Development and Distribution License (the "License"). 7*cdf0c1d5Smjnelson# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate# ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate# 287c478bd9Sstevel@tonic-gate# xref: build and maintain source cross-reference databases. 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gate 31*cdf0c1d5SmjnelsonONBLDDIR=$(dirname $(whence $0)) 32*cdf0c1d5Smjnelson 33*cdf0c1d5SmjnelsonPATH=/usr/bin:/usr/ccs/bin:${BUILD_TOOLS:-/opt}/teamware/bin:$ONBLDDIR 34*cdf0c1d5Smjnelsonexport PATH 357c478bd9Sstevel@tonic-gatePROG=`basename $0` 367c478bd9Sstevel@tonic-gateXREFMK=`dirname $0`/xref.mk 377c478bd9Sstevel@tonic-gateXRMAKEFILE=Makefile export XRMAKEFILE 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate# 407c478bd9Sstevel@tonic-gate# The CSCOPEOPTIONS variable can cause problems if it's set in the environment 417c478bd9Sstevel@tonic-gate# when using cscope; remove it. 427c478bd9Sstevel@tonic-gate# 437c478bd9Sstevel@tonic-gateunset CSCOPEOPTIONS 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate# 467c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout 477c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it. 487c478bd9Sstevel@tonic-gate# 497c478bd9Sstevel@tonic-gateunset CDPATH 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate# 527c478bd9Sstevel@tonic-gate# Print the provided failure message and exit with an error. 537c478bd9Sstevel@tonic-gate# 547c478bd9Sstevel@tonic-gatefail() 557c478bd9Sstevel@tonic-gate{ 567c478bd9Sstevel@tonic-gate echo $PROG: $@ > /dev/stderr 577c478bd9Sstevel@tonic-gate exit 1 587c478bd9Sstevel@tonic-gate} 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate# 617c478bd9Sstevel@tonic-gate# Print the provided warning message. 627c478bd9Sstevel@tonic-gate# 637c478bd9Sstevel@tonic-gatewarn() 647c478bd9Sstevel@tonic-gate{ 657c478bd9Sstevel@tonic-gate echo $PROG: warning: $@ > /dev/stderr 667c478bd9Sstevel@tonic-gate} 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate# 697c478bd9Sstevel@tonic-gate# Print the provided informational message. 707c478bd9Sstevel@tonic-gate# 717c478bd9Sstevel@tonic-gateinfo() 727c478bd9Sstevel@tonic-gate{ 737c478bd9Sstevel@tonic-gate echo $PROG: $@ 747c478bd9Sstevel@tonic-gate} 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate# 777c478bd9Sstevel@tonic-gate# Print the provided informational message, and the current value of $SECONDS 787c478bd9Sstevel@tonic-gate# in a user-friendly format. 797c478bd9Sstevel@tonic-gate# 807c478bd9Sstevel@tonic-gatetimeinfo() 817c478bd9Sstevel@tonic-gate{ 827c478bd9Sstevel@tonic-gate typeset -Z2 sec 837c478bd9Sstevel@tonic-gate typeset min seconds 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate ((seconds = SECONDS)) 867c478bd9Sstevel@tonic-gate ((min = seconds / 60)) 877c478bd9Sstevel@tonic-gate ((sec = seconds % 60)) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate info "$1 in ${min}m${sec}s" 907c478bd9Sstevel@tonic-gate} 917c478bd9Sstevel@tonic-gate 92*cdf0c1d5Smjnelsonwhich_scm | read SCM_MODE CODEMGR_WS || exit 1 93*cdf0c1d5Smjnelson 94*cdf0c1d5Smjnelsonif [[ $SCM_MODE == "unknown" ]];then 95*cdf0c1d5Smjnelson print -u2 "Unable to determine SCM type currently in use." 96*cdf0c1d5Smjnelson exit 1 977c478bd9Sstevel@tonic-gatefi 987c478bd9Sstevel@tonic-gate 99*cdf0c1d5Smjnelsonexport CODEMGR_WS 100*cdf0c1d5SmjnelsonSRC=$CODEMGR_WS/usr/src export SRC 101*cdf0c1d5SmjnelsonMACH=`uname -p` export MACH 102*cdf0c1d5Smjnelson 1037c478bd9Sstevel@tonic-gate[ -f $XREFMK ] || fail "cannot locate xref.mk" 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gateclobber= 1067c478bd9Sstevel@tonic-gatenoflg= 1077c478bd9Sstevel@tonic-gatexrefs= 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gatewhile getopts cfm:px: flag; do 1107c478bd9Sstevel@tonic-gate case $flag in 1117c478bd9Sstevel@tonic-gate c) 1127c478bd9Sstevel@tonic-gate clobber=y 1137c478bd9Sstevel@tonic-gate ;; 1147c478bd9Sstevel@tonic-gate f) 1157c478bd9Sstevel@tonic-gate noflg=y 1167c478bd9Sstevel@tonic-gate ;; 1177c478bd9Sstevel@tonic-gate m) 1187c478bd9Sstevel@tonic-gate XRMAKEFILE=$OPTARG 1197c478bd9Sstevel@tonic-gate ;; 1207c478bd9Sstevel@tonic-gate p) 1217c478bd9Sstevel@tonic-gate # 1227c478bd9Sstevel@tonic-gate # The ENVCPPFLAGS* environment variables contain the include 1237c478bd9Sstevel@tonic-gate # paths to our proto areas; clear 'em so that they don't end 1247c478bd9Sstevel@tonic-gate # up in CPPFLAGS, and thus don't end up in XRINCS in xref.mk. 1257c478bd9Sstevel@tonic-gate # 1267c478bd9Sstevel@tonic-gate ENVCPPFLAGS1= 1277c478bd9Sstevel@tonic-gate ENVCPPFLAGS2= 1287c478bd9Sstevel@tonic-gate ENVCPPFLAGS3= 1297c478bd9Sstevel@tonic-gate ENVCPPFLAGS4= 1307c478bd9Sstevel@tonic-gate ;; 1317c478bd9Sstevel@tonic-gate x) 1327c478bd9Sstevel@tonic-gate xrefs=$OPTARG 1337c478bd9Sstevel@tonic-gate ;; 1347c478bd9Sstevel@tonic-gate \?) 1357c478bd9Sstevel@tonic-gate echo "usage: $PROG [-cfp] [-m <makefile>]"\ 1367c478bd9Sstevel@tonic-gate "[-x cscope|ctags|etags[,...]] [<subtree> ...]"\ 1377c478bd9Sstevel@tonic-gate > /dev/stderr 1387c478bd9Sstevel@tonic-gate exit 1 1397c478bd9Sstevel@tonic-gate ;; 1407c478bd9Sstevel@tonic-gate esac 1417c478bd9Sstevel@tonic-gatedone 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gateshift $((OPTIND - 1)) 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate# 1467c478bd9Sstevel@tonic-gate# Get the list of directories before we reset $@. 1477c478bd9Sstevel@tonic-gate# 1487c478bd9Sstevel@tonic-gatedirs=$@ 1497c478bd9Sstevel@tonic-gate[ -z "$dirs" ] && dirs=. 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate# 1527c478bd9Sstevel@tonic-gate# Get the canonical path to the workspace. This allows xref to work 1537c478bd9Sstevel@tonic-gate# even in the presence of lofs(7FS). 1547c478bd9Sstevel@tonic-gate# 1557c478bd9Sstevel@tonic-gatecd $CODEMGR_WS 1567c478bd9Sstevel@tonic-gateCODEMGR_WS=`/bin/pwd` 1577c478bd9Sstevel@tonic-gatecd - > /dev/null 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate# 1607c478bd9Sstevel@tonic-gate# Process the xref format list. For convenience, support common synonyms 1617c478bd9Sstevel@tonic-gate# for the xref formats. 1627c478bd9Sstevel@tonic-gate# 1637c478bd9Sstevel@tonic-gateif [ -z "$xrefs" ]; then 1647c478bd9Sstevel@tonic-gate # 1657c478bd9Sstevel@tonic-gate # Disable etags if we can't find it. 1667c478bd9Sstevel@tonic-gate # 1677c478bd9Sstevel@tonic-gate xrefs="cscope ctags" 1687c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.etags.check 2>/dev/null 1>&2 && \ 1697c478bd9Sstevel@tonic-gate xrefs="$xrefs etags" 1707c478bd9Sstevel@tonic-gateelse 1717c478bd9Sstevel@tonic-gate oldifs=$IFS 1727c478bd9Sstevel@tonic-gate IFS=, 1737c478bd9Sstevel@tonic-gate set -- $xrefs 1747c478bd9Sstevel@tonic-gate IFS=$oldifs 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate xrefs= 1777c478bd9Sstevel@tonic-gate for xref; do 1787c478bd9Sstevel@tonic-gate case $xref in 1797c478bd9Sstevel@tonic-gate cscope|cscope.out) 1807c478bd9Sstevel@tonic-gate xrefs="$xrefs cscope" 1817c478bd9Sstevel@tonic-gate ;; 1827c478bd9Sstevel@tonic-gate ctags|tags) 1837c478bd9Sstevel@tonic-gate xrefs="$xrefs ctags" 1847c478bd9Sstevel@tonic-gate ;; 1857c478bd9Sstevel@tonic-gate etags|TAGS) 1867c478bd9Sstevel@tonic-gate xrefs="$xrefs etags" 1877c478bd9Sstevel@tonic-gate ;; 1887c478bd9Sstevel@tonic-gate *) 1897c478bd9Sstevel@tonic-gate warn "ignoring unknown cross-reference \"$xref\"" 1907c478bd9Sstevel@tonic-gate ;; 1917c478bd9Sstevel@tonic-gate esac 1927c478bd9Sstevel@tonic-gate done 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate [ -z "$xrefs" ] && fail "no known cross-reference formats specified" 1957c478bd9Sstevel@tonic-gatefi 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate# 1987c478bd9Sstevel@tonic-gate# Process the requested list of directories. 1997c478bd9Sstevel@tonic-gate# 2007c478bd9Sstevel@tonic-gatefor dir in $dirs; do 2017c478bd9Sstevel@tonic-gate if [ ! -d $dir ]; then 2027c478bd9Sstevel@tonic-gate warn "directory \"$dir\" does not exist; skipping" 2037c478bd9Sstevel@tonic-gate continue 2047c478bd9Sstevel@tonic-gate fi 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate # 2077c478bd9Sstevel@tonic-gate # NOTE: we cannot use $PWD because it will mislead in the presence 2087c478bd9Sstevel@tonic-gate # of lofs(7FS). 2097c478bd9Sstevel@tonic-gate # 2107c478bd9Sstevel@tonic-gate cd $dir || fail "cannot change to directory $dir" 2117c478bd9Sstevel@tonic-gate pwd=`/bin/pwd` 2127c478bd9Sstevel@tonic-gate reldir=${pwd##${CODEMGR_WS}/} 2137c478bd9Sstevel@tonic-gate if [ "$reldir" = "$pwd" ]; then 2147c478bd9Sstevel@tonic-gate warn "directory \"$pwd\" is not beneath \$CODEMGR_WS; skipping" 2157c478bd9Sstevel@tonic-gate cd - > /dev/null 2167c478bd9Sstevel@tonic-gate continue 2177c478bd9Sstevel@tonic-gate fi 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate # 2207c478bd9Sstevel@tonic-gate # If we're building cross-references, then run `xref.clean' first 2217c478bd9Sstevel@tonic-gate # to purge any crud that may be lying around from previous aborted runs. 2227c478bd9Sstevel@tonic-gate # 2237c478bd9Sstevel@tonic-gate if [ -z "$clobber" ]; then 2247c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.clean > /dev/null 2257c478bd9Sstevel@tonic-gate fi 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate # 2287c478bd9Sstevel@tonic-gate # Find flg-related source files, if requested. 2297c478bd9Sstevel@tonic-gate # 2307c478bd9Sstevel@tonic-gate if [ -z "$noflg" -a -z "$clobber" ]; then 2317c478bd9Sstevel@tonic-gate SECONDS=0 2327c478bd9Sstevel@tonic-gate info "$reldir: finding flg-related source files" 2337c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.flg > /dev/null 2347c478bd9Sstevel@tonic-gate if [ $? -ne 0 ]; then 2357c478bd9Sstevel@tonic-gate warn "$reldir: unable to find flg-related source files" 2367c478bd9Sstevel@tonic-gate else 2377c478bd9Sstevel@tonic-gate nfiles=`wc -l < xref.flg` 2387c478bd9Sstevel@tonic-gate if [ "$nfiles" -eq 1 ]; then 2397c478bd9Sstevel@tonic-gate msg="found 1 flg-related source file" 2407c478bd9Sstevel@tonic-gate else 2417c478bd9Sstevel@tonic-gate msg="found $nfiles flg-related source files" 2427c478bd9Sstevel@tonic-gate fi 2437c478bd9Sstevel@tonic-gate timeinfo "$reldir: $msg" 2447c478bd9Sstevel@tonic-gate fi 2457c478bd9Sstevel@tonic-gate fi 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate # 2487c478bd9Sstevel@tonic-gate # Build or clobber all of the requested cross-references. 2497c478bd9Sstevel@tonic-gate # 2507c478bd9Sstevel@tonic-gate for xref in $xrefs; do 2517c478bd9Sstevel@tonic-gate if [ -n "$clobber" ]; then 2527c478bd9Sstevel@tonic-gate info "$reldir: clobbering $xref cross-reference" 2537c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.${xref}.clobber > /dev/null || 2547c478bd9Sstevel@tonic-gate warn "$reldir: cannot clobber $xref cross-reference" 2557c478bd9Sstevel@tonic-gate continue 2567c478bd9Sstevel@tonic-gate fi 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate SECONDS=0 2597c478bd9Sstevel@tonic-gate info "$reldir: building $xref cross-reference" 2607c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.${xref} > /dev/null || 2617c478bd9Sstevel@tonic-gate fail "$reldir: cannot build $xref cross-reference" 2627c478bd9Sstevel@tonic-gate timeinfo "$reldir: built $xref cross-reference" 2637c478bd9Sstevel@tonic-gate done 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate make -e -f $XREFMK xref.clean > /dev/null || 2667c478bd9Sstevel@tonic-gate warn "$reldir: cannot clean up temporary files" 2677c478bd9Sstevel@tonic-gate cd - > /dev/null 2687c478bd9Sstevel@tonic-gatedone 2697c478bd9Sstevel@tonic-gateexit 0 270