]> git.saurik.com Git - apple/xnu.git/blob - config/newvers.pl
xnu-792.6.56.tar.gz
[apple/xnu.git] / config / newvers.pl
1 #!/usr/bin/perl
2 #
3 # This tool is used to stamp kernel version information into files at kernel
4 # build time. Each argument provided on the command line is the path to a file
5 # that needs to be updated with the current verison information. The file
6 # xnu/config/MasterVersion is read to determine the version number to use.
7 # Each file is read, and all occurrences of the following strings are replaced
8 # in-place like so:
9 # ###KERNEL_VERSION_LONG### 1.2.3b4
10 # ###KERNEL_VERSION_SHORT### 1.2.3
11 # ###KERNEL_VERSION_MAJOR### 1
12 # ###KERNEL_VERSION_MINOR### 2
13 # ###KERNEL_VERSION_VARIANT### 3b4
14 # ###KERNEL_VERSION_REVISION### 3
15 # ###KERNEL_VERSION_STAGE### VERSION_STAGE_BETA (see libkern/version.h)
16 # ###KERNEL_VERSION_PRERELEASE_LEVEL### 4
17 # ###KERNEL_BUILDER### root
18 # ###KERNEL_BUILD_OBJROOT### xnu/xnu-690.obj~2/RELEASE_PPC
19 # ###KERNEL_BUILD_DATE### Sun Oct 24 05:33:28 PDT 2004
20
21 sub ReadFile {
22 my ($fileName) = @_;
23 my $data;
24 local $/ = undef; # Read complete files
25
26 if (open(IN, "<$fileName")) {
27 $data=<IN>;
28 close IN;
29 return $data;
30 }
31 die "newvers: Can't read file \"$fileName\"\n";
32 }
33
34 sub WriteFile {
35 my ($fileName, $data) = @_;
36
37 open (OUT, ">$fileName") or die "newvers: Can't write file \"$fileName\"\n";
38 print OUT $data;
39 close(OUT);
40 }
41
42 my $versfile = "MasterVersion";
43 $versfile = "$ENV{'SRCROOT'}/config/$versfile" if ($ENV{'SRCROOT'});
44 my $BUILD_OBJROOT=$ENV{'OBJROOT'} . "/" . $ENV{'KERNEL_CONFIG'} . '_' . $ENV{'ARCH_CONFIG'};
45 my $BUILD_DATE = `date`;
46 $BUILD_DATE =~ s/[\n\t]//g;
47 my $BUILDER=`whoami`;
48 $BUILDER =~ s/[\n\t]//g;
49 $BUILD_OBJROOT =~ s|.*(xnu.*)|$1|;
50
51 my $rawvers = &ReadFile($versfile);
52 #$rawvers =~ s/\s//g;
53 ($rawvers) = split "\n", $rawvers;
54 my ($VERSION_MAJOR, $VERSION_MINOR, $VERSION_VARIANT) = split /\./, $rawvers;
55 die "newvers: Invalid MasterVersion \"$rawvers\"!!! " if (!$VERSION_MAJOR);
56 $VERSION_MINOR = "0" unless ($VERSION_MINOR);
57 $VERSION_VARIANT = "0" unless ($VERSION_VARIANT);
58 $VERSION_VARIANT =~ tr/A-Z/a-z/;
59 $VERSION_VARIANT =~ m/(\d+)((?:d|a|b|r|fc)?)(\d*)/;
60 my $VERSION_REVISION = $1;
61 my $stage = $2;
62 my $VERSION_PRERELEASE_LEVEL = $3;
63 $VERSION_REVISION ="0" unless ($VERSION_REVISION);
64 $stage = "r" if (!$stage || ($stage eq "fc"));
65 $VERSION_PRERELEASE_LEVEL = "0" unless ($VERSION_PRERELEASE_LEVEL);
66
67 my $VERSION_STAGE;
68 $VERSION_STAGE = 'VERSION_STAGE_DEV' if ($stage eq 'd');
69 $VERSION_STAGE = 'VERSION_STAGE_ALPHA' if ($stage eq 'a');
70 $VERSION_STAGE = 'VERSION_STAGE_BETA' if ($stage eq 'b');
71 $VERSION_STAGE = 'VERSION_STAGE_RELEASE' if ($stage eq 'r');
72
73 my $VERSION_SHORT = "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_REVISION";
74 my $VERSION_LONG = $VERSION_SHORT;
75 $VERSION_LONG .= "$stage$VERSION_PRERELEASE_LEVEL" if (($stage ne "r") || ($VERSION_PRERELEASE_LEVEL != 0));
76
77 my $file;
78 foreach $file (@ARGV) {
79 print "newvers.pl: Stamping version \"$VERSION_LONG\" into \"$file\" ...";
80 my $data = &ReadFile($file);
81 my $count=0;
82 $count += $data =~ s/###KERNEL_VERSION_LONG###/$VERSION_LONG/g;
83 $count += $data =~ s/###KERNEL_VERSION_SHORT###/$VERSION_SHORT/g;
84 $count += $data =~ s/###KERNEL_VERSION_MAJOR###/$VERSION_MAJOR/g;
85 $count += $data =~ s/###KERNEL_VERSION_MINOR###/$VERSION_MINOR/g;
86 $count += $data =~ s/###KERNEL_VERSION_VARIANT###/$VERSION_VARIANT/g;
87 $count += $data =~ s/###KERNEL_VERSION_REVISION###/$VERSION_REVISION/g;
88 $count += $data =~ s/###KERNEL_VERSION_STAGE###/$VERSION_STAGE/g;
89 $count += $data =~ s/###KERNEL_VERSION_PRERELEASE_LEVEL###/$VERSION_PRERELEASE_LEVEL/g;
90 $count += $data =~ s/###KERNEL_BUILDER###/$BUILDER/g;
91 $count += $data =~ s/###KERNEL_BUILD_OBJROOT###/$BUILD_OBJROOT/g;
92 $count += $data =~ s/###KERNEL_BUILD_DATE###/$BUILD_DATE/g;
93 print " $count replacements\n";
94 &WriteFile($file, $data);
95 }
96
97 if (0==scalar @ARGV) {
98 print "newvers.pl: read version \"$rawvers\" from \"$versfile\"\n";
99 print "newvers.pl: ###KERNEL_VERSION_LONG### = $VERSION_LONG\n";
100 print "newvers.pl: ###KERNEL_VERSION_SHORT### = $VERSION_SHORT\n";
101 print "newvers.pl: ###KERNEL_VERSION_MAJOR### = $VERSION_MAJOR\n";
102 print "newvers.pl: ###KERNEL_VERSION_MINOR### = $VERSION_MINOR\n";
103 print "newvers.pl: ###KERNEL_VERSION_VARIANT### = $VERSION_VARIANT\n";
104 print "newvers.pl: ###KERNEL_VERSION_REVISION### = $VERSION_REVISION\n";
105 print "newvers.pl: ###KERNEL_VERSION_STAGE### = $VERSION_STAGE\n";
106 print "newvers.pl: ###KERNEL_VERSION_PRERELEASE_LEVEL### = $VERSION_PRERELEASE_LEVEL\n";
107 print "newvers.pl: ###KERNEL_BUILDER### = $BUILDER\n";
108 print "newvers.pl: ###KERNEL_BUILD_OBJROOT### = $BUILD_OBJROOT\n";
109 print "newvers.pl: ###KERNEL_BUILD_DATE### = $BUILD_DATE\n";
110 }