summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perlmods/Makefile.am2
-rw-r--r--perlmods/install_order1
-rwxr-xr-xtools/build_perl_modules312
3 files changed, 251 insertions, 64 deletions
diff --git a/perlmods/Makefile.am b/perlmods/Makefile.am
index 3f479f3..1495900 100644
--- a/perlmods/Makefile.am
+++ b/perlmods/Makefile.am
@@ -1,7 +1,7 @@
1perlmoduledir = $(exec_prefix)/perl 1perlmoduledir = $(exec_prefix)/perl
2 2
3all-local: 3all-local:
4 $(top_srcdir)/tools/build_perl_modules -d $(perlmoduledir) -m . 4 $(top_srcdir)/tools/build_perl_modules -d $(perlmoduledir) -em .
5 5
6install-exec-local: 6install-exec-local:
7 $(top_srcdir)/tools/build_perl_modules -d $(perlmoduledir) -i . 7 $(top_srcdir)/tools/build_perl_modules -d $(perlmoduledir) -i .
diff --git a/perlmods/install_order b/perlmods/install_order
index d4056f9..7f07348 100644
--- a/perlmods/install_order
+++ b/perlmods/install_order
@@ -1,4 +1,5 @@
1# Modules installed in this order 1# Modules installed in this order
2default:
2Test-Simple 3Test-Simple
3Perl-OSType 4Perl-OSType
4parent 5parent
diff --git a/tools/build_perl_modules b/tools/build_perl_modules
index af82db9..57d6e61 100755
--- a/tools/build_perl_modules
+++ b/tools/build_perl_modules
@@ -1,6 +1,6 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2# SYNTAX: 2# SYNTAX:
3# build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] tarball_dir 3# build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] [-s <section>] tarball_dir
4# 4#
5# DESCRIPTION: 5# DESCRIPTION:
6# Installs perl modules found in tarball_dir 6# Installs perl modules found in tarball_dir
@@ -8,9 +8,12 @@
8# Will take action against each distribution in turn 8# Will take action against each distribution in turn
9# -d is a necessary destination directory for the perl mods 9# -d is a necessary destination directory for the perl mods
10# If -c is set, will remove the module build directories and exit 10# If -c is set, will remove the module build directories and exit
11# If -e is set, will extract module
11# If -m is set, will run perl Makefile.PL and make 12# If -m is set, will run perl Makefile.PL and make
12# If -t is set, will run make test 13# If -t is set, will run make test
13# If -i is set, will run make install 14# If -i is set, will run make install
15# If -s <section> specified will only work on that section in the
16# install_order file - defaults to first section only
14# Options are discrete. This is because an overall ./configure, make, make test, make install 17# 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 18# are run in different invocations. Obviously, you can't run a -t without a -m, but there's no
16# checking here for that 19# checking here for that
@@ -23,81 +26,264 @@ use Getopt::Std;
23use Cwd; 26use Cwd;
24use File::Path; 27use File::Path;
25 28
29# remove host site_lib directories to ensure this is a 'full & clean' build of deps
30BEGIN: {
31 my @user_libs = split( /:/, $ENV{PERL5LIB} || "" );
32 chomp(@user_libs);
33
34 # clear out old PERL5LIB to avoid confusion with anything preinstalled
35 foreach my $lib (@INC) {
36 next if $lib eq ".";
37 foreach my $var (qw/ sitelib_stem sitelib sitearch sitearchexp /) {
38 foreach my $user_lib (@user_libs) {
39 $lib = '' if ( $lib =~ m/$user_lib/ );
40 }
41 $lib = ''
42 if ( ( $Config{$var} && $lib =~ m/^$Config{$var}/ )
43 || $lib =~ m/site_perl/ );
44 }
45 }
46}
47
48my $file_regexp = '(\.pm)?-v?([\d_]+\.?)*\.(?:tgz|tar\.gz)$';
49
50my $have_yaml = 0;
51my $have_module_build = 0;
52
26my $opts = {}; 53my $opts = {};
27getopts('d:cmti', $opts) || die "Invalid options"; 54getopts( 'd:cemtis:', $opts ) || die "Invalid options";
28my $moddir = shift @ARGV or die "Must specify a directory where tarballs exist"; 55my $moddir = shift @ARGV
56 or die "Must specify a directory where tarballs exist";
57
58my $prefix = $opts->{d};
59die "Must set a destination directory" unless $prefix;
29 60
30my $destdir = $opts->{d}; 61my $destdir = '';
31die "Must set a destination directory" unless $destdir; 62my $mm_destdir = '';
63my $mb_destdir = '';
64if ( $ENV{DESTDIR} ) {
65 $destdir = $ENV{DESTDIR};
66 $mm_destdir = 'DESTDIR=' . $destdir;
67 $mb_destdir = '--destdir ' . $destdir;
68}
32 69
33chdir $moddir or die "Cannot change to $moddir"; 70chdir $moddir or die "Cannot change to $moddir";
34open F, "install_order" or die "Cannot open install_order file"; 71open F, "install_order" or die "Cannot open install_order file";
35my @files = grep { ! /^#/ && chop } <F>; 72my @files = grep { !/^#/ && chop } <F>;
36close F; 73close F;
37 74
75# Remove linux only perl module from Solaris systems
76if ( $^O eq "solaris" ) {
77 @files = grep { !/Sys-Statistics-Linux/ } @files;
78}
79
80my @filelist;
81opendir( DIR, "." );
82foreach my $found ( readdir(DIR) ) {
83 push( @filelist, $found )
84 if ( -f $found && $found =~ m/\.(?:tgz|tar\.gz)$/ );
85}
86close(DIR);
87
88my $tag = $opts->{s} || "default";
89my $in_section = 0;
90
38my @tarballs; 91my @tarballs;
39foreach my $f (@files) { 92foreach my $f (@files) {
40 # Needs to be better. Also, what if there are two with same name? 93 next
41 my $tarball; 94 if ( !$f || $f =~ m/^\s+$/ || $f =~ m/^\s*#/ ); # ignore all blank lines
42 eval '$tarball = <'."$f".'*.tar.gz>'; 95 $f =~ s/\s+//; # remove all whitespaces from line
43 die unless ($tarball); 96 $f =~ s/\s+#.*//; # remove all comments from the line
44 print "Got $f, with file: $tarball",$/; 97
45 push @tarballs, $tarball; 98 if ( $f =~ m/^(\w+):$/ ) {
46 (my $dir = $tarball) =~ s/\.tar.gz//; 99 if ( $tag && $1 ne $tag && $tag ne "all" ) {
47 # Need to do cleaning before doing each module in turn 100 $in_section = 0;
48 if ($opts->{c}) { 101 next;
49 print "Cleaning $dir",$/; 102 }
50 rmtree($dir); 103 $in_section = 1;
51 } 104 $tag = $1 if ( !$tag );
105 last if ( $1 ne $tag && $tag ne "all" );
106 next;
107 }
108
109 next if ( !$in_section );
110
111 # sort fully qualified names
112 #$f =~ s/(\.pm)?-v?(\d+\.?)*\.(?:tgz|tar\.gz)//;
113 #warn("b4 f=$f");
114 $f =~ s/$file_regexp//;
115
116 # Needs to be better. Also, what if there are two with same name?
117 #warn("f=$f");
118 my $tarball = ( grep( /^$f$file_regexp/, @filelist ) )[0];
119
120 #warn("got f=$f tarball=$tarball");
121 #eval '$tarball = <' . "$f" . '[-pmv0-9.]*.tar.gz>';
122 die("Couldn't find tarball for $f in $moddir\n")
123 unless ( $tarball && -f $tarball );
124 push @tarballs, $tarball;
125 ( my $dir = $tarball ) =~ s/\.(?:tgz|tar.gz)$//;
126
127 # Need to do cleaning before doing each module in turn
128 if ( $opts->{c} ) {
129 print "Cleaning $dir", $/;
130 rmtree($dir) if ($dir);
131 }
52} 132}
53 133
54if ($opts->{c}) { 134if ( $opts->{c} ) {
55 print "Finished cleaning",$/; 135 print "Finished cleaning", $/;
56 exit; 136 exit;
57} 137}
58 138
139my $libs = "$destdir/$prefix/lib:$destdir/$prefix/lib/$Config{archname}";
140
59my $topdir = cwd(); 141my $topdir = cwd();
142
143# set an initial value if there isnt one already
144# Need to use PERL5LIB to ensure we get pre-installed mods from earlier
145# tags in the install_order file
146$ENV{PERL5LIB} ||= q{};
147
148# Set Module::AutoInstall to ignore CPAN, to avoid trying to pull dependencies in
149$ENV{PERL_AUTOINSTALL} = "--skipdeps";
150
151# keep a record of how many times a module build is done. This is so they may
152# be built a second time to include optional prereq's that couldnt
153# previously be built due to circular dependancies
154my %built_modules;
60foreach my $tarball (@tarballs) { 155foreach my $tarball (@tarballs) {
61 (my $dir = $tarball) =~ s/\.tar.gz//; 156 ( my $dir = $tarball ) =~ s/\.(?:tgz|tar.gz)$//;
62 if ($opts->{m}) { 157
63 # Don't compile if already done - this is because of invocating this 158 die if ( $dir eq "exit" );
64 # script at different stages 159
65 unless (-e $dir) { 160 if ( $opts->{e} ) {
66 system("gunzip -c $tarball | tar -xf -") == 0 or die "Cannot extract $tarball"; 161 unless ( -e $dir ) {
67 chdir $dir or die "Can't chdir into $dir"; 162 print 'Extracting ', $tarball, $/;
68 if (-e "Makefile.PL") { 163 system("gunzip -c $tarball | tar -xf -") == 0
69 system("perl Makefile.PL PREFIX=$destdir INSTALLDIRS=site LIB=$destdir/lib") == 0 164 or die "Cannot extract $tarball";
70 or die "Can't run perl Makefile.PL"; 165 }
71 system("make") == 0 or die "Can't run make"; 166 next unless ( $opts->{m} || $opts->{t} || $opts->{i} );
72 } else { 167 }
73 system("perl Build.PL --prefix $destdir --installdirs site --install_path lib=$destdir/lib") == 0 168
74 or die "Can't run perl Build.PL"; 169 # Need to add this so all modules is are for subsequent ones
75 system("./Build") == 0 or die "Can't run ./Build"; 170 # Done here to partial previous builds can be continued
76 } 171 $ENV{PERL5LIB} = "$topdir/$dir/blib/arch:" . $ENV{PERL5LIB}; # Required for IO-Compress, I think
77 chdir $topdir or die "Can't chdir to top";; 172 $ENV{PERL5LIB} = "$topdir/$dir/blib/lib:" . $ENV{PERL5LIB};
78 } 173
79 } 174 # PathTools does something weird where it removes blib from @INC. We manually force ExtUtils::MakeMaker to be included
80 175 $ENV{PERL5LIB} = "$topdir/$dir/lib:" . $ENV{PERL5LIB} if ($dir =~/ExtUtils-MakeMaker/);
81 chdir $dir or die "Can't chdir into $dir"; 176
82 177 # warn("PERL5LIB=$ENV{PERL5LIB}");
83 # Need to add this so this module is found for subsequent ones 178
84 my @dirs = split(":", $ENV{PERL5LIB} || ""); 179 if ( !$have_yaml ) {
85 unshift @dirs, "$topdir/$dir/blib/lib"; 180 $have_yaml = 0;
86 $ENV{PERL5LIB}=join(":", @dirs); 181 }
87 182
88 if ($opts->{t}) { 183 if ( !$have_module_build ) {
89 if (-e "Makefile") { 184 $have_module_build = check_for_module('Module::Build');
90 system("make test") == 0 or die "Can't run make test failed"; 185 }
91 } else { 186
92 system("./Build test") == 0 or die "./Build test failed"; 187 if ( $opts->{m} ) {
93 } 188
94 } 189 # Don't compile if already done - this is because of invocating this
95 if ($opts->{i}) { 190 # script at different stages
96 if (-e "Makefile") { 191 if ( $built_modules{$dir} || !-f "$dir/Makefile" && !-f "$dir/Build" ) {
97 system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install"; 192 $built_modules{$dir}++;
98 } else { 193 my @missing;
99 system("./Build install") == 0 or die "Can't run ./Build install"; 194 chdir "$topdir/$dir" or die "Can't chdir into $dir";
100 } 195 warn("\nWorking in: $topdir/$dir\n\n");
101 } 196
102 chdir $topdir or die "Can't go back to $topdir"; 197 # Another horrible hack. XML-Parser uses special Makefile variables, so we add these on here for Solaris only
198 my $extra_args = "";
199 if ( $^O eq "solaris" && $dir =~ /^XML-Parser-/ ) {
200 $extra_args = "EXPATLIBPATH=/usr/sfw/lib EXPATINCPATH=/usr/sfw/share/src/expat/lib/";
201 }
202
203 #warn("PERL5LIB=$ENV{PERL5LIB}\n");
204
205 if ( -f "Build.PL" && $have_module_build ) {
206 warn("Using Build.PL\n");
207 }
208 elsif ( -f 'Makefile.PL' ) {
209 warn("Using Makefile.PL\n");
210
211 # Horribly hacky - remove xdefine if this is Time-HiRes
212 # because the subsequent perl Makefile.PL will fail
213 if ( $dir =~ /Time-HiRes/ ) {
214 unlink "xdefine";
215 }
216 }
217 else {
218 die "No Makefile.PL nor Build.PL found";
219 }
220
221 my $command;
222 if ( -f "Build.PL" && $have_module_build ) {
223 open( CMD, "|-", "perl Build.PL $mb_destdir --install_base=$prefix --install_path lib=$prefix/lib --install_path arch=$prefix/lib/$Config{archname} --install_path bin=$prefix/bin --install_path script=$prefix/bin --install_path bindoc=$prefix/man/man1 --install_path libdoc=$prefix/man/man3" ) || die "Can't run perl Build.PL";
224 $command = "./Build";
225 }
226 elsif ( -f 'Makefile.PL' ) {
227 open( CMD, "|-", "perl Makefile.PL $mm_destdir INSTALL_BASE=$prefix INSTALLDIRS=site INSTALLSITELIB=$prefix/lib INSTALLSITEARCH=$prefix/lib/$Config{archname} $extra_args" ) || die "Can't run perl Makefile.PL";
228 $command = "make";
229 }
230 else {
231 die "No Makefile.PL nor Build.PL found";
232 }
233 close(CMD);
234 system($command) == 0
235 or die "Can't run $command. Please\n\trm -rf $topdir/$dir\nto remake from this point)";
236
237 chdir $topdir or die "Can't chdir to top";
238 }
239 }
240
241 chdir $dir or die "Can't chdir into $dir";
242
243 if ( $opts->{t} ) {
244 warn("****** Testing $dir ****** \n");
245 if ( -f "Build.PL" ) {
246 system("./Build test") == 0
247 or die "'Build test' failed in $dir: $!\n";
248 }
249 else {
250 system("make test") == 0
251 or die "'make test' failed in $dir: $!\n";
252 }
253 }
254 if ( $opts->{i} && !-f 'installed' ) {
255
256 # Need to set this so that XML::SAX will install ParserDetails.ini by finding the right XML::SAX copy
257 # Also makes sense to do this anyway, as I guess CPAN must be doing this for it to usually work
258 my $saved_PERL5LIB = $ENV{PERL5LIB};
259 $ENV{PERL5LIB} = "$ENV{DESTDIR}/$prefix/lib:$saved_PERL5LIB";
260 if ( -f "Build" ) {
261 system("./Build install") == 0
262 or die "Can't run make install: $!\n";
263 }
264 else {
265 system("make install") == 0
266 or die "Can't run make install: $!\n";
267 }
268 $ENV{PERL5LIB} = $saved_PERL5LIB;
269 open my $install_flag_file, '>', 'installed'
270 or die 'Unable to touch "installed": ', $!, $/;
271 close $install_flag_file
272 or die 'Unable to close "installed": ', $!, $/;
273 }
274 chdir $topdir or die "Can't go back to $topdir";
275}
276
277sub check_for_module {
278 my ($module) = @_;
279
280 warn 'Checking if ', $module, ' is available yet...', $/;
281 if ( system("$^X -M$module -e 0 2>/dev/null") == 0 ) {
282 warn '... yes!', $/;
283 return 1;
284 }
285
286 warn '... no!', $/;
287 return 0;
288
103} 289}