3 # build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] [-s <section>] tarball_dir
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 -e is set, will extract module
12 # If -m is set, will run perl Makefile.PL and make
13 # If -t is set, will run make test
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
17 # Options are discrete. This is because an overall ./configure, make, make test, make install
18 # are run in different invocations. Obviously, you can't run a -t without a -m, but there's no
19 # checking here for that
21 # Can only use base modules
29 # remove host site_lib directories to ensure this is a 'full & clean' build of deps
31 my @user_libs = split( /:/, $ENV{PERL5LIB
} || "" );
34 # clear out old PERL5LIB to avoid confusion with anything preinstalled
35 foreach my $lib (@INC) {
37 foreach my $var (qw
/ sitelib_stem sitelib sitearch sitearchexp /) {
38 foreach my $user_lib (@user_libs) {
39 $lib = '' if ( $lib =~ m/$user_lib/ );
42 if ( ( $Config{$var} && $lib =~ m/^$Config{$var}/ )
43 || $lib =~ m/site_perl/ );
48 my $file_regexp = '(\.pm)?-v?([\d_]+\.?)*\.(?:tgz|tar\.gz)$';
51 my $have_module_build = 0;
54 getopts
( 'd:cemtis:', $opts ) || die "Invalid options";
55 my $moddir = shift @ARGV
56 or die "Must specify a directory where tarballs exist";
58 my $prefix = $opts->{d
};
59 die "Must set a destination directory" unless $prefix;
64 if ( $ENV{DESTDIR
} ) {
65 $destdir = $ENV{DESTDIR
};
66 $mm_destdir = 'DESTDIR=' . $destdir;
67 $mb_destdir = '--destdir ' . $destdir;
70 chdir $moddir or die "Cannot change to $moddir";
71 open F
, "install_order" or die "Cannot open install_order file";
72 my @files = grep { !/^#/ && chop } <F
>;
75 # Remove linux only perl module from Solaris systems
76 if ( $^O
eq "solaris" ) {
77 @files = grep { !/Sys-Statistics-Linux/ } @files;
82 foreach my $found ( readdir(DIR
) ) {
83 push( @filelist, $found )
84 if ( -f
$found && $found =~ m/\.(?:tgz|tar\.gz)$/ );
88 my $tag = $opts->{s
} || "default";
92 foreach my $f (@files) {
94 if ( !$f || $f =~ m/^\s+$/ || $f =~ m/^\s*#/ ); # ignore all blank lines
95 $f =~ s/\s+//; # remove all whitespaces from line
96 $f =~ s/\s+#.*//; # remove all comments from the line
98 if ( $f =~ m/^(\w+):$/ ) {
99 if ( $tag && $1 ne $tag && $tag ne "all" ) {
104 $tag = $1 if ( !$tag );
105 last if ( $1 ne $tag && $tag ne "all" );
109 next if ( !$in_section );
111 # sort fully qualified names
112 #$f =~ s/(\.pm)?-v?(\d+\.?)*\.(?:tgz|tar\.gz)//;
114 $f =~ s/$file_regexp//;
116 # Needs to be better. Also, what if there are two with same name?
118 my $tarball = ( grep( /^$f$file_regexp/, @filelist ) )[0];
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)$//;
127 # Need to do cleaning before doing each module in turn
129 print "Cleaning $dir", $/;
130 rmtree
($dir) if ($dir);
135 print "Finished cleaning", $/;
139 my $libs = "$destdir/$prefix/lib:$destdir/$prefix/lib/$Config{archname}";
143 # set an initial value if there isn't 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{};
148 # Set Module::AutoInstall to ignore CPAN, to avoid trying to pull dependencies in
149 $ENV{PERL_AUTOINSTALL
} = "--skipdeps";
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 couldn't
153 # previously be built due to circular dependencies
155 foreach my $tarball (@tarballs) {
156 ( my $dir = $tarball ) =~ s/\.(?:tgz|tar.gz)$//;
158 die if ( $dir eq "exit" );
162 print 'Extracting ', $tarball, $/;
163 system("gunzip -c $tarball | tar -xf -") == 0
164 or die "Cannot extract $tarball";
166 next unless ( $opts->{m
} || $opts->{t
} || $opts->{i
} );
169 # Need to add this so all modules is are for subsequent ones
170 # Done here to partial previous builds can be continued
171 $ENV{PERL5LIB
} = "$topdir/$dir/blib/arch:" . $ENV{PERL5LIB
}; # Required for IO-Compress, I think
172 $ENV{PERL5LIB
} = "$topdir/$dir/blib/lib:" . $ENV{PERL5LIB
};
174 # PathTools does something weird where it removes blib from @INC. We manually force ExtUtils::MakeMaker to be included
175 $ENV{PERL5LIB
} = "$topdir/$dir/lib:" . $ENV{PERL5LIB
} if ($dir =~/ExtUtils-MakeMaker/);
177 # warn("PERL5LIB=$ENV{PERL5LIB}");
183 if ( !$have_module_build ) {
184 $have_module_build = check_for_module
('Module::Build');
189 # Don't compile if already done - this is because of invocating this
190 # script at different stages
191 print "******************** $tarball\n";
192 if ( $built_modules{$dir} || !-f
"$dir/Makefile" && !-f
"$dir/Build" ) {
193 $built_modules{$dir}++;
195 chdir "$topdir/$dir" or die "Can't chdir into $dir";
196 warn("\nWorking in: $topdir/$dir\n\n");
198 # Another horrible hack. XML-Parser uses special Makefile variables, so we add these on here for Solaris only
200 if ( $^O
eq "solaris" && $dir =~ /^XML-Parser-/ ) {
201 $extra_args = "EXPATLIBPATH=/usr/sfw/lib EXPATINCPATH=/usr/sfw/share/src/expat/lib/";
204 #warn("PERL5LIB=$ENV{PERL5LIB}\n");
206 if ( -f
"Build.PL" && $have_module_build ) {
207 warn("Using Build.PL\n");
209 elsif ( -f
'Makefile.PL' ) {
210 warn("Using Makefile.PL\n");
212 # Horribly hacky - remove xdefine if this is Time-HiRes
213 # because the subsequent perl Makefile.PL will fail
214 if ( $dir =~ /Time-HiRes/ ) {
219 die "No Makefile.PL nor Build.PL found";
223 if ( -f
"Build.PL" && $have_module_build ) {
224 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";
225 $command = "./Build";
227 elsif ( -f
'Makefile.PL' ) {
228 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";
232 die "No Makefile.PL nor Build.PL found";
235 system($command) == 0
236 or die "Can't run $command. Please\n\trm -rf $topdir/$dir\nto remake from this point)";
238 chdir $topdir or die "Can't chdir to top";
242 chdir $dir or die "Can't chdir into $dir";
245 warn("****** Testing $dir ****** \n");
246 if ( -f
"Build.PL" ) {
247 system("./Build test") == 0
248 or die "'Build test' failed in $dir: $!\n";
251 system("make test") == 0
252 or die "'make test' failed in $dir: $!\n";
255 if ( $opts->{i
} && !-f
'installed' ) {
257 # Need to set this so that XML::SAX will install ParserDetails.ini by finding the right XML::SAX copy
258 # Also makes sense to do this anyway, as I guess CPAN must be doing this for it to usually work
259 my $saved_PERL5LIB = $ENV{PERL5LIB
};
260 $ENV{PERL5LIB
} = "$destdir/$prefix/lib:$saved_PERL5LIB";
262 system("./Build install") == 0
263 or die "Can't run make install: $!\n";
266 system("make install") == 0
267 or die "Can't run make install: $!\n";
269 $ENV{PERL5LIB
} = $saved_PERL5LIB;
270 open my $install_flag_file, '>', 'installed'
271 or die 'Unable to touch "installed": ', $!, $/;
272 close $install_flag_file
273 or die 'Unable to close "installed": ', $!, $/;
275 chdir $topdir or die "Can't go back to $topdir";
278 sub check_for_module
{
281 warn 'Checking if ', $module, ' is available yet...', $/;
282 if ( system("$^X -M$module -e 0 2>/dev/null") == 0 ) {