2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
10 # $Date: 2008/01/04 10:47:39 +0100 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2008, 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 # --test-archives=1 check if archives can be read
37 # --test-archives=2 like 1, but also extract archives
38 # --test-archives=3 like 2, but also apply patches
42 prefix => '/tmp/perl/install/<config>/<perl>',
43 build => '/tmp/perl/build/<config>',
44 source => '/tmp/perl/source',
53 config_args => '-des',
56 config_args => '-des -Dusethreads',
57 masked_versions => [ qr/^5\.00[01234]/ ],
60 config_args => '-des -Duse5005threads',
61 masked_versions => [ qr/^5\.00[012345]|^5.(9|\d\d)/ ],
64 config_args => '-des -Doptimize=-g',
101 qr/^5\.004_0[1234]$/,
116 [ \&patch_sysv, old_format => 1 ],
138 GetOptions(\%opt, qw(
150 if (exists $opt{config}) {
151 for my $cfg (@{$opt{config}}) {
152 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
156 $opt{config} = [sort keys %config];
160 /^(perl-?(5\..*))\.tar\.(gz|bz2)$/ or return;
161 $perl{$1} = { version => $2, source => $File::Find::name, compress => $3 };
164 if (exists $opt{perl}) {
165 for my $perl (@{$opt{perl}}) {
167 exists $perl{$p} or $p = "perl$perl";
168 exists $perl{$p} or $p = "perl-$perl";
169 exists $perl{$p} or die "Cannot find perl: $perl\n";
174 @perls = sort keys %perl;
177 if ($opt{'test-archives'}) {
180 -d $test or mkpath($test);
181 chdir $test or die "chdir $test: $!\n";
182 for my $perl (@perls) {
184 my $d = extract_source($perl{$perl});
185 if ($opt{'test-archives'} > 2) {
187 chdir $d or die "chdir $d: $!\n";
188 patch_source($perl{$perl}{version});
189 chdir $cwd2 or die "chdir $cwd2:$!\n"
195 chdir $cwd or die "chdir $cwd: $!\n";
196 print STDERR "cleaning up\n";
203 for my $cfg (@{$opt{config}}) {
204 for my $perl (@perls) {
205 my $config = $config{$cfg};
206 %current = (config => $cfg, perl => $perl, version => $perl{$perl}{version});
208 if (is($config->{masked_versions}, $current{version})) {
209 print STDERR "skipping $perl for configuration $cfg (masked)\n";
213 if (-d expand($opt{prefix}) and !$opt{force}) {
214 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
220 my $build = expand($opt{build});
221 -d $build or mkpath($build);
222 chdir $build or die "chdir $build: $!\n";
224 print STDERR "building $perl with configuration $cfg\n";
225 buildperl($perl, $config);
227 chdir $cwd or die "chdir $cwd: $!\n";
234 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
242 defined $s1 != defined $s2 and return 0;
244 ref $s2 and ($s1, $s2) = ($s2, $s1);
247 if (ref $s1 eq 'ARRAY') {
248 is($_, $s2) and return 1 for @$s1;
259 my($perl, $cfg) = @_;
261 my $d = extract_source($perl{$perl});
262 chdir $d or die "chdir $d: $!\n";
264 patch_source($perl{$perl}{version});
266 build_and_install($perl{$perl});
273 my $what = $opt{'test-archives'} ? 'test' : 'read';
274 print "${what}ing $perl->{source}\n";
278 for my $f (Archive::Tar->list_archive($perl->{source})) {
279 my($t) = $f =~ /^([^\\\/]+)/ or die "ooops, should always match...\n";
280 die "refusing to extract $perl->{source}, as it would not extract to a single directory\n"
281 if defined $target and $target ne $t;
285 if ($opt{'test-archives'} == 0 || $opt{'test-archives'} > 1) {
287 print "removing old build directory $target\n";
291 print "extracting $perl->{source}\n";
293 Archive::Tar->extract_archive($perl->{source})
294 or die "extract failed: " . Archive::Tar->error() . "\n";
296 -d $target or die "oooops, $target not found\n";
307 if (is($p->{perl}, $version)) {
308 for my $s (@{$p->{subs}}) {
309 my($sub, @args) = @$s;
316 sub build_and_install
319 my $prefix = expand($opt{prefix});
321 print "building perl $perl->{version} ($current{config})\n";
323 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
324 run_or_die("sed -i -e '/^.*<built-in>/d' -e '/^.*<command line>/d' makefile x2p/makefile");
325 run_or_die("make all");
326 run("make test") if $opt{test};
328 run_or_die("make install");
331 print "\n*** NOT INSTALLING PERL ***\n\n";
338 print "patching ext/DB_File/DB_File.xs\n";
339 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
345 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
346 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
351 +#if _SEM_SEMUN_UNDEFINED
355 + struct semid_ds *buf;
356 + unsigned short int *array;
357 + struct seminfo *__buf;
362 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
371 # check if patching is required
372 return if $^O ne 'linux' or -f '/usr/include/asm/page.h';
374 if ($opt{old_format}) {
376 --- ext/IPC/SysV/SysV.xs.org 1998-07-20 10:20:07.000000000 +0200
377 +++ ext/IPC/SysV/SysV.xs 2007-08-12 10:51:06.000000000 +0200
381 #include <sys/types.h>
383 -#include <asm/page.h>
385 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
392 --- ext/IPC/SysV/SysV.xs.org 2007-08-11 00:12:46.000000000 +0200
393 +++ ext/IPC/SysV/SysV.xs 2007-08-11 00:10:51.000000000 +0200
397 #include <sys/types.h>
399 -# include <asm/page.h>
401 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
403 # include <sys/ipc.h>
411 print "patching $_\n" for $patch =~ /^\+{3}\s+(\S+)/gm;
412 my $diff = 'tmp.diff';
413 write_or_die($diff, $patch);
414 run_or_die("patch -s -p0 <$diff");
415 unlink $diff or die "unlink $diff: $!\n";
420 my($file, $data) = @_;
421 my $fh = new IO::File ">$file" or die "$file: $!\n";
427 # print "[running @_]\n";
428 system "@_" and die "@_: $?\n";
433 # print "[running @_]\n";
434 system "@_" and warn "@_: $?\n";
441 buildperl.pl - build/install perl distributions
445 perl buildperl.pl [options]
447 --help show this help
449 --source=directory directory containing source tarballs
450 [default: /tmp/perl/source]
452 --build=directory directory used for building perls [EXPAND]
453 [default: /tmp/perl/build/<config>]
455 --prefix=directory use this installation prefix [EXPAND]
456 [default: /tmp/perl/install/<config>/<perl>]
458 --config=configuration build this configuration [MULTI]
459 [default: all possible configurations]
461 --perl=version build this version of perl [MULTI]
462 [default: all possible versions]
464 --force rebuild and install already installed versions
466 --test run test suite after building
468 --noinstall don't install after building
470 options tagged with [MULTI] can be given multiple times
472 options tagged with [EXPAND] expand the following items
474 <perl> versioned perl directory (e.g. 'perl-5.6.1')
475 <version> perl version (e.g. '5.6.1')
476 <config> name of the configuration (e.g. 'default')
480 The following examples assume that your Perl source tarballs are
481 in F</tmp/perl/source>. If they are somewhere else, use the C<--source>
482 option to specify a different source directory.
484 To build a default configuration of perl5.004_05 and install it
485 to F</opt/perl5.004_05>, you would say:
487 buildperl.pl --prefix='/opt/<perl>' --perl=5.004_05 --config=default
489 To build debugging configurations of all perls in the source directory
490 and install them to F</opt>, use:
492 buildperl.pl --prefix='/opt/<perl>' --config=debug
494 To build all configurations for perl-5.8.5 and perl-5.8.6, test them
495 and don't install them, run:
497 buildperl.pl --perl=5.8.5 --perl=5.8.6 --test --noinstall
501 Copyright (c) 2004-2008, Marcus Holland-Moritz.
503 This program is free software; you can redistribute it and/or
504 modify it under the same terms as Perl itself.
508 See L<Devel::PPPort> and L<HACKERS>.