build: Add rpm target
[openafs.git] / build-tools / make-release
index 12e818b..7ef82e7 100755 (executable)
@@ -25,9 +25,12 @@ pod2usage(1) if $help;
 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
 
 my $tagName = shift;
-my $version = shift;
+my $notused = shift;  # Used to be "version".
 
 pod2usage(2) if !defined($tagName);
+if (defined $notused) {
+    warn "Warning: argument '$notused' is ignored.\n";
+}
 
 # Tag the repository
 
@@ -40,20 +43,26 @@ if ($tagPoint) {
         or die "git push failed with : $!";
 }
 
-$version = `git describe --abbrev=4 $tagName`;
+my $version = `git describe --abbrev=4 $tagName`;
 chomp $version;
-$version=~s/openafs-[^-]*-//;
-$version=~s/_/./g;
+if (!$version) {
+    die "Failed to describe $tagName.\n";
+}
+my $suffix = $version;
+$suffix =~ s/openafs-[^-]*-//;
+$suffix =~ s/_/./g;
+my $name = "openafs-$suffix";
 
 # Grab the tagged code into a temporary directory
 
-my $name = "openafs-".$version;
-
 my $tempDir = File::Temp::tempdir();
 system ("git archive --format=tar --prefix=$name/ $tagName ".
         " | tar -C $tempDir -x") == 0
     or die "Git archive failed with: $?";
 
+# Make the output path, if not already present.
+File::Path::mkpath($outDir);
+
 # Construct the ChangeLog
 if ($last) {
     system("git log $last..$tagName > $outDir/ChangeLog");
@@ -62,7 +71,10 @@ if ($last) {
 }
 
 # Describe the tree
-system("git describe --abbrev=4 $tagName > $tempDir/$name/.version");
+open(my $fh, ">", "$tempDir/$name/.version") or
+    die "Failed to open $tempDir/$name/.version: $!\n";
+print $fh "$version\n";
+close($fh);
 
 # Run regen.sh to create the rest of the tree
 system ("cd $tempDir/$name && ./regen.sh") == 0
@@ -132,7 +144,7 @@ make-release - Make an OpenAFS release from git
 
 =head1 SYNOPSIS
 
-make-release [options] <tag> [<version>]
+make-release [options] <tag>
 
  Options:
     --help               brief help message
@@ -164,7 +176,7 @@ changes between I<object> and the current tag
 =item B<--dir> I<directory>
 
 Instead of generating all of the output in the current directory, place it
-in <directory>, which must already exist.
+in <directory>, which is created if it does not already exist.
 
 =item B<--tagpoint> I<commit|branch>