2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
10 # $Date: 2006/12/02 09:58:34 +0100 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2006, Marcus Holland-Moritz.
15 # Version 2.x, Copyright (C) 2001, Paul Marquess.
16 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
18 # This program is free software; you can redistribute it and/or
19 # modify it under the same terms as Perl itself.
21 ################################################################################
33 # TODO: - extra arguments to Configure
36 prefix => '/tmp/perl/install/<config>/<perl>',
37 build => '/tmp/perl/build/<config>',
38 source => '/tmp/perl/source',
47 config_args => '-des',
50 config_args => '-des -Dusethreads',
51 masked_versions => [ qr/^5\.00[01234]/ ],
54 config_args => '-des -Duse5005threads',
55 masked_versions => [ qr/^5\.00[012345]|^5.(9|\d\d)/ ],
58 config_args => '-des -Doptimize=-g',
105 GetOptions(\%opt, qw(
117 if (exists $opt{config}) {
118 for my $cfg (@{$opt{config}}) {
119 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
123 $opt{config} = [sort keys %config];
127 /^(perl-?(5\..*))\.tar\.(gz|bz2)$/ or return;
128 $perl{$1} = { version => $2, source => $File::Find::name, compress => $3 };
131 if (exists $opt{perl}) {
132 for my $perl (@{$opt{perl}}) {
134 exists $perl{$p} or $p = "perl$perl";
135 exists $perl{$p} or $p = "perl-$perl";
136 exists $perl{$p} or die "Cannot find perl: $perl\n";
141 @perls = sort keys %perl;
144 if ($opt{'test-archives'}) {
147 -d $test or mkpath($test);
148 chdir $test or die "chdir $test: $!\n";
149 for my $perl (@perls) {
151 my $d = extract_source($perl{$perl});
156 chdir $cwd or die "chdir $cwd: $!\n";
157 print STDERR "cleaning up\n";
164 for my $cfg (@{$opt{config}}) {
165 for my $perl (@perls) {
166 my $config = $config{$cfg};
167 %current = (config => $cfg, perl => $perl, version => $perl{$perl}{version});
169 if (is($config->{masked_versions}, $current{version})) {
170 print STDERR "skipping $perl for configuration $cfg (masked)\n";
174 if (-d expand($opt{prefix}) and !$opt{force}) {
175 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
181 my $build = expand($opt{build});
182 -d $build or mkpath($build);
183 chdir $build or die "chdir $build: $!\n";
185 print STDERR "building $perl with configuration $cfg\n";
186 buildperl($perl, $config);
188 chdir $cwd or die "chdir $cwd: $!\n";
195 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
203 defined $s1 != defined $s2 and return 0;
205 ref $s2 and ($s1, $s2) = ($s2, $s1);
208 if (ref $s1 eq 'ARRAY') {
209 is($_, $s2) and return 1 for @$s1;
220 my($perl, $cfg) = @_;
222 my $d = extract_source($perl{$perl});
223 chdir $d or die "chdir $d: $!\n";
225 patch_source($perl{$perl}{version});
227 build_and_install($perl{$perl});
234 my $what = $opt{'test-archives'} ? 'test' : 'read';
235 print "${what}ing $perl->{source}\n";
239 for my $f (Archive::Tar->list_archive($perl->{source})) {
240 my($t) = $f =~ /^([^\\\/]+)/ or die "ooops, should always match...\n";
241 die "refusing to extract $perl->{source}, as it would not extract to a single directory\n"
242 if defined $target and $target ne $t;
246 if ($opt{'test-archives'} == 0 || $opt{'test-archives'} > 1) {
248 print "removing old build directory $target\n";
252 print "extracting $perl->{source}\n";
254 Archive::Tar->extract_archive($perl->{source})
255 or die "extract failed: " . Archive::Tar->error() . "\n";
257 -d $target or die "oooops, $target not found\n";
268 if (is($p->{perl}, $version)) {
269 for my $s (@{$p->{subs}}) {
270 my($sub, @args) = @$s;
277 sub build_and_install
280 my $prefix = expand($opt{prefix});
282 print "building perl $perl->{version} ($current{config})\n";
284 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
285 run_or_die("sed -i -e '/^.*<built-in>/d' -e '/^.*<command line>/d' makefile x2p/makefile");
286 run_or_die("make all");
287 run("make test") if $opt{test};
289 run_or_die("make install");
292 print "\n*** NOT INSTALLING PERL ***\n\n";
299 print "patching DB_File\n";
300 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
305 patch('doio.c', <<'END');
306 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
307 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
312 +#if _SEM_SEMUN_UNDEFINED
316 + struct semid_ds *buf;
317 + unsigned short int *array;
318 + struct seminfo *__buf;
323 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
330 my($file, $patch) = @_;
331 print "patching $file\n";
332 my $diff = "$file.diff";
333 write_or_die($diff, $patch);
334 run_or_die("patch -s -p0 <$diff");
335 unlink $diff or die "unlink $diff: $!\n";
340 my($file, $data) = @_;
341 my $fh = new IO::File ">$file" or die "$file: $!\n";
347 # print "[running @_]\n";
348 system "@_" and die "@_: $?\n";
353 # print "[running @_]\n";
354 system "@_" and warn "@_: $?\n";
361 buildperl.pl - build/install perl distributions
365 perl buildperl.pl [options]
367 --help show this help
369 --source=directory directory containing source tarballs
370 [default: /tmp/perl/source]
372 --build=directory directory used for building perls [EXPAND]
373 [default: /tmp/perl/build/<config>]
375 --prefix=directory use this installation prefix [EXPAND]
376 [default: /tmp/perl/install/<config>/<perl>]
378 --config=configuration build this configuration [MULTI]
379 [default: all possible configurations]
381 --perl=version build this version of perl [MULTI]
382 [default: all possible versions]
384 --force rebuild and install already installed versions
386 --test run test suite after building
388 --noinstall don't install after building
390 options tagged with [MULTI] can be given multiple times
392 options tagged with [EXPAND] expand the following items
394 <perl> versioned perl directory (e.g. 'perl-5.6.1')
395 <version> perl version (e.g. '5.6.1')
396 <config> name of the configuration (e.g. 'default')
400 The following examples assume that your Perl source tarballs are
401 in F</tmp/perl/source>. If they are somewhere else, use the C<--source>
402 option to specify a different source directory.
404 To build a default configuration of perl5.004_05 and install it
405 to F</opt/perl5.004_05>, you would say:
407 buildperl.pl --prefix='/opt/<perl>' --perl=5.004_05 --config=default
409 To build debugging configurations of all perls in the source directory
410 and install them to F</opt>, use:
412 buildperl.pl --prefix='/opt/<perl>' --config=debug
414 To build all configurations for perl-5.8.5 and perl-5.8.6, test them
415 and don't install them, run:
417 buildperl.pl --perl=5.8.5 --perl=5.8.6 --test --noinstall
421 Copyright (c) 2004-2006, Marcus Holland-Moritz.
423 This program is free software; you can redistribute it and/or
424 modify it under the same terms as Perl itself.
428 See L<Devel::PPPort> and L<HACKERS>.