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;
148 if (!$config->open("autoMakefile")) {
149 die "Run ./configure first\n";
151 while (defined($line = <$config>)) {
153 if ($line =~ /LINUX :?= (.*)/) {
159 my $ver = new IO::File;
160 if (!$ver->open("$dir/include/linux/utsrelease.h")) {
161 if (!$ver->open("$dir/include/linux/version.h")) {
162 die "Run make dep on $dir\n";
165 while(defined($line = <$ver>)) {
166 $line =~ /\#define UTS_RELEASE "(.*)"/;
182 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
186 my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday,
192 sub generate_ver($$$)
196 my $linuxdir = shift;
198 #print "localtime: " . localtime($mtime) . "\n";
200 my $show_last = mtime2date($mtime);
202 print "#define BUILD_VERSION \"";
204 my $lustre_vers = $ENV{LUSTRE_VERS};
207 print "$tag-$lustre_vers\"\n";
208 # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these
209 # lines. maybe we only want to print -CHANGED when something is changed
210 # and print nothing when it's pristine
211 } elsif ($pristine) {
212 print "$tag-$show_last-PRISTINE-$linuxdir-$kernver\"\n";
214 print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n";
219 $progname =~ s/.*\///;
221 if ($progname eq "tree_status.pl" && !-d "CVS" && !-d ".git") {
222 die("a tree status can only be determined in an source code control system checkout\n");
225 chomp(my $cwd = `pwd`);
230 # for get_latest_mtime and get_tag you need to be in srcdir
236 my $mtime = get_latest_mtime();
238 if ($progname eq "version_tag.pl") {
239 my $linuxdir = get_linuxdir();
240 $linuxdir =~ s/\//\./g;
241 generate_ver($tag, $mtime, $linuxdir);
242 } elsif ($progname eq "tree_status.pl") {
243 print "PRISTINE = $pristine\n";
244 print "MTIME = $mtime\n";