2 # -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*-
12 # Use the CVS tag first otherwise use the portals version
18 my $tagfile = new IO::File;
19 if (!$tagfile->open("lustre/CVS/Tag")) {
20 # is there a good way to do this with git or should the git case just
21 # fall through to use config.h? it is always nice to know if we are
22 # working on a tag or branch.
23 my $verfile = new IO::File;
24 if (!$verfile->open("config.h")) {
27 while(defined($line = <$verfile>)) {
28 $line =~ /\#define VERSION "(.*)"/;
45 sub get_latest_mtime()
47 my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4,
48 "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9,
49 "Nov" => 10, "Dec" => 11);
55 # if we got here, we are operating in a CVS checkout
56 my @entries = `find . -name Entries`;
58 foreach $entry_file (@entries) {
60 my $entry = new IO::File;
61 if (!$entry->open($entry_file)) {
62 die "unable to open $entry_file: $!\n";
65 while (defined($line = <$entry>)) {
67 #print "line: $line\n";
68 my ($junk, $file, $version, $date) = split(/\//, $line);
70 #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n";
71 #print "last_mtime: " . localtime($last_mtime) . "\n";
74 $file eq "lustre.spec.in") {
75 # also used to skip: "$file !~ m/\.(c|h|am|in)$/" but I see
76 # no good reason why only the above file patterns should
77 # count towards pristine/changed. it should be any file,
82 my $cur_dir = $entry_file;
83 $cur_dir =~ s/\/CVS\/Entries$//;
84 my @statbuf = stat("$cur_dir/$file");
85 my $mtime = $statbuf[9];
86 if (!defined($mtime)) {
89 my $local_date = gmtime($mtime);
90 if ($local_date ne $date &&
91 $file ne "lustre.spec.in") {
92 #print "$file : " . localtime($mtime) . "\n";
96 if ($mtime > $last_mtime) {
101 my @t = split(/ +/, $date);
103 #print "skipping: $date\n";
106 my ($hours, $min, $sec) = split(/:/, $t[3]);
107 my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]);
109 $mon = $months{$mon};
110 $secs = timelocal($sec, $min, $hours, $mday, $mon, $year);
111 if ($secs > $last_mtime) {
118 } elsif (-d ".git") {
120 # TODO: figure out how to determine the most recently modified file
121 # in a git working copy.
122 # NOTE: this is not simply the newest file in the whole tree,
123 # but the newest file in the tree that is from the
125 $last_mtime = time();
127 my $tree_status = new IO::File;
128 if (!$tree_status->open("tree_status")) {
129 die "unable to open the tree_status file: $!\n";
132 while (defined($line = <$tree_status>)) {
133 if ($line =~ /^PRISTINE\s*=\s*(\d)/) {
135 } elsif ($line =~ /^MTIME\s*=\s*(\d+)/) {
146 my $config = new IO::File;
147 my ($line, $dir, $objdir);
148 if (!$config->open("autoMakefile")) {
149 die "Run ./configure first\n";
151 while (defined($line = <$config>)) {
153 if ($line =~ /LINUX :?= (.*)/) {
155 } elsif ($line =~ /LINUX_OBJ :?= (.*)/) {
157 } elsif ($line =~ /MODULES_TRUE = #/ ||
158 $line =~ /MODULE_TARGET = $/) {
159 # nothing to do if modules are not being built
164 my $ver = new IO::File;
165 if (!$ver->open("$objdir/include/linux/utsrelease.h") &&
166 !$ver->open("$objdir/include/linux/version.h") &&
167 !$ver->open("$dir/include/linux/utsrelease.h") &&
168 !$ver->open("$dir/include/linux/version.h")) {
169 die "Run make dep on '$dir'\n";
172 while(defined($line = <$ver>)) {
173 $line =~ /\#define UTS_RELEASE "(.*)"/;
189 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
193 my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday,
199 sub generate_ver($$$)
203 my $linuxdir = shift;
205 # assume building without modules
208 if ($linuxdir ne "") {
209 $postfix = "-$kernver";
212 #print "localtime: " . localtime($mtime) . "\n";
214 my $lustre_vers = $ENV{LUSTRE_VERS};
216 print "#define BUILD_VERSION \"";
219 print "$tag-$lustre_vers\"\n";
223 my $show_last = mtime2date($mtime);
225 # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these
226 # lines. maybe we only want to print -CHANGED when something is changed
227 # and print nothing when it's pristine
229 print "$tag-$show_last-PRISTINE$postfix\"\n";
231 print "$tag-$show_last-CHANGED$postfix\"\n";
236 $progname =~ s/.*\///;
238 if ($progname eq "tree_status.pl" && !-d "CVS" && !-d ".git") {
239 die("a tree status can only be determined in an source code control system checkout\n");
242 chomp(my $cwd = `pwd`);
247 # for get_latest_mtime and get_tag you need to be in srcdir
253 my $mtime = get_latest_mtime()
254 if (!defined($ENV{LUSTRE_VERS}));
256 if ($progname eq "version_tag.pl") {
257 my $linuxdir = get_linuxdir();
258 $linuxdir =~ s/\//\./g;
259 generate_ver($tag, $mtime, $linuxdir);
260 } elsif ($progname eq "tree_status.pl") {
261 print "PRISTINE = $pristine\n";
262 print "MTIME = $mtime\n";