diff --git a/Makefile.in b/Makefile.in index c647888f9b..72014bcb1f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -783,8 +783,10 @@ clean2: dist: ./build-tools/make-release --dir=packages HEAD -srpm: - (cd packages && ../src/packaging/RedHat/makesrpm.pl *-src.tar.bz2 *-doc.tar.bz2) +srpm: dist + ./src/packaging/RedHat/makesrpm.pl --dir=packages \ + packages/openafs-*-src.tar.bz2 \ + packages/openafs-*-doc.tar.bz2 dox: if test "x$(DOXYGEN)" != "x"; then \ diff --git a/src/packaging/RedHat/makesrpm.pl b/src/packaging/RedHat/makesrpm.pl index 7744d5dc24..7d6e1a96f9 100755 --- a/src/packaging/RedHat/makesrpm.pl +++ b/src/packaging/RedHat/makesrpm.pl @@ -3,24 +3,39 @@ use strict; use warnings; +use Getopt::Long; +use Pod::Usage; use IO::Dir; use IO::File; use File::Path; use File::Copy; use File::Temp; +use File::Basename; +use File::Spec; # Build an SRPM for OpenAFS, given a src and doc tarball, release notes, # and ChangeLog. +my $help = 0; +my $man = 0; +my $dir = "."; + +GetOptions( + "help|?" => \$help, + "man" => \$man, + "dir=s" => \$dir, +) or pod2usage(-exitval => 1, -verbose => 1); +pod2usage(-exitval => 0, -verbose => 1) if $help; +pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1) if $man; + my $srcball = shift; my $docball = shift; my $relnotes = shift; my $changelog = shift; my $cellservdb = shift; -if (!$srcball && !$docball) { - printf "Usage: makesrpm [ [ []]]\n"; - exit(1); +if (!defined($srcball) || !defined($docball)) { + pod2usage(-exitval => 1, -verbose => 1); } if (! -f $srcball) { @@ -77,15 +92,12 @@ if ($afsversion=~m/(.*)-([0-9]+)-(g[a-f0-9]+)$/) { $linuxrel.=".$2.$3"; } -print "Linux release is $linuxrel\n"; -print "Linux version is $linuxver\n"; +# Avoid illegal characters in RPM package version and release strings. +$linuxver =~ s/-/_/g; +$linuxrel =~ s/-/_/g; -# Figure out a major, minor and release so that we know which version we're -# building, and therefore what the srpm is going to be called -$linuxver=~/([0-9]+)\.([0-9]+)\.([0-9]+)/; -my $major = $1; -my $minor = $2; -my $patchlevel = $3; +print "Package version is $linuxver\n"; +print "Package release is $linuxrel\n"; # Build the RPM root @@ -165,18 +177,49 @@ system("rpmbuild -bs --nodeps --define \"dist %undefined\" ". or die "rpmbuild failed : $!\n"; # Copy it out to somewhere useful -if (!defined($major) || $major > 1 || ($major == 1 && $minor >= 6)) { - File::Copy::copy("$tmpdir/rpmdir/SRPMS/openafs-$linuxver-$linuxrel.src.rpm", - "openafs-$linuxver-$linuxrel.src.rpm") - or die "Unable to copy output RPM : $!\n"; - - print "SRPM is openafs-$linuxver-$linuxrel.src.rpm\n"; -} else { - File::Copy::copy("$tmpdir/rpmdir/SRPMS/openafs-$linuxver-1.$linuxrel.src.rpm", - "openafs-$linuxver-1.$linuxrel.src.rpm") - or die "Unable to copy output RPM : $!\n"; - - print "SRPM is openafs-$linuxver-1.$linuxrel.src.rpm\n"; +my @srpms = glob("$tmpdir/rpmdir/SRPMS/*.src.rpm"); +if (scalar(@srpms) != 1) { + die "Generated SRPM file not found.\n"; } +my $filename = File::Basename::fileparse($srpms[0]); +my $srpm = File::Spec->rel2abs("$dir/$filename"); +File::Path::make_path($dir); +File::Copy::copy($srpms[0], $srpm) + or die "Failed to copy '$srpms[0]' to '$srpm': $!\n"; +print "SRPM is $srpm\n"; +__END__ +=head1 NAME + +makesrpm.pl - Build the SRPM for OpenAFS from source distibution files + +=head1 SYNOPSIS + +makesrpm.pl [options] [ [ []]] + +=head1 DESCRIPTION + +Build the SRPM for OpenAFS from source distibution files. Generate empty RELNOTES +and ChangeLog files if not provided. Download the CellServDB file from +grand.central.org if one is not provided. + +=head1 OPTIONS + +=over 4 + +=item B<--help> + +Print help message and exit. + +=item B<--man> + +Print full man page and exit. + +=item B<--dir> I + +Place the generated SRPM file in I instead of the current directory. + +=back + +=cut