1*3edf445cSab196087#!/usr/bin/perl -w 2*3edf445cSab196087# 3*3edf445cSab196087# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 4*3edf445cSab196087# Use is subject to license terms. 5*3edf445cSab196087# 6*3edf445cSab196087# CDDL HEADER START 7*3edf445cSab196087# 8*3edf445cSab196087# The contents of this file are subject to the terms of the 9*3edf445cSab196087# Common Development and Distribution License (the "License"). 10*3edf445cSab196087# You may not use this file except in compliance with the License. 11*3edf445cSab196087# 12*3edf445cSab196087# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13*3edf445cSab196087# or http://www.opensolaris.org/os/licensing. 14*3edf445cSab196087# See the License for the specific language governing permissions 15*3edf445cSab196087# and limitations under the License. 16*3edf445cSab196087# 17*3edf445cSab196087# When distributing Covered Code, include this CDDL HEADER in each 18*3edf445cSab196087# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19*3edf445cSab196087# If applicable, add the following below this CDDL HEADER, with the 20*3edf445cSab196087# fields enclosed by brackets "[]" replaced with your own identifying 21*3edf445cSab196087# information: Portions Copyright [yyyy] [name of copyright owner] 22*3edf445cSab196087# 23*3edf445cSab196087# CDDL HEADER END 24*3edf445cSab196087# 25*3edf445cSab196087#pragma ident "%Z%%M% %I% %E% SMI" 26*3edf445cSab196087 27*3edf445cSab196087 28*3edf445cSab196087# 29*3edf445cSab196087# Generate a revision number for the sgs linker components, based 30*3edf445cSab196087# on usr/src/cmd/sgs/packages/common/SUNWonld-README. 31*3edf445cSab196087# 32*3edf445cSab196087# usage: readme_revision [-d] [readme-file] 33*3edf445cSab196087# 34*3edf445cSab196087# This revision number used to be the SCCS revision id for that file, 35*3edf445cSab196087# in the form 1.xxx (where xxx was the revision). There were two benefits: 36*3edf445cSab196087# 37*3edf445cSab196087# (1) You could examine the sccs revision log to determine the CR 38*3edf445cSab196087# of the putback that created the revision. 39*3edf445cSab196087# (2) The revisions were monotonically increasing. 40*3edf445cSab196087# 41*3edf445cSab196087# In order to remove the hard wired dependence on sccs, this script generates 42*3edf445cSab196087# a replacement revision number, by returning the string '1.xxx', where 43*3edf445cSab196087# xxx is an integer giving the number of unique CR lines found in the file. 44*3edf445cSab196087# This means that the revision goes up by one for each CR we fix, which 45*3edf445cSab196087# makes intutive sense, and is similar to the way the SCCS revision worked. 46*3edf445cSab196087# 47*3edf445cSab196087# If this is a debug/development build (-d option), then we include 48*3edf445cSab196087# additional information at the end of the revision: 49*3edf445cSab196087# 50*3edf445cSab196087# - Workspace name 51*3edf445cSab196087# - user 52*3edf445cSab196087# - CR # of last item in the readme file 53*3edf445cSab196087# - date, 54*3edf445cSab196087# 55*3edf445cSab196087# This extra information is useful when we need to identify SUNWonld 56*3edf445cSab196087# linker packages in the field, and provides the information previously 57*3edf445cSab196087# supplied by (1) above. 58*3edf445cSab196087# 59*3edf445cSab196087 60*3edf445cSab196087use vars qw($script $usage $readme $cnt); 61*3edf445cSab196087use vars qw($debug $last_cr $wsname $date); 62*3edf445cSab196087 63*3edf445cSab196087# Use the basename of the name we're invoked under as the script name 64*3edf445cSab196087@_ = split /\//, $0; 65*3edf445cSab196087$script = $_[$#_]; 66*3edf445cSab196087$usage = "usage: $script [-d] [readme-file]\n"; 67*3edf445cSab196087 68*3edf445cSab196087$debug = 0; 69*3edf445cSab196087# Process the options 70*3edf445cSab196087while ((scalar(@ARGV) > 0) && ($_ = $ARGV[0],/^-/)) { 71*3edf445cSab196087 ARG: { 72*3edf445cSab196087 if (/^-d$/) { 73*3edf445cSab196087 $debug = 1; 74*3edf445cSab196087 last ARG; 75*3edf445cSab196087 } 76*3edf445cSab196087 77*3edf445cSab196087 78*3edf445cSab196087 # If it gets here, the option is unknown. 79*3edf445cSab196087 die $usage; 80*3edf445cSab196087 } 81*3edf445cSab196087 shift; 82*3edf445cSab196087} 83*3edf445cSab196087 84*3edf445cSab196087# Plain argument 85*3edf445cSab196087$cnt = scalar @ARGV; 86*3edf445cSab196087{ 87*3edf445cSab196087 if ($cnt == 0) { 88*3edf445cSab196087 $readme = 'SUNWonld-README'; 89*3edf445cSab196087 next; 90*3edf445cSab196087 } 91*3edf445cSab196087 92*3edf445cSab196087 if ($cnt == 1) { 93*3edf445cSab196087 $readme = $ARGV[0]; 94*3edf445cSab196087 next; 95*3edf445cSab196087 } 96*3edf445cSab196087 97*3edf445cSab196087 die $usage; 98*3edf445cSab196087} 99*3edf445cSab196087 100*3edf445cSab196087 101*3edf445cSab196087open(FILE, $readme) || die "$script: Unable to open $readme\n"; 102*3edf445cSab196087 103*3edf445cSab196087# At the date this script was put into service, the SCCS revision 104*3edf445cSab196087# of SUNWonld-README was 1.627, and SUNWonld-README had 588 unique 105*3edf445cSab196087# CRs. Revisions are supposed to always increase monotonically, so 106*3edf445cSab196087# we add 1000 to the number of unique CRs. 107*3edf445cSab196087# 108*3edf445cSab196087# This means that any linker with a version <1000 was built using 109*3edf445cSab196087# the SCCS revision, and any linker with version >=1000 was built 110*3edf445cSab196087# with this script. 111*3edf445cSab196087$cnt = 1000; 112*3edf445cSab196087 113*3edf445cSab196087while ($_ = <FILE>) { 114*3edf445cSab196087 chomp $_; 115*3edf445cSab196087 116*3edf445cSab196087 # If the line starts with a number, it is taken as a CR. 117*3edf445cSab196087 if ($_ =~ /^(\d+)\s/) { 118*3edf445cSab196087 $cnt++; 119*3edf445cSab196087 $last_cr = $1; 120*3edf445cSab196087 } 121*3edf445cSab196087} 122*3edf445cSab196087close FILE; 123*3edf445cSab196087 124*3edf445cSab196087# If this is a standard build, the revision # is all we want 125*3edf445cSab196087if ($debug == 0) { 126*3edf445cSab196087 print "1.$cnt\n"; 127*3edf445cSab196087 exit 0; 128*3edf445cSab196087} 129*3edf445cSab196087 130*3edf445cSab196087# For debug mode, add diagnostic data 131*3edf445cSab196087# 132*3edf445cSab196087($wsname = $ENV{'CODEMGR_WS'}) ne '' || ($wsname = 'unknown'); 133*3edf445cSab196087@wsname = split /\//, $wsname; 134*3edf445cSab196087$wsname = $wsname[$#wsname]; 135*3edf445cSab196087 136*3edf445cSab196087$date = `date +%m/%d/%y`; 137*3edf445cSab196087 138*3edf445cSab196087print "1.$cnt:$wsname-$ENV{USER}-$last_cr-$date\n"; 139*3edf445cSab196087 140*3edf445cSab196087exit 0; 141