Whamcloud - gitweb
LU-2275 mdt: Avoid setting positive dispositions too early
[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/linux/utsrelease.h") &&
47         !$ver->open("$objdir/include/linux/version.h") &&
48         !$ver->open("$dir/include/linux/utsrelease.h") &&
49         !$ver->open("$dir/include/linux/version.h")) {
50             die "Run make dep on '$dir'\n";
51     }
52
53     while(defined($line = <$ver>)) {
54         $line =~ /\#define UTS_RELEASE "(.*)"/;
55         if ($1) {
56             $kernver = $1;
57             last;
58         }
59     }
60     $ver->close();
61     chomp($kernver);
62     return $kernver;
63
64 }
65
66 sub generate_ver($$$$$$$)
67 {
68
69     my $tag = shift;
70     my $local_version = shift;
71     my $buildid = shift;
72     my $linuxdir = shift;
73     my $pristine = shift;
74     my $kernver = shift;
75     my $env_vers = shift;
76
77     print "#define BUILD_VERSION \"$tag";
78
79     if ($env_vers) {
80         print "-$env_vers\"\n";
81         return 0;
82     }
83
84     if ($local_version ne "") {
85         print "-$local_version";
86     }
87
88     print "-$buildid";
89     # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these
90     # lines.  maybe we only want to print -CHANGED when something is changed
91     # and print nothing when it's pristine
92     if ($pristine) {
93         print "-PRISTINE";
94     } else {
95         print "-CHANGED";
96     }
97
98     if ($kernver ne "") {
99         print "-$kernver";
100     }
101
102     print "\"\n";
103
104 }
105
106 my $progname = $0;
107 $progname =~ s/.*\///;
108
109 chomp(my $cwd = `pwd`);
110
111 my $path = $0;
112 $path =~ s/(.+)\/.*/\1/;
113 push(@INC, $cwd . "/" . $path);
114
115 my $is_git = 0;
116 my $is_cvs = 0;
117
118 # ARGV[0] = srcdir
119 # ARGV[1] = builddir
120
121 # need to be in srcdir
122 if ($ARGV[0]) {
123     chdir($ARGV[0]);
124 }
125
126 if (-d ".git") {
127     $is_git = 1;
128     require "version_tag-git.pl";
129 } elsif (-d "CVS") {
130     $is_cvs = 1;
131     require "version_tag-cvs.pl";
132 } else {
133     die("a tree status can only be determined in an source code control system checkout\n")
134         if ($progname eq "make_META.pl");
135     require "version_tag-none.pl";
136 }
137
138 ($am_linuxdir, $am_linuxobjdir, $am_modules, $am_version, $local_version,
139  $am_buildid) = read_autoMakefile();
140
141 my $tag = get_tag();
142 my $pristine = is_pristine();
143 my $buildid = get_buildid();
144
145 if ($progname eq "version_tag.pl") {
146     my $kernver = "";
147     $kernver = get_kernver($am_linuxdir, $am_linuxobjdir)
148         if ($am_linuxdir ne "");
149
150     my $linuxdir =~ s/\//\./g;
151     generate_ver($tag, $local_version, $buildid, $linuxdir, $pristine, $kernver,
152                  $ENV{LUSTRE_VERS});
153 } elsif ($progname eq "make_META.pl") {
154     print "TAG = $tag\n";
155     print "VERSION = $am_version\n";
156     print "BUILDID = $buildid\n";
157     print "PRISTINE = $pristine\n";
158     print "LOCAL_VERSION = $local_version\n";
159 }
160
161 exit(0);