2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
10 # $Date: 2006/01/14 22:41:11 +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',
46 config_args => '-des',
49 config_args => '-des -Dusethreads',
50 masked_versions => [ qr/^5\.00[01234]/ ],
53 config_args => '-des -Duse5005threads',
54 masked_versions => [ qr/^5\.00[012345]|^5.(9|\d\d)/ ],
57 config_args => '-des -Doptimize=-g',
104 GetOptions(\%opt, qw(
115 if (exists $opt{config}) {
116 for my $cfg (@{$opt{config}}) {
117 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
121 $opt{config} = [sort keys %config];
125 /^(perl-?(5\..*))\.tar\.(gz|bz2)$/ or return;
126 $perl{$1} = { version => $2, source => $File::Find::name, compress => $3 };
129 if (exists $opt{perl}) {
130 for my $perl (@{$opt{perl}}) {
132 exists $perl{$p} or $p = "perl$perl";
133 exists $perl{$p} or $p = "perl-$perl";
134 exists $perl{$p} or die "Cannot find perl: $perl\n";
139 @perls = sort keys %perl;
144 for my $cfg (@{$opt{config}}) {
145 for my $perl (@perls) {
146 my $config = $config{$cfg};
147 %current = (config => $cfg, perl => $perl, version => $perl{$perl}{version});
149 if (is($config->{masked_versions}, $current{version})) {
150 print STDERR "skipping $perl for configuration $cfg (masked)\n";
154 if (-d expand($opt{prefix}) and !$opt{force}) {
155 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
161 my $build = expand($opt{build});
162 -d $build or mkpath($build);
163 chdir $build or die "chdir $build: $!\n";
165 print STDERR "building $perl with configuration $cfg\n";
166 buildperl($perl, $config);
168 chdir $cwd or die "chdir $cwd: $!\n";
175 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
183 defined $s1 != defined $s2 and return 0;
185 ref $s2 and ($s1, $s2) = ($s2, $s1);
188 if (ref $s1 eq 'ARRAY') {
189 is($_, $s2) and return 1 for @$s1;
200 my($perl, $cfg) = @_;
202 my $d = extract_source($perl{$perl});
203 chdir $d or die "chdir $d: $!\n";
205 patch_source($perl{$perl}{version});
207 build_and_install($perl{$perl});
214 print "reading $perl->{source}\n";
218 for my $f (Archive::Tar->list_archive($perl->{source})) {
219 my($t) = $f =~ /^([^\\\/]+)/ or die "ooops, should always match...\n";
220 die "refusing to extract $perl->{source}, as it would not extract to a single directory\n"
221 if defined $target and $target ne $t;
226 print "removing old build directory $target\n";
230 print "extracting $perl->{source}\n";
232 Archive::Tar->extract_archive($perl->{source})
233 or die "extract failed: " . Archive::Tar->error() . "\n";
235 -d $target or die "oooops, $target not found\n";
245 if (is($p->{perl}, $version)) {
246 for my $s (@{$p->{subs}}) {
247 my($sub, @args) = @$s;
254 sub build_and_install
257 my $prefix = expand($opt{prefix});
259 print "building perl $perl->{version} ($current{config})\n";
261 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
262 run_or_die("sed -i -e '/^.*<built-in>/d' -e '/^.*<command line>/d' makefile x2p/makefile");
263 run_or_die("make all");
264 run("make test") if $opt{test};
266 run_or_die("make install");
269 print "\n*** NOT INSTALLING PERL ***\n\n";
276 print "patching DB_File\n";
277 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
282 patch('doio.c', <<'END');
283 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
284 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
289 +#if _SEM_SEMUN_UNDEFINED
293 + struct semid_ds *buf;
294 + unsigned short int *array;
295 + struct seminfo *__buf;
300 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
307 my($file, $patch) = @_;
308 print "patching $file\n";
309 my $diff = "$file.diff";
310 write_or_die($diff, $patch);
311 run_or_die("patch -s -p0 <$diff");
312 unlink $diff or die "unlink $diff: $!\n";
317 my($file, $data) = @_;
318 my $fh = new IO::File ">$file" or die "$file: $!\n";
324 # print "[running @_]\n";
325 system "@_" and die "@_: $?\n";
330 # print "[running @_]\n";
331 system "@_" and warn "@_: $?\n";
338 buildperl.pl - build/install perl distributions
342 perl buildperl.pl [options]
344 --help show this help
346 --source=directory directory containing source tarballs
347 [default: /tmp/perl/source]
349 --build=directory directory used for building perls [EXPAND]
350 [default: /tmp/perl/build/<config>]
352 --prefix=directory use this installation prefix [EXPAND]
353 [default: /tmp/perl/install/<config>/<perl>]
355 --config=configuration build this configuration [MULTI]
356 [default: all possible configurations]
358 --perl=version build this version of perl [MULTI]
359 [default: all possible versions]
361 --force rebuild and install already installed versions
363 --test run test suite after building
365 --noinstall don't install after building
367 options tagged with [MULTI] can be given multiple times
369 options tagged with [EXPAND] expand the following items
371 <perl> versioned perl directory (e.g. 'perl-5.6.1')
372 <version> perl version (e.g. '5.6.1')
373 <config> name of the configuration (e.g. 'default')
377 The following examples assume that your Perl source tarballs are
378 in F</tmp/perl/source>. If they are somewhere else, use the C<--source>
379 option to specify a different source directory.
381 To build a default configuration of perl5.004_05 and install it
382 to F</opt/perl5.004_05>, you would say:
384 buildperl.pl --prefix='/opt/<perl>' --perl=5.004_05 --config=default
386 To build debugging configurations of all perls in the source directory
387 and install them to F</opt>, use:
389 buildperl.pl --prefix='/opt/<perl>' --config=debug
391 To build all configurations for perl-5.8.5 and perl-5.8.6, test them
392 and don't install them, run:
394 buildperl.pl --perl=5.8.5 --perl=5.8.6 --test --noinstall
398 Copyright (c) 2004-2005, Marcus Holland-Moritz.
400 This program is free software; you can redistribute it and/or
401 modify it under the same terms as Perl itself.
405 See L<Devel::PPPort>.