]>
Commit | Line | Data |
---|---|---|
91447636 A |
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'}; | |
2d21ac55 A |
45 | if($ENV{'MACHINE_CONFIG'} ne "DEFAULT") { |
46 | $BUILD_OBJROOT .= '_' . $ENV{'MACHINE_CONFIG'}; | |
47 | } | |
91447636 A |
48 | my $BUILD_DATE = `date`; |
49 | $BUILD_DATE =~ s/[\n\t]//g; | |
50 | my $BUILDER=`whoami`; | |
51 | $BUILDER =~ s/[\n\t]//g; | |
52 | $BUILD_OBJROOT =~ s|.*(xnu.*)|$1|; | |
53 | ||
54 | my $rawvers = &ReadFile($versfile); | |
55 | #$rawvers =~ s/\s//g; | |
56 | ($rawvers) = split "\n", $rawvers; | |
57 | my ($VERSION_MAJOR, $VERSION_MINOR, $VERSION_VARIANT) = split /\./, $rawvers; | |
58 | die "newvers: Invalid MasterVersion \"$rawvers\"!!! " if (!$VERSION_MAJOR); | |
59 | $VERSION_MINOR = "0" unless ($VERSION_MINOR); | |
60 | $VERSION_VARIANT = "0" unless ($VERSION_VARIANT); | |
61 | $VERSION_VARIANT =~ tr/A-Z/a-z/; | |
62 | $VERSION_VARIANT =~ m/(\d+)((?:d|a|b|r|fc)?)(\d*)/; | |
63 | my $VERSION_REVISION = $1; | |
64 | my $stage = $2; | |
65 | my $VERSION_PRERELEASE_LEVEL = $3; | |
66 | $VERSION_REVISION ="0" unless ($VERSION_REVISION); | |
67 | $stage = "r" if (!$stage || ($stage eq "fc")); | |
68 | $VERSION_PRERELEASE_LEVEL = "0" unless ($VERSION_PRERELEASE_LEVEL); | |
69 | ||
70 | my $VERSION_STAGE; | |
71 | $VERSION_STAGE = 'VERSION_STAGE_DEV' if ($stage eq 'd'); | |
72 | $VERSION_STAGE = 'VERSION_STAGE_ALPHA' if ($stage eq 'a'); | |
73 | $VERSION_STAGE = 'VERSION_STAGE_BETA' if ($stage eq 'b'); | |
74 | $VERSION_STAGE = 'VERSION_STAGE_RELEASE' if ($stage eq 'r'); | |
75 | ||
76 | my $VERSION_SHORT = "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_REVISION"; | |
77 | my $VERSION_LONG = $VERSION_SHORT; | |
78 | $VERSION_LONG .= "$stage$VERSION_PRERELEASE_LEVEL" if (($stage ne "r") || ($VERSION_PRERELEASE_LEVEL != 0)); | |
79 | ||
80 | my $file; | |
81 | foreach $file (@ARGV) { | |
82 | print "newvers.pl: Stamping version \"$VERSION_LONG\" into \"$file\" ..."; | |
83 | my $data = &ReadFile($file); | |
84 | my $count=0; | |
85 | $count += $data =~ s/###KERNEL_VERSION_LONG###/$VERSION_LONG/g; | |
86 | $count += $data =~ s/###KERNEL_VERSION_SHORT###/$VERSION_SHORT/g; | |
87 | $count += $data =~ s/###KERNEL_VERSION_MAJOR###/$VERSION_MAJOR/g; | |
88 | $count += $data =~ s/###KERNEL_VERSION_MINOR###/$VERSION_MINOR/g; | |
89 | $count += $data =~ s/###KERNEL_VERSION_VARIANT###/$VERSION_VARIANT/g; | |
90 | $count += $data =~ s/###KERNEL_VERSION_REVISION###/$VERSION_REVISION/g; | |
91 | $count += $data =~ s/###KERNEL_VERSION_STAGE###/$VERSION_STAGE/g; | |
92 | $count += $data =~ s/###KERNEL_VERSION_PRERELEASE_LEVEL###/$VERSION_PRERELEASE_LEVEL/g; | |
93 | $count += $data =~ s/###KERNEL_BUILDER###/$BUILDER/g; | |
94 | $count += $data =~ s/###KERNEL_BUILD_OBJROOT###/$BUILD_OBJROOT/g; | |
95 | $count += $data =~ s/###KERNEL_BUILD_DATE###/$BUILD_DATE/g; | |
96 | print " $count replacements\n"; | |
97 | &WriteFile($file, $data); | |
98 | } | |
99 | ||
100 | if (0==scalar @ARGV) { | |
101 | print "newvers.pl: read version \"$rawvers\" from \"$versfile\"\n"; | |
102 | print "newvers.pl: ###KERNEL_VERSION_LONG### = $VERSION_LONG\n"; | |
103 | print "newvers.pl: ###KERNEL_VERSION_SHORT### = $VERSION_SHORT\n"; | |
104 | print "newvers.pl: ###KERNEL_VERSION_MAJOR### = $VERSION_MAJOR\n"; | |
105 | print "newvers.pl: ###KERNEL_VERSION_MINOR### = $VERSION_MINOR\n"; | |
106 | print "newvers.pl: ###KERNEL_VERSION_VARIANT### = $VERSION_VARIANT\n"; | |
107 | print "newvers.pl: ###KERNEL_VERSION_REVISION### = $VERSION_REVISION\n"; | |
108 | print "newvers.pl: ###KERNEL_VERSION_STAGE### = $VERSION_STAGE\n"; | |
109 | print "newvers.pl: ###KERNEL_VERSION_PRERELEASE_LEVEL### = $VERSION_PRERELEASE_LEVEL\n"; | |
110 | print "newvers.pl: ###KERNEL_BUILDER### = $BUILDER\n"; | |
111 | print "newvers.pl: ###KERNEL_BUILD_OBJROOT### = $BUILD_OBJROOT\n"; | |
112 | print "newvers.pl: ###KERNEL_BUILD_DATE### = $BUILD_DATE\n"; | |
113 | } |