Whamcloud - gitweb
RPM build fixes.
[fs/lustre-release.git] / lustre / scripts / version_tag.pl
index a92fef4..334d2d6 100644 (file)
@@ -9,13 +9,27 @@ use Time::Local;
 my $pristine = 1;
 my $kernver;
 
+# Use the CVS tag first otherwise use the portals version
 sub get_tag()
 {
     my $tag;
+    my $line;
 
     my $tagfile = new IO::File;
     if (!$tagfile->open("CVS/Tag")) {
-        return "HEAD";
+        my $verfile = new IO::File;
+        if (!$verfile->open("portals/include/config.h")) {
+          return "UNKNOWN";
+        }
+        while(defined($line = <$verfile>)) {
+            $line =~ /\#define VERSION "(.*)"/;
+            if ($1) {
+                $tag = $1;
+                last;
+            }
+        }
+        $verfile->close();
+        return $tag
     } else {
         my $tmp = <$tagfile>;
         $tagfile->close();
@@ -59,6 +73,9 @@ sub get_latest_mtime()
             $cur_dir =~ s/\/CVS\/Entries$//;
             my @statbuf = stat("$cur_dir/$file");
             my $mtime = $statbuf[9];
+            if (!defined($mtime)) {
+                next;
+            }
             my $local_date = gmtime($mtime);
             if ($local_date ne $date &&
                 $file ne "lustre.spec.in") {
@@ -100,7 +117,7 @@ sub get_linuxdir()
     }
     while (defined($line = <$config>)) {
         chomp($line);
-        if ($line =~ /LINUX = (.*)/) {
+        if ($line =~ /LINUX :?= (.*)/) {
             $dir = $1;
             last;
         }
@@ -145,13 +162,27 @@ sub generate_ver($$$)
         print "$tag-$show_last-CHANGED-$linuxdir-$kernver\"\n";
     }
 }
+chomp(my $cwd = `pwd`);
+
+# ARGV[0] = srcdir
+# ARGV[1] = builddir
+
+# for get_latest_mtime and get_tag you need to be in srcdir
 
 if ($ARGV[0]) {
     chdir($ARGV[0]);
 }
-my $linuxdir = get_linuxdir();
 my $tag = get_tag();
 my $mtime = get_latest_mtime();
+
+# for get_linuxdir you need to be in builddir 
+
+if ($ARGV[1]) {
+   chdir($cwd);
+   chdir($ARGV[1]);
+}
+my $linuxdir = get_linuxdir();
+
 generate_ver($tag, $mtime, $linuxdir);
 
 exit(0);