2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
10 # $Date: 2009/01/18 14:10:50 +0100 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2009, 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 ################################################################################
32 # TODO: - extra arguments to Configure
35 # --test-archives=1 check if archives can be read
36 # --test-archives=2 like 1, but also extract archives
37 # --test-archives=3 like 2, but also apply patches
41 prefix => '/tmp/perl/install/<config>/<perl>',
42 build => '/tmp/perl/build/<config>',
43 source => '/tmp/perl/source',
54 config_args => '-des',
57 config_args => '-des -Dusethreads',
58 masked_versions => [ qr/^5\.00[01234]/ ],
61 config_args => '-des -Duse5005threads',
62 masked_versions => [ qr/^5\.00[012345]|^5.(9|\d\d)/ ],
65 config_args => '-des -Doptimize=-g',
102 qr/^5\.004_0[1234]$/,
117 [ \&patch_sysv, old_format => 1 ],
139 GetOptions(\%opt, qw(
155 if ($opt{patch} || $opt{oneshot}) {
156 @{$opt{perl}} == 1 or die "Exactly one --perl must be given with --patch or --oneshot\n";
157 my $perl = $opt{perl}[0];
158 patch_source($perl) if !exists $opt{patch} || $opt{patch};
159 if (exists $opt{oneshot}) {
160 eval { require String::ShellQuote };
161 die "--oneshot requires String::ShellQuote to be installed\n" if $@;
162 %current = (config => 'oneshot', version => $perl);
163 $config{oneshot} = { config_args => String::ShellQuote::shell_quote(@ARGV) };
164 build_and_install($perl{$perl});
169 if (exists $opt{config}) {
170 for my $cfg (@{$opt{config}}) {
171 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
175 $opt{config} = [sort keys %config];
179 /^(perl-?(5\..*))\.tar\.(gz|bz2)$/ or return;
180 $perl{$1} = { version => $2, source => $File::Find::name, compress => $3 };
183 if (exists $opt{perl}) {
184 for my $perl (@{$opt{perl}}) {
186 exists $perl{$p} or $p = "perl$perl";
187 exists $perl{$p} or $p = "perl-$perl";
188 exists $perl{$p} or die "Cannot find perl: $perl\n";
193 @perls = sort keys %perl;
196 if ($opt{'test-archives'}) {
199 -d $test or mkpath($test);
200 chdir $test or die "chdir $test: $!\n";
201 for my $perl (@perls) {
203 my $d = extract_source($perl{$perl});
204 if ($opt{'test-archives'} > 2) {
206 chdir $d or die "chdir $d: $!\n";
207 patch_source($perl{$perl}{version});
208 chdir $cwd2 or die "chdir $cwd2:$!\n"
214 chdir $cwd or die "chdir $cwd: $!\n";
215 print STDERR "cleaning up\n";
220 for my $cfg (@{$opt{config}}) {
221 for my $perl (@perls) {
222 my $config = $config{$cfg};
223 %current = (config => $cfg, perl => $perl, version => $perl{$perl}{version});
225 if (is($config->{masked_versions}, $current{version})) {
226 print STDERR "skipping $perl for configuration $cfg (masked)\n";
230 if (-d expand($opt{prefix}) and !$opt{force}) {
231 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
237 my $build = expand($opt{build});
238 -d $build or mkpath($build);
239 chdir $build or die "chdir $build: $!\n";
241 print STDERR "building $perl with configuration $cfg\n";
242 buildperl($perl, $config);
244 chdir $cwd or die "chdir $cwd: $!\n";
251 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
259 defined $s1 != defined $s2 and return 0;
261 ref $s2 and ($s1, $s2) = ($s2, $s1);
264 if (ref $s1 eq 'ARRAY') {
265 is($_, $s2) and return 1 for @$s1;
276 my($perl, $cfg) = @_;
278 my $d = extract_source($perl{$perl});
279 chdir $d or die "chdir $d: $!\n";
281 patch_source($perl{$perl}{version});
283 build_and_install($perl{$perl});
288 eval { require Archive::Tar };
289 die "Archive processing requires Archive::Tar to be installed\n" if $@;
293 my $what = $opt{'test-archives'} ? 'test' : 'read';
294 print "${what}ing $perl->{source}\n";
298 for my $f (Archive::Tar->list_archive($perl->{source})) {
299 my($t) = $f =~ /^([^\\\/]+)/ or die "ooops, should always match...\n";
300 die "refusing to extract $perl->{source}, as it would not extract to a single directory\n"
301 if defined $target and $target ne $t;
305 if ($opt{'test-archives'} == 0 || $opt{'test-archives'} > 1) {
307 print "removing old build directory $target\n";
311 print "extracting $perl->{source}\n";
313 Archive::Tar->extract_archive($perl->{source})
314 or die "extract failed: " . Archive::Tar->error() . "\n";
316 -d $target or die "oooops, $target not found\n";
327 if (is($p->{perl}, $version)) {
328 for my $s (@{$p->{subs}}) {
329 my($sub, @args) = @$s;
336 sub build_and_install
339 my $prefix = expand($opt{prefix});
341 print "building perl $perl->{version} ($current{config})\n";
343 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
344 run_or_die("sed -i -e '/^.*<built-in>/d' -e '/^.*<command line>/d' makefile x2p/makefile");
345 run_or_die("make all");
346 run("make test") if $opt{test};
348 run_or_die("make install");
351 print "\n*** NOT INSTALLING PERL ***\n\n";
358 print "patching ext/DB_File/DB_File.xs\n";
359 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
365 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
366 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
371 +#if _SEM_SEMUN_UNDEFINED
375 + struct semid_ds *buf;
376 + unsigned short int *array;
377 + struct seminfo *__buf;
382 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
391 # check if patching is required
392 return if $^O ne 'linux' or -f '/usr/include/asm/page.h';
394 if ($opt{old_format}) {
396 --- ext/IPC/SysV/SysV.xs.org 1998-07-20 10:20:07.000000000 +0200
397 +++ ext/IPC/SysV/SysV.xs 2007-08-12 10:51:06.000000000 +0200
401 #include <sys/types.h>
403 -#include <asm/page.h>
405 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
412 --- ext/IPC/SysV/SysV.xs.org 2007-08-11 00:12:46.000000000 +0200
413 +++ ext/IPC/SysV/SysV.xs 2007-08-11 00:10:51.000000000 +0200
417 #include <sys/types.h>
419 -# include <asm/page.h>
421 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
423 # include <sys/ipc.h>
431 print "patching $_\n" for $patch =~ /^\+{3}\s+(\S+)/gm;
432 my $diff = 'tmp.diff';
433 write_or_die($diff, $patch);
434 run_or_die("patch -s -p0 <$diff");
435 unlink $diff or die "unlink $diff: $!\n";
440 my($file, $data) = @_;
441 my $fh = new IO::File ">$file" or die "$file: $!\n";
447 # print "[running @_]\n";
448 system "@_" and die "@_: $?\n";
453 # print "[running @_]\n";
454 system "@_" and warn "@_: $?\n";
461 buildperl.pl - build/install perl distributions
465 perl buildperl.pl [options]
467 --help show this help
469 --source=directory directory containing source tarballs
470 [default: /tmp/perl/source]
472 --build=directory directory used for building perls [EXPAND]
473 [default: /tmp/perl/build/<config>]
475 --prefix=directory use this installation prefix [EXPAND]
476 [default: /tmp/perl/install/<config>/<perl>]
478 --config=configuration build this configuration [MULTI]
479 [default: all possible configurations]
481 --perl=version build this version of perl [MULTI]
482 [default: all possible versions]
484 --force rebuild and install already installed versions
486 --test run test suite after building
488 --noinstall don't install after building
490 --patch only patch the perl source in the current directory
492 --oneshot build from the perl source in the current directory
493 (extra arguments are passed to Configure)
495 options tagged with [MULTI] can be given multiple times
497 options tagged with [EXPAND] expand the following items
499 <perl> versioned perl directory (e.g. 'perl-5.6.1')
500 <version> perl version (e.g. '5.6.1')
501 <config> name of the configuration (e.g. 'default')
505 The following examples assume that your Perl source tarballs are
506 in F</tmp/perl/source>. If they are somewhere else, use the C<--source>
507 option to specify a different source directory.
509 To build a default configuration of perl5.004_05 and install it
510 to F</opt/perl5.004_05>, you would say:
512 buildperl.pl --prefix='/opt/<perl>' --perl=5.004_05 --config=default
514 To build debugging configurations of all perls in the source directory
515 and install them to F</opt>, use:
517 buildperl.pl --prefix='/opt/<perl>' --config=debug
519 To build all configurations for perl-5.8.5 and perl-5.8.6, test them
520 and don't install them, run:
522 buildperl.pl --perl=5.8.5 --perl=5.8.6 --test --noinstall
524 To build and install a single version of perl with special configuration
527 buildperl.pl --perl=5.6.0 --prefix=/opt/p560ld --oneshot -- -des -Duselongdouble
531 Copyright (c) 2004-2009, Marcus Holland-Moritz.
533 This program is free software; you can redistribute it and/or
534 modify it under the same terms as Perl itself.
538 See L<Devel::PPPort> and L<HACKERS>.