12 # Build an SRPM for OpenAFS, given a src and doc tarball, release notes,
18 my $changelog = shift;
20 if (!$srcball && !$docball) {
21 printf "Usage: <version> <src.tar.gz> <doc.tar.gz> [<relnotes> [<changelog>]]\n";
26 die "Unable to open $srcball\n";
29 my $tmpdir = File::Temp::tempdir(CLEANUP => 1);
31 system("tar -C $tmpdir -xvjf $srcball \*/configure.in ".
32 "\*/src/packaging/RedHat > /dev/null")==0
33 or die "Unable to unpack src tar ball\n";
35 my $dirh = IO::Dir->new($tmpdir);
37 while (defined($vdir = $dirh->read) && $vdir=~/^\./) {};
39 die "Unable to find unpacked source code\n" if !$vdir;
41 my $srcdir = $tmpdir."/".$vdir;
43 # Work out which version we're dealing with from the configure.in file
45 my $fh = new IO::File $srcdir."/configure.in"
46 or die "Unable to find unpacked configure.in file";
48 if (/AM_INIT_AUTOMAKE\(openafs,(.*)\)/) {
57 print "Building version $version\n";
58 File::Path::mkpath([ $tmpdir."/rpmdir/SPECS",
59 $tmpdir."/rpmdir/SRPMS",
60 $tmpdir."/rpmdir/SOURCES"], 0, 0755);
62 File::Copy::copy($srcball,
63 $tmpdir."/rpmdir/SOURCES/openafs-$version-src.tar.bz2")
64 or die "Unable to copy $srcball into position\n";
66 File::Copy::copy($docball,
67 $tmpdir."/rpmdir/SOURCES/openafs-$version-doc.tar.bz2")
68 or die "Unable to copy $docball into position\n";
71 # Populate it with all the stuff in the packaging directory, except the
73 my $pkgdirh = IO::Dir->new($srcdir."/src/packaging/RedHat")
74 or die "Unable to find RedHat packaging directory\n";
76 while (defined($file = $pkgdirh->read)) {
77 if (-f $srcdir."/src/packaging/RedHat/".$file) {
78 next if $file eq "openafs.spec.in";
80 print "Copying $file into place\n";
81 File::Copy::copy($srcdir."/src/packaging/RedHat/".$file,
82 $tmpdir."/rpmdir/SOURCES/".$file);
87 # Some files need particular modes.
88 chmod 0755, $tmpdir."/rpmdir/SOURCES/openafs-kernel-version.sh";
89 chmod 0755, $tmpdir."/rpmdir/SOURCES/openafs-kvers-is.sh";
91 # Create the specfile. Use sed for this, cos its easier
92 system("cat ".$srcdir."/src/packaging/RedHat/openafs.spec.in | ".
93 "sed -e 's/\@VERSION\@/$version/g' ".
94 " -e 's/\%define afsvers.*/%define afsvers $version/g' ".
95 " -e 's/\%define pkgvers.*/%define pkgvers $version/g' > ".
96 $tmpdir."/rpmdir/SPECS/openafs.spec") == 0
97 or die "sed failed : $!\n";
100 File::Copy::copy($relnotes,
101 $tmpdir."/rpmdir/SOURCES/RELNOTES-$version")
102 or die "Unable to copy $relnotes into position\n";
104 print "WARNING: No release notes provided. Using empty file\n";
105 system("touch $tmpdir/rpmdir/SOURCES/RELNOTES-$version");
109 File::Copy::copy($changelog,
110 $tmpdir."/rpmdir/SOURCES/ChangeLog")
111 or die "Unable to copy $changelog into position\n";
113 print "WARNING: No changelog provided. Using empty file\n";
114 system("touch $tmpdir/rpmdir/SOURCES/ChangeLog");
118 system("rpmbuild -bs --define \"_topdir $tmpdir/rpmdir\" ".
119 "$tmpdir/rpmdir/SPECS/openafs.spec > /dev/null") == 0
120 or die "rpmbuild failed : $!\n";
122 # Copy it out to somewhere useful
123 File::Copy::copy("$tmpdir/rpmdir/SRPMS/openafs-$version-1.1.src.rpm",
124 "openafs-$version-1.1.src.rpm")
125 or die "Unable to copy output RPM : $!\n";
127 print "SRPM is openafs-$version-1.1.src.rpm\n";