# Version 2.01, Tom Christiansen, Thu Mar 30 08:25:14 MST 2000
# Version 2.02, Simon Cozens, Sun Apr 16 01:53:36 JST 2000
# Version 2.03, Edward Peschko, Mon Feb 26 12:04:17 PST 2001
+# Version 2.04, Enache Adrian,Fri, 18 Jul 2003 23:15:37 +0300
use strict;
use warnings;
use Fcntl qw(:DEFAULT :flock);
use File::Temp qw(tempfile);
use Cwd;
-our $VERSION = 2.03;
+our $VERSION = 2.04;
$| = 1;
$SIG{INT} = sub { exit(); }; # exit gracefully and clean up after ourselves.
'static', # Dirty hack to enable -shared/-static
'shared', # Create a shared library (--shared for compat.)
'log:s', # where to log compilation process information
+ 'Wb:s', # pass (comma-sepearated) options to backend
'testsuite', # try to be nice to testsuite
);
}
sub compile_byte {
- require ByteLoader;
- my $stash = grab_stash();
- my $command = "$BinPerl -MO=Bytecode,$stash $Input";
- # The -a option means we'd have to close the file and lose the
- # lock, which would create the tiniest of races. Instead, append
- # the output ourselves.
- vprint 1, "Writing on $Output";
-
- my $openflags = O_WRONLY | O_CREAT;
- $openflags |= O_BINARY if eval { O_BINARY; 1 };
- $openflags |= O_EXLOCK if eval { O_EXLOCK; 1 };
-
- # these dies are not "$0: .... \n" because they "can't happen"
-
- sysopen(OUT, $Output, $openflags)
- or die "can't write to $Output: $!";
-
- # this is blocking; hold on; why are we doing this??
- # flock OUT, LOCK_EX or die "can't lock $Output: $!"
- # unless eval { O_EXLOCK; 1 };
-
- truncate(OUT, 0)
- or die "couldn't trunc $Output: $!";
-
- print OUT <<EOF;
-#!$^X
-use ByteLoader $ByteLoader::VERSION;
-EOF
-
- # Now the compile:
- vprint 1, "Compiling...";
- vprint 3, "Calling $command";
+ my $command = "$BinPerl -MO=Bytecode,-H,-o$Output $Input";
+ $Input =~ s/^-e.*$/-e/;
my ($output_r, $error_r) = spawnit($command);
if (@$error_r && $? != 0) {
- _die("$0: $Input did not compile, which can't happen:\n@$error_r\n");
+ _die("$0: $Input did not compile:\n@$error_r\n");
} else {
my @error = grep { !/^$Input syntax OK$/o } @$error_r;
warn "$0: Unexpected compiler output:\n@error" if @error;
}
- # Write it and leave.
- print OUT @$output_r or _die("can't write $Output: $!");
- close OUT or _die("can't close $Output: $!");
-
- # wait, how could it be anything but what you see next?
chmod 0777 & ~umask, $Output or _die("can't chmod $Output: $!");
exit 0;
}
my $lose = 0;
my ($cfh);
my $testsuite = '';
+ my $addoptions = opt(Wb);
+
+ if( $addoptions ) {
+ $addoptions .= ',' if $addoptions !~ m/,$/;
+ }
if (opt(testsuite)) {
my $bo = join '', @begin_output;
# This has to do the write itself, so we can't keep a lock. Life
# sucks.
- my $command = "$BinPerl $taint -MO=$Backend,$testsuite$max_line_len$stash,-o$cfile $Input";
+ my $command = "$BinPerl $taint -MO=$Backend,$addoptions$testsuite$max_line_len$stash,-o$cfile $Input";
vprint 1, "Compiling...";
vprint 1, "Calling $command";
$link .= " -libpath:".$_ for split /\s+/, opt(L);
my @mods = split /-?u /, $stash;
$link .= " ".ExtUtils::Embed::ldopts("-std", \@mods);
- $link .= " perl57.lib msvcrt.lib";
+ $link .= " perl5$Config{PERL_VERSION}.lib kernel32.lib msvcrt.lib";
vprint 3, "running $Config{cc} $compile";
system("$Config{cc} $compile");
vprint 3, "running $Config{ld} $link";
sub _usage_and_die {
_die(<<EOU);
$0: Usage:
-$0 [-o executable] [-r] [-O|-B|-c|-S] [-log log] [source[.pl] | -e oneliner]
+$0 [-o executable] [-r] [-O|-B|-c|-S] [-I /foo] [-L /foo] [-log log] [source[.pl] | -e oneliner]
EOU
}