1#!/usr/bin/ksh -p 2# 3# CDDL HEADER START 4# 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. 8# 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. 13# 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] 19# 20# CDDL HEADER END 21# 22# 23# ident "%Z%%M% %I% %E% SMI" 24# 25# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 26# Use is subject to license terms. 27# 28# Given a machine-optimal patch makeup table (see ctfcvtptbl), this program 29# will allow the build process to determine the following: 30# 31# * The patch ID associated with a given module 32# * The KU required by the patch associated with a given module 33# * The patch ID and location of the genunix module preceding the genunix 34# module currently being built. 35# 36 37PROGNAME=$(basename "$0") 38 39usage() 40{ 41 echo "Usage: $PROGNAME [-nr] [-o outfmt] [-b build_type] -t table" \ 42 "module_path" >&2 43} 44 45die() 46{ 47 echo "$1" >&2 48 exit 1 49} 50 51outfmt="patch,ku" 52notfoundok=0 53relative=0 54build_type=debug32 55err=0 56while getopts b:lno:rt: c ; do 57 case $c in 58 b) 59 build_type="$OPTARG" 60 ;; 61 n) 62 notfoundok=1 63 ;; 64 o) 65 outfmt="$OPTARG" 66 ;; 67 r) 68 relative=1 69 ;; 70 t) 71 table="$OPTARG" 72 ;; 73 \?) 74 err=1 75 ;; 76 esac 77done 78shift `expr $OPTIND - 1` 79 80if [[ $err -eq 1 || $# -ne 1 || -z "$table" ]] ; then 81 usage 82 exit 2 83fi 84 85print_garpath=0 86print_ku=0 87print_patch=0 88print_lastgu=0 89for word in $(echo "$outfmt" |tr ',' ' ') ; do 90 case $word in 91 garpath) 92 print_garpath=1 93 ;; 94 ku) 95 print_ku=1 96 ;; 97 lastgu) 98 print_lastgu=1 99 ;; 100 patch) 101 print_patch=1 102 ;; 103 \?) 104 usage 105 exit 2 106 esac 107done 108 109module="$1" 110shift 111 112if [[ ! -f "$table" ]] ; then 113 die "$PROGNAME: Cannot open $table" 114fi 115 116head -1 "$table" |sed -e 's/^\([^=]*\)=/\1 /' |read garkw garpath 117 118if [[ "$garkw" != "GENUNIX_ARCHIVE" || -z "$garpath" ]] ; then 119 die "$PROGNAME: $table is not a machine-optimal patch table" >&2 120fi 121 122if [[ $relative -eq 1 ]] ; then 123 crd=$(pwd |sed -e 's:^.*usr/src/uts::') 124 module=$(echo "$crd/$module" |sed -e 's://*:/:g') 125fi 126 127fgrep "$module" "$table" |read junk patch ku 128 129if [[ -z "$patch" || 130 "$(expr "$patch" : '[0-9]\{6\}-[0-9][0-9]')" -ne 9 ]] ; then 131 if [[ "$notfoundok" -eq 1 ]] ; then 132 patch="-" 133 else 134 die "$PROGNAME: Cannot find patch for $module" >&2 135 fi 136fi 137 138if [[ -z "$ku" ]] ; then 139 ku="-" 140fi 141 142# Output 143 144space="" 145if [[ $print_patch -eq 1 ]] ; then 146 echo "$space$patch\c" 147 space=" " 148fi 149if [[ $print_ku -eq 1 ]] ; then 150 echo "$space$ku\c" 151 space=" " 152fi 153if [[ $print_garpath -eq 1 ]] ; then 154 echo "$space$garpath\c" 155 space=" " 156fi 157if [[ $print_lastgu -eq 1 ]] ; then 158 suffix= 159 if expr $build_type : '.*64' >/dev/null ; then 160 if [ `uname -p` = "sparc" ] ; then 161 suffix=/sparcv9 162 else 163 suffix=/amd64 164 fi 165 fi 166 echo "$space$garpath/$ku$suffix/genunix\c" 167 space=" " 168fi 169[[ -n "$space" ]] && echo 170 171return 0 172