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