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