2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
8 # Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
9 # Version 2.x, Copyright (C) 2001, Paul Marquess.
10 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
15 ################################################################################
26 # TODO: - extra arguments to Configure
29 # --test-archives=1 check if archives can be read
30 # --test-archives=2 like 1, but also extract archives
31 # --test-archives=3 like 2, but also apply patches
35 prefix => '/tmp/perl/install/<config>/<perl>',
36 build => '/tmp/perl/build/<config>',
37 source => '/tmp/perl/source',
49 config_args => '-des',
52 config_args => '-des -Dusethreads',
53 masked_versions => [ qr/^5\.00[01234]/ ],
56 config_args => '-des -Duse5005threads',
57 masked_versions => [ qr/^5\.00[012345]|^5\.(9|\d\d)|^5\.8\.9/ ],
60 config_args => '-des -Doptimize=-g',
112 [ \&patch_sysv, old_format => 1 ],
133 qr/^5\.005(?:_0[1-4])?$/,
137 [ \&patch_configure ],
138 [ \&patch_makedepend_lc ],
146 [ \&patch_makedepend_lc ],
153 GetOptions(\%opt, qw(
171 $job_string = "-j$opt{jobs}" if $opt{jobs} != 1;
173 if ($opt{patch} || $opt{oneshot}) {
174 @{$opt{perl}} == 1 or die "Exactly one --perl must be given with --patch or --oneshot\n";
175 my $perl = $opt{perl}[0];
176 patch_source($perl) if !exists $opt{patch} || $opt{patch};
177 if (exists $opt{oneshot}) {
178 eval { require String::ShellQuote };
179 die "--oneshot requires String::ShellQuote to be installed\n" if $@;
180 %current = (config => 'oneshot', version => $perl);
181 $config{oneshot} = { config_args => String::ShellQuote::shell_quote(@ARGV) };
182 build_and_install($perl{$perl});
187 if (exists $opt{config}) {
188 for my $cfg (@{$opt{config}}) {
189 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
193 $opt{config} = [sort keys %config];
197 /^(perl-?(5\..*))\.tar\.(gz|bz2|lzma)$/ or return;
198 $perl{$1} = { version => $2, source => $File::Find::name, compress => $3 };
201 if (exists $opt{perl}) {
202 for my $perl (@{$opt{perl}}) {
204 exists $perl{$p} or $p = "perl$perl";
205 exists $perl{$p} or $p = "perl-$perl";
206 exists $perl{$p} or die "Cannot find perl: $perl\n";
211 @perls = sort keys %perl;
214 if ($opt{'test-archives'}) {
217 -d $test or mkpath($test);
218 chdir $test or die "chdir $test: $!\n";
219 for my $perl (@perls) {
221 my $d = extract_source($perl{$perl});
222 if ($opt{'test-archives'} > 2) {
224 chdir $d or die "chdir $d: $!\n";
225 patch_source($perl{$perl}{version});
226 chdir $cwd2 or die "chdir $cwd2:$!\n"
232 chdir $cwd or die "chdir $cwd: $!\n";
233 print STDERR "cleaning up\n";
238 for my $cfg (@{$opt{config}}) {
239 for my $perl (@perls) {
240 my $config = $config{$cfg};
241 %current = (config => $cfg, perl => $perl, version => $perl{$perl}{version});
243 if (is($config->{masked_versions}, $current{version})) {
244 print STDERR "skipping $perl for configuration $cfg (masked)\n";
248 if (-d expand($opt{prefix}) and !$opt{force}) {
249 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
255 my $build = expand($opt{build});
256 -d $build or mkpath($build);
257 chdir $build or die "chdir $build: $!\n";
259 print STDERR "building $perl with configuration $cfg\n";
260 buildperl($perl, $config);
262 chdir $cwd or die "chdir $cwd: $!\n";
269 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
277 defined $s1 != defined $s2 and return 0;
279 ref $s2 and ($s1, $s2) = ($s2, $s1);
282 if (ref $s1 eq 'ARRAY') {
283 is($_, $s2) and return 1 for @$s1;
294 my($perl, $cfg) = @_;
296 my $d = extract_source($perl{$perl});
297 chdir $d or die "chdir $d: $!\n";
299 patch_source($perl{$perl}{version});
301 build_and_install($perl{$perl});
306 eval { require Archive::Tar };
307 die "Archive processing requires Archive::Tar to be installed\n" if $@;
311 my $what = $opt{'test-archives'} ? 'test' : 'read';
312 print "${what}ing $perl->{source}\n";
316 for my $f (Archive::Tar->list_archive($perl->{source})) {
317 my($t) = $f =~ /^([^\\\/]+)/ or die "ooops, should always match...\n";
318 die "refusing to extract $perl->{source}, as it would not extract to a single directory\n"
319 if defined $target and $target ne $t;
323 if ($opt{'test-archives'} == 0 || $opt{'test-archives'} > 1) {
325 print "removing old build directory $target\n";
329 print "extracting $perl->{source}\n";
331 Archive::Tar->extract_archive($perl->{source})
332 or die "extract failed: " . Archive::Tar->error() . "\n";
334 -d $target or die "oooops, $target not found\n";
345 if (is($p->{perl}, $version)) {
346 for my $s (@{$p->{subs}}) {
347 my($sub, @args) = @$s;
354 sub build_and_install
357 my $prefix = expand($opt{prefix});
359 run_or_die(q{sed -i -e "s:\\*/\\*) finc=\\"-I\\`echo \\$file | sed 's#/\\[^/\\]\\*\\$##\\`\\" ;;:*/*) finc=\\"-I\\`echo \\$file | sed 's#/[^/]\\*\\$##'\\`\\" ;;:" makedepend.SH});
361 print "building perl $perl->{version} ($current{config})\n";
363 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
364 if (-f "x2p/makefile") {
365 run_or_die("sed -i -e '/^.*<builtin>/d' -e '/^.*<built-in>/d' -e '/^.*<command line>/d' -e '/^.*<command-line>/d' makefile x2p/makefile");
367 run_or_die("make $job_string all");
368 run("TEST_JOBS=$opt{jobs} make $job_string test") if $opt{test};
370 run_or_die("make $job_string install");
373 print "\n*** NOT INSTALLING PERL ***\n\n";
380 print "patching ext/DB_File/DB_File.xs\n";
381 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
387 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
388 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
393 +#if _SEM_SEMUN_UNDEFINED
397 + struct semid_ds *buf;
398 + unsigned short int *array;
399 + struct seminfo *__buf;
404 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
413 # check if patching is required
414 return if $^O ne 'linux' or -f '/usr/include/asm/page.h';
416 if ($opt{old_format}) {
418 --- ext/IPC/SysV/SysV.xs.org 1998-07-20 10:20:07.000000000 +0200
419 +++ ext/IPC/SysV/SysV.xs 2007-08-12 10:51:06.000000000 +0200
423 #include <sys/types.h>
425 -#include <asm/page.h>
427 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
434 --- ext/IPC/SysV/SysV.xs.org 2007-08-11 00:12:46.000000000 +0200
435 +++ ext/IPC/SysV/SysV.xs 2007-08-11 00:10:51.000000000 +0200
439 #include <sys/types.h>
441 -# include <asm/page.h>
443 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
445 # include <sys/ipc.h>
455 @@ -3380,6 +3380,18 @@
456 test "X$gfpthkeep" != Xy && gfpth=""
459 +# gcc 3.1 complains about adding -Idirectories that it already knows about,
460 +# so we will take those off from locincpth.
461 +case "$gccversion" in
463 + echo "main(){}">try.c
464 + for incdir in `$cc -v -c try.c 2>&1 | \
465 + sed '1,/^#include <\.\.\.>/d;/^End of search list/,$d;s/^ //'` ; do
466 + locincpth=`echo $locincpth | sed s!$incdir!!`
471 : What should the include directory be ?
477 sub patch_makedepend_lc
482 @@ -58,6 +58,10 @@ case $PERL_CONFIG_SH in
486 +# Avoid localized gcc/cc messages
490 # We need .. when we are in the x2p directory if we are using the
491 # cppstdin wrapper script.
492 # Put .. and . first so that we pick up the present cppstdin, not
499 print "patching $_\n" for $patch =~ /^\+{3}\s+(\S+)/gm;
500 my $diff = 'tmp.diff';
501 write_or_die($diff, $patch);
502 run_or_die("patch -s -p0 <$diff");
503 unlink $diff or die "unlink $diff: $!\n";
508 my($file, $data) = @_;
509 my $fh = new IO::File ">$file" or die "$file: $!\n";
515 # print "[running @_]\n";
516 system "@_" and die "@_: $?\n";
521 # print "[running @_]\n";
522 system "@_" and warn "@_: $?\n";
529 buildperl.pl - build/install perl distributions
533 perl buildperl.pl [options]
535 --help show this help
537 --source=directory directory containing source tarballs
538 [default: /tmp/perl/source]
540 --build=directory directory used for building perls [EXPAND]
541 [default: /tmp/perl/build/<config>]
543 --prefix=directory use this installation prefix [EXPAND]
545 /tmp/perl/install/<config>/<perl>]
547 --config=configuration build this configuration [MULTI]
548 [default: all possible configurations]
550 --perl=version build this version of perl [MULTI]
551 [default: all possible versions]
553 --force rebuild and install already installed
556 --test run test suite after building
558 --noinstall don't install after building
560 --patch only patch the perl source in the current
563 --oneshot build from the perl source in the current
564 directory (extra arguments are passed to
567 -j N Build and test with N parallel jobs, default 1.
569 options tagged with [MULTI] can be given multiple times
571 options tagged with [EXPAND] expand the following items
573 <perl> versioned perl directory (e.g. 'perl-5.6.1')
574 <version> perl version (e.g. '5.6.1')
575 <config> name of the configuration (e.g. 'default')
579 The following examples assume that your Perl source tarballs are
580 in F</tmp/perl/source>. If they are somewhere else, use the C<--source>
581 option to specify a different source directory.
583 To build a default configuration of perl5.004_05 and install it
584 to F</opt/perl5.004_05>, you would say:
586 buildperl.pl --prefix='/opt/<perl>' --perl=5.004_05 --config=default
588 To build debugging configurations of all perls in the source directory
589 and install them to F</opt>, use:
591 buildperl.pl --prefix='/opt/<perl>' --config=debug
593 To build all configurations for perl-5.8.5 and perl-5.8.6, test them
594 and don't install them, run:
596 buildperl.pl --perl=5.8.5 --perl=5.8.6 --test --noinstall
598 To build and install a single version of perl with special configuration
601 buildperl.pl --perl=5.6.0 --prefix=/opt/p560ld --oneshot -- -des \
606 Copyright (c) 2004-2013, Marcus Holland-Moritz.
608 This program is free software; you can redistribute it and/or
609 modify it under the same terms as Perl itself.
613 See L<Devel::PPPort> and L<HACKERS>.