xref: /onnv-gate/usr/src/tools/ctf/scripts/ctffindmod.sh (revision 2722:3846fae40902)
10Sstevel@tonic-gate#!/usr/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
6*2722Sjohnlev# Common Development and Distribution License (the "License").
7*2722Sjohnlev# 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#
230Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
240Sstevel@tonic-gate#
25*2722Sjohnlev# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
260Sstevel@tonic-gate# Use is subject to license terms.
270Sstevel@tonic-gate#
280Sstevel@tonic-gate# Given a machine-optimal patch makeup table (see ctfcvtptbl), this program
290Sstevel@tonic-gate# will allow the build process to determine the following:
300Sstevel@tonic-gate#
310Sstevel@tonic-gate#   * The patch ID associated with a given module
320Sstevel@tonic-gate#   * The KU required by the patch associated with a given module
330Sstevel@tonic-gate#   * The patch ID and location of the genunix module preceding the genunix
340Sstevel@tonic-gate#     module currently being built.
350Sstevel@tonic-gate#
360Sstevel@tonic-gate
370Sstevel@tonic-gatePROGNAME=$(basename "$0")
380Sstevel@tonic-gate
390Sstevel@tonic-gateusage()
400Sstevel@tonic-gate{
410Sstevel@tonic-gate	echo "Usage: $PROGNAME [-nr] [-o outfmt] [-b build_type] -t table" \
420Sstevel@tonic-gate	    "module_path" >&2
430Sstevel@tonic-gate}
440Sstevel@tonic-gate
450Sstevel@tonic-gatedie()
460Sstevel@tonic-gate{
470Sstevel@tonic-gate	echo "$1" >&2
480Sstevel@tonic-gate	exit 1
490Sstevel@tonic-gate}
500Sstevel@tonic-gate
510Sstevel@tonic-gateoutfmt="patch,ku"
520Sstevel@tonic-gatenotfoundok=0
530Sstevel@tonic-gaterelative=0
540Sstevel@tonic-gatebuild_type=debug32
550Sstevel@tonic-gateerr=0
560Sstevel@tonic-gatewhile getopts b:lno:rt: c ; do
570Sstevel@tonic-gate	case $c in
580Sstevel@tonic-gate	    b)
590Sstevel@tonic-gate		build_type="$OPTARG"
600Sstevel@tonic-gate		;;
610Sstevel@tonic-gate	    n)
620Sstevel@tonic-gate		notfoundok=1
630Sstevel@tonic-gate		;;
640Sstevel@tonic-gate	    o)
650Sstevel@tonic-gate		outfmt="$OPTARG"
660Sstevel@tonic-gate		;;
670Sstevel@tonic-gate	    r)
680Sstevel@tonic-gate		relative=1
690Sstevel@tonic-gate		;;
700Sstevel@tonic-gate	    t)
710Sstevel@tonic-gate		table="$OPTARG"
720Sstevel@tonic-gate		;;
730Sstevel@tonic-gate	    \?)
740Sstevel@tonic-gate		err=1
750Sstevel@tonic-gate		;;
760Sstevel@tonic-gate	esac
770Sstevel@tonic-gatedone
780Sstevel@tonic-gateshift `expr $OPTIND - 1`
790Sstevel@tonic-gate
800Sstevel@tonic-gateif [[ $err -eq 1 || $# -ne 1 || -z "$table" ]] ; then
810Sstevel@tonic-gate	usage
820Sstevel@tonic-gate	exit 2
830Sstevel@tonic-gatefi
840Sstevel@tonic-gate
850Sstevel@tonic-gateprint_garpath=0
860Sstevel@tonic-gateprint_ku=0
870Sstevel@tonic-gateprint_patch=0
880Sstevel@tonic-gateprint_lastgu=0
890Sstevel@tonic-gatefor word in $(echo "$outfmt" |tr ',' ' ') ; do
900Sstevel@tonic-gate	case $word in
910Sstevel@tonic-gate	    garpath)
920Sstevel@tonic-gate		print_garpath=1
930Sstevel@tonic-gate		;;
940Sstevel@tonic-gate	    ku)
950Sstevel@tonic-gate		print_ku=1
960Sstevel@tonic-gate		;;
970Sstevel@tonic-gate	    lastgu)
980Sstevel@tonic-gate		print_lastgu=1
990Sstevel@tonic-gate		;;
1000Sstevel@tonic-gate	    patch)
1010Sstevel@tonic-gate		print_patch=1
1020Sstevel@tonic-gate		;;
1030Sstevel@tonic-gate	    \?)
1040Sstevel@tonic-gate		usage
1050Sstevel@tonic-gate		exit 2
1060Sstevel@tonic-gate	esac
1070Sstevel@tonic-gatedone
1080Sstevel@tonic-gate
1090Sstevel@tonic-gatemodule="$1"
1100Sstevel@tonic-gateshift
1110Sstevel@tonic-gate
1120Sstevel@tonic-gateif [[ ! -f "$table" ]] ; then
1130Sstevel@tonic-gate	die "$PROGNAME: Cannot open $table"
1140Sstevel@tonic-gatefi
1150Sstevel@tonic-gate
1160Sstevel@tonic-gatehead -1 "$table" |sed -e 's/^\([^=]*\)=/\1 /' |read garkw garpath
1170Sstevel@tonic-gate
1180Sstevel@tonic-gateif [[ "$garkw" != "GENUNIX_ARCHIVE" || -z "$garpath" ]] ; then
1190Sstevel@tonic-gate	die "$PROGNAME: $table is not a machine-optimal patch table" >&2
1200Sstevel@tonic-gatefi
1210Sstevel@tonic-gate
1220Sstevel@tonic-gateif [[ $relative -eq 1 ]] ; then
1230Sstevel@tonic-gate	crd=$(pwd |sed -e 's:^.*usr/src/uts::')
1240Sstevel@tonic-gate	module=$(echo "$crd/$module" |sed -e 's://*:/:g')
1250Sstevel@tonic-gatefi
1260Sstevel@tonic-gate
1270Sstevel@tonic-gatefgrep "$module" "$table" |read junk patch ku
1280Sstevel@tonic-gate
1290Sstevel@tonic-gateif [[ -z "$patch" ||
1300Sstevel@tonic-gate    "$(expr "$patch" : '[0-9]\{6\}-[0-9][0-9]')" -ne 9 ]] ; then
1310Sstevel@tonic-gate	if [[ "$notfoundok" -eq 1 ]] ; then
1320Sstevel@tonic-gate		patch="-"
1330Sstevel@tonic-gate	else
1340Sstevel@tonic-gate		die "$PROGNAME: Cannot find patch for $module" >&2
1350Sstevel@tonic-gate	fi
1360Sstevel@tonic-gatefi
1370Sstevel@tonic-gate
1380Sstevel@tonic-gateif [[ -z "$ku" ]] ; then
1390Sstevel@tonic-gate	ku="-"
1400Sstevel@tonic-gatefi
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate# Output
1430Sstevel@tonic-gate
1440Sstevel@tonic-gatespace=""
1450Sstevel@tonic-gateif [[ $print_patch -eq 1 ]] ; then
1460Sstevel@tonic-gate	echo "$space$patch\c"
1470Sstevel@tonic-gate	space=" "
1480Sstevel@tonic-gatefi
1490Sstevel@tonic-gateif [[ $print_ku -eq 1 ]] ; then
1500Sstevel@tonic-gate	echo "$space$ku\c"
1510Sstevel@tonic-gate	space=" "
1520Sstevel@tonic-gatefi
1530Sstevel@tonic-gateif [[ $print_garpath -eq 1 ]] ; then
1540Sstevel@tonic-gate	echo "$space$garpath\c"
1550Sstevel@tonic-gate	space=" "
1560Sstevel@tonic-gatefi
1570Sstevel@tonic-gateif [[ $print_lastgu -eq 1 ]] ; then
1580Sstevel@tonic-gate	suffix=
1590Sstevel@tonic-gate	if expr $build_type : '.*64' >/dev/null ; then
1600Sstevel@tonic-gate		if [ `uname -p` = "sparc" ] ; then
1610Sstevel@tonic-gate			suffix=/sparcv9
1620Sstevel@tonic-gate		else
163*2722Sjohnlev			suffix=/amd64
1640Sstevel@tonic-gate		fi
1650Sstevel@tonic-gate	fi
1660Sstevel@tonic-gate	echo "$space$garpath/$ku$suffix/genunix\c"
1670Sstevel@tonic-gate	space=" "
1680Sstevel@tonic-gatefi
1690Sstevel@tonic-gate[[ -n "$space" ]] && echo
1700Sstevel@tonic-gate
1710Sstevel@tonic-gatereturn 0
172