diff options
Diffstat (limited to 'tools/build_perl_modules')
-rwxr-xr-x | tools/build_perl_modules | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/build_perl_modules b/tools/build_perl_modules new file mode 100755 index 00000000..fb471459 --- /dev/null +++ b/tools/build_perl_modules | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # SYNTAX: | ||
3 | # build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] tarball_dir | ||
4 | # | ||
5 | # DESCRIPTION: | ||
6 | # Installs perl modules found in tarball_dir | ||
7 | # Expects a file called install_order, containing one line per distribution name | ||
8 | # Will take action against each distribution in turn | ||
9 | # -d is a necessary destination directory for the perl mods | ||
10 | # If -c is set, will remove the module build directories and exit | ||
11 | # If -m is set, will run perl Makefile.PL and make | ||
12 | # If -t is set, will run make test | ||
13 | # If -i is set, will run make install | ||
14 | # Options are discrete. This is because an overall ./configure, make, make test, make install | ||
15 | # are run in different invocations. Obviously, you can't run a -t without a -m, but there's no | ||
16 | # checking here for that | ||
17 | |||
18 | # Can only use base modules | ||
19 | use warnings; | ||
20 | use strict; | ||
21 | use Config; | ||
22 | use Getopt::Std; | ||
23 | use Cwd; | ||
24 | use File::Path; | ||
25 | |||
26 | my $opts = {}; | ||
27 | getopts('d:cmti', $opts) || die "Invalid options"; | ||
28 | my $moddir = shift @ARGV or die "Must specify a directory where tarballs exist"; | ||
29 | |||
30 | my $destdir = $opts->{d}; | ||
31 | die "Must set a destination directory" unless $destdir; | ||
32 | |||
33 | chdir $moddir or die "Cannot change to $moddir"; | ||
34 | open F, "install_order" or die "Cannot open install_order file"; | ||
35 | my @files = grep { ! /^#/ && chop } <F>; | ||
36 | close F; | ||
37 | |||
38 | my @tarballs; | ||
39 | foreach my $f (@files) { | ||
40 | # Needs to be better. Also, what if there are two with same name? | ||
41 | my $tarball; | ||
42 | eval '$tarball = <'."$f".'*.tar.gz>'; | ||
43 | die unless ($tarball); | ||
44 | print "Got $f, with file: $tarball",$/; | ||
45 | push @tarballs, $tarball; | ||
46 | (my $dir = $tarball) =~ s/\.tar.gz//; | ||
47 | # Need to do cleaning before doing each module in turn | ||
48 | if ($opts->{c}) { | ||
49 | print "Cleaning $dir",$/; | ||
50 | rmtree($dir); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | if ($opts->{c}) { | ||
55 | print "Finished cleaning",$/; | ||
56 | exit; | ||
57 | } | ||
58 | |||
59 | my $topdir = cwd(); | ||
60 | foreach my $tarball (@tarballs) { | ||
61 | (my $dir = $tarball) =~ s/\.tar.gz//; | ||
62 | if ($opts->{m}) { | ||
63 | # Don't compile if already done - this is because of invocating this | ||
64 | # script at different stages | ||
65 | unless (-e $dir) { | ||
66 | system("gunzip -c $tarball | tar -xf -") == 0 or die "Cannot extract $tarball"; | ||
67 | chdir $dir or die "Can't chdir into $dir"; | ||
68 | system("perl Makefile.PL PREFIX=$destdir INSTALLDIRS=site LIB=$destdir/lib") == 0 or die "Can't run perl Makefile.PL"; | ||
69 | system("make") == 0 or die "Can't run make"; | ||
70 | chdir $topdir or die "Can't chdir to top";; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | chdir $dir or die "Can't chdir into $dir"; | ||
75 | |||
76 | # Need to add this so this module is found for subsequent ones | ||
77 | $ENV{PERL5LIB}="$topdir/$dir/blib/lib:$ENV{PERL5LIB}"; | ||
78 | |||
79 | if ($opts->{t}) { | ||
80 | system("make test") == 0 or die "Can't run make test failed"; | ||
81 | } | ||
82 | if ($opts->{i}) { | ||
83 | system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install"; | ||
84 | } | ||
85 | chdir $topdir or die "Can't go back to $topdir"; | ||
86 | } | ||