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