1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#!/usr/bin/perl -w
# Build an RPM. Usage:
# rpmbuild.pl [lib path]
use strict;
use warnings;
use File::Copy;
use Template;
use lib "./lib";
use RiveScript; # So we get its version no.
use RiveScript::WD;
# Use the pwd command to get the current working directory.
my $pwd = `pwd`;
chomp($pwd);
# Build number = today's date.
my @time = localtime();
my $build = join("",
sprintf("%04d", $time[5] + 1900),
sprintf("%02d", $time[4] + 1),
sprintf("%02d", $time[3]),
);
print "Preparing build root...\n";
makedir("./build", "./build/usr");
command("perl Makefile.PL PREFIX=build/usr");
command("make");
command("make test");
command("make install");
print "Copying utils from bin/...\n";
makedir("./build/usr/bin");
copy("./bin/rivescript", "./build/usr/bin/");
print "\n";
print "Preparing Template Toolkit...\n";
my $tt = Template->new ({
RELATIVE => 1,
PRE_CHOMP => 0,
POST_CHOMP => 0,
});
my $vars = {
version => $RiveScript::VERSION,
build => $build,
wd_version => $RiveScript::WD::VERSION,
files => [],
};
print "Making file list from buildroot...\n";
my @flist = &crawl("./build");
foreach my $file (@flist) {
$file =~ s/^\.\/build//i;
if ($file =~ /rpmbuild\.pl$/ || $file =~ /perllocal\.pod$/ || $file =~ /\.packlist$/) {
unlink("./build/$file");
next;
}
my $attr = "0644";
if (-d $file || $file =~ /^\/usr\/bin/i) {
$attr = "0755";
}
push (@{$vars->{files}}, "%attr($attr,root,root) $file");
}
print "Creating RPM spec file...\n";
my $output;
eval {
$tt->process("./perl-RiveScript.spec.tt", $vars, \$output) or die $@;
};
if ($@) {
die $@;
}
open (SPEC, ">perl-RiveScript.spec");
print SPEC $output;
close (SPEC);
print "Building RPM...\n";
command("rpmbuild --target=noarch --buildroot=$pwd/build -ba perl-RiveScript.spec");
print "Cleaning up...\n";
command("make clean");
command("rm -rf build/");
unlink("./perl-RiveScript.spec");
sub command {
my $cmd = shift;
print "\$ $cmd\n";
system($cmd);
}
sub crawl {
my $dir = shift;
my @files = ();
opendir (DIR, $dir);
foreach my $file (readdir(DIR)) {
next if $file eq ".";
next if $file eq "..";
if (-d "$dir/$file") {
push (@files, &crawl("$dir/$file"));
}
else {
push (@files, "$dir/$file");
}
}
return @files;
}
sub makedir {
my @dirs = @_;
foreach my $d (@dirs) {
print "mkdir $d\n";
mkdir($d) unless -d $d;
}
}
sub prompt {
my $q = shift;
print "$q ";
chomp (my $answer = <STDIN>);
return $answer;
}
|