Whamcloud - gitweb
LU-5162 mdc: Add exception entry check for radix_tree
[fs/lustre-release.git] / lustre / scripts / version_tag.pl
1 #!/usr/bin/perl
2 # -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*-
3
4 use IO::File;
5
6 # get all of the values we want out of the autoMakefile
7 sub read_autoMakefile() {
8
9     my $file = new IO::File;
10     my ($line, $dir, $objdir, $modules, $version, $local_version, $buildid);
11     if (!$file->open("autoMakefile")) {
12         die "Run ./configure first\n";
13     }
14     $modules = 1;
15     while (defined($line = <$file>)) {
16         chomp($line);
17         if ($line =~ /^LINUX :?= (.*)/) {
18             $dir = $1;
19         } elsif ($line =~ /^LINUX_OBJ :?= (.*)/) {
20             $objdir = $1;
21         } elsif ($line =~ /^MODULES_TRUE = #/ ||
22                  $line =~ /^MODULE_TARGET = $/) {
23             # modules are not being built
24             $modules = 1;
25         } elsif ($line =~ /^VERSION = (.*)/) {
26             $version = "$1";
27         } elsif ($line =~ /^DOWNSTREAM_RELEASE = (.*)/ && $1 ne "") {
28             $local_version = "$1";
29         } elsif ($line =~ /^BUILDID = (.*)/ && $1 ne "") {
30             $buildid = "$1";
31         }
32     }
33     $file->close();
34
35     return ($dir, $objdir, $modules, $version, $local_version, $buildid);
36
37 }
38
39 sub get_kernver($$)
40 {
41
42     my $dir = shift;
43     my $objdir = shift;
44
45     my $ver = new IO::File;
46     if (!$ver->open("$objdir/include/generated/utsrelease.h") &&
47         !$ver->open("$objdir/include/linux/utsrelease.h") &&
48         !$ver->open("$objdir/include/linux/version.h") &&
49         !$ver->open("$dir/include/generated/utsrelease.h") &&
50         !$ver->open("$dir/include/linux/utsrelease.h") &&
51         !$ver->open("$dir/include/linux/version.h")) {
52             die "Run make dep on '$dir'\n";
53     }
54
55     while(defined($line = <$ver>)) {
56         $line =~ /\#define UTS_RELEASE "(.*)"/;
57         if ($1) {
58             $kernver = $1;
59             last;
60         }
61     }
62     $ver->close();
63     chomp($kernver);
64     return $kernver;
65
66 }
67
68 sub generate_ver($$$$$$$)
69 {
70
71     my $tag = shift;
72     my $local_version = shift;
73     my $buildid = shift;
74     my $linuxdir = shift;
75     my $pristine = shift;
76     my $kernver = shift;
77     my $env_vers = shift;
78
79     print "#define BUILD_VERSION \"$tag";
80
81     if ($env_vers) {
82         print "-$env_vers\"\n";
83         return 0;
84     }
85
86     if ($local_version ne "") {
87         print "-$local_version";
88     }
89
90     print "-$buildid";
91     # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these
92     # lines.  maybe we only want to print -CHANGED when something is changed
93     # and print nothing when it's pristine
94     if ($pristine) {
95         print "-PRISTINE";
96     } else {
97         print "-CHANGED";
98     }
99
100     if ($kernver ne "") {
101         print "-$kernver";
102     }
103
104     print "\"\n";
105
106 }
107
108 my $progname = $0;
109 $progname =~ s/.*\///;
110
111 chomp(my $cwd = `pwd`);
112
113 my $path = $0;
114 $path =~ s/(.+)\/.*/\1/;
115 push(@INC, $cwd . "/" . $path);
116
117 # The _first_ argument on the command line may be --make_META
118 # Remove it from ARGV if found
119 if ($ARGV[0] eq "--make_META") {
120     shift @ARGV;
121     $make_meta = 1;
122 }
123
124 # ARGV[0] = srcdir
125 # ARGV[1] = builddir
126
127 # need to be in srcdir
128 if ($ARGV[0]) {
129     chdir($ARGV[0]);
130 }
131
132 if (-d ".git") {
133     require "version_tag-git.pl";
134 } else {
135     die("a tree status can only be determined in an source code control system checkout\n")
136         if ($make_meta);
137     require "version_tag-none.pl";
138 }
139
140 ($am_linuxdir, $am_linuxobjdir, $am_modules, $am_version, $local_version,
141  $am_buildid) = read_autoMakefile();
142
143 my $tag = get_tag();
144 my $pristine = is_pristine();
145 my $buildid = get_buildid();
146
147 if (!$make_meta) {
148     my $kernver = "";
149     $kernver = get_kernver($am_linuxdir, $am_linuxobjdir)
150         if ($am_linuxdir ne "");
151
152     my $linuxdir =~ s/\//\./g;
153     generate_ver($tag, $local_version, $buildid, $linuxdir, $pristine, $kernver,
154                  $ENV{LUSTRE_VERS});
155 } else {
156     print "TAG = $tag\n";
157     print "VERSION = $am_version\n";
158     print "BUILDID = $buildid\n";
159     print "PRISTINE = $pristine\n";
160     print "LOCAL_VERSION = $local_version\n";
161 }
162
163 exit(0);