2 ################################################################################
4 # buildperl.pl -- build various versions of perl automatically
6 ################################################################################
10 # $Date: 2005/01/31 08:10:49 +0100 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2005, 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 prefix => '/tmp/perl/install/<config>/<perl>',
34 build => '/tmp/perl/build/<config>',
35 source => '/tmp/perl/source',
41 config_args => '-des',
44 config_args => '-des -Dusethreads',
45 masked_versions => [ qr/^perl5\.00[01234]/ ],
48 config_args => '-des -Duse5005threads',
49 masked_versions => [ qr/^perl5\.00[012345]|^perl-5.(9|\d\d)/ ],
52 config_args => '-des -Doptimize=-g',
59 qr/^perl5\.00[01234]/,
89 qr/^perl5\.004_0[1234]/,
107 if (exists $opt{config}) {
108 for my $cfg (@{$opt{config}}) {
109 exists $config{$cfg} or die "Unknown configuration: $cfg\n";
113 $opt{config} = [sort keys %config];
117 /^(perl-?(5\..*))\.tar.gz$/ or return;
118 $perl{$1} = { version => $2, source => $File::Find::name };
121 if (exists $opt{perl}) {
122 for my $perl (@{$opt{perl}}) {
124 exists $perl{$p} or $p = "perl$perl";
125 exists $perl{$p} or $p = "perl-$perl";
126 exists $perl{$p} or die "Cannot find perl: $perl\n";
131 @perls = sort keys %perl;
134 $ENV{PATH} = "~/bin:$ENV{PATH}"; # use ccache
138 for my $cfg (@{$opt{config}}) {
139 for my $perl (@perls) {
140 my $config = $config{$cfg};
141 %current = (config => $cfg, perl => $perl);
143 if (is($config->{masked_versions}, $perl)) {
144 print STDERR "skipping $perl for configuration $cfg (masked)\n";
148 if (-d expand($opt{prefix}) and !$opt{force}) {
149 print STDERR "skipping $perl for configuration $cfg (already installed)\n";
155 my $build = expand($opt{build});
156 -d $build or mkpath($build);
157 chdir $build or die "chdir $build: $!\n";
159 print STDERR "building $perl with configuration $cfg\n";
160 buildperl($perl, $config);
162 chdir $cwd or die "chdir $cwd: $!\n";
169 $in =~ s/(<(\w+)>)/exists $current{$2} ? $current{$2} : $1/eg;
177 defined $s1 != defined $s2 and return 0;
179 ref $s2 and ($s1, $s2) = ($s2, $s1);
182 if (ref $s1 eq 'ARRAY') {
183 is($_, $s2) and return 1 for @$s1;
194 my($perl, $cfg) = @_;
196 my $d = extract_source($perl{$perl});
197 chdir $d or die "chdir $d: $!\n";
201 build_and_install($perl{$perl});
207 my $target = "perl-$perl->{version}";
209 for my $dir ("perl$perl->{version}", "perl-$perl->{version}") {
211 print "removing old build directory $dir\n";
216 print "extracting $perl->{source}\n";
218 run_or_die("tar xzf $perl->{source}");
220 if ($perl->{version} !~ /^\d+\.\d+\.\d+/ && -d "perl-$perl->{version}") {
221 $target = "perl$perl->{version}";
222 rename "perl-$perl->{version}", $target or die "rename: $!\n";
225 -d $target or die "$target not found\n";
235 if (is($p->{perl}, $perl)) {
236 for my $s (@{$p->{subs}}) {
237 my($sub, @args) = @$s;
244 sub build_and_install
247 my $prefix = expand($opt{prefix});
249 print "building perl $perl->{version} ($current{config})\n";
251 run_or_die("./Configure $config{$current{config}}{config_args} -Dusedevel -Uinstallusrbinperl -Dprefix=$prefix");
252 run_or_die("sed -i -e '/^.*<built-in>/d' -e '/^.*<command line>/d' makefile x2p/makefile");
253 run_or_die("make all");
255 run_or_die("make install");
261 print "patching DB_File\n";
262 run_or_die("sed -i -e 's/<db.h>/<db$ver\\/db.h>/' ext/DB_File/DB_File.xs");
267 patch('doio.c', <<'END');
268 --- doio.c.org 2004-06-07 23:14:45.000000000 +0200
269 +++ doio.c 2003-11-04 08:03:03.000000000 +0100
274 +#if _SEM_SEMUN_UNDEFINED
278 + struct semid_ds *buf;
279 + unsigned short int *array;
280 + struct seminfo *__buf;
285 do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
292 my($file, $patch) = @_;
293 print "patching $file\n";
294 my $diff = "$file.diff";
295 write_or_die($diff, $patch);
296 run_or_die("patch -s -p0 <$diff");
297 unlink $diff or die "unlink $diff: $!\n";
302 my($file, $data) = @_;
303 my $fh = new IO::File ">$file" or die "$file: $!\n";
309 # print "[running @_]\n";
310 system "@_" and die "@_: $?\n";
315 # print "[running @_]\n";
316 system "@_" and warn "@_: $?\n";