use Config;
use File::Basename qw(&basename &dirname);
+use Cwd;
# List explicitly here the variables you want Configure to
# generate. Metaconfig only looks for shell variables, so you
# This forces PL files to create target in same directory as PL file.
# This is so that make depend always knows where to find PL derivatives.
+$origdir = cwd;
chdir dirname($0);
$file = basename($0, '.PL');
$file .= '.com' if $^O eq 'VMS';
use strict;
use FileHandle;
use File::Basename qw(&basename &dirname);
+use Cwd;
use Getopt::Long;
$obj = ($options->{'o'})? $options->{'o'} :
_getExecutable($file, $module_ext);
- $so = "$obj.so";
+ $so = "$obj.$Config{so}";
$type = 'sharedlib';
return() if (!$obj);
+ $objfile = ($options->{'C'}) ? $options->{'C'} : "$file.c";
}
else
{
if ($errcode);
_print("Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
- my $errcode = _compileCode($file, $objfile, $obj)
+ $errcode = _compileCode($file, $objfile, $obj)
if (!$options->{'gen'});
if ($errcode)
_removeCode($file) if ($options->{'e'});
- _removeCode($obj) if (($options->{'e'} &&
- ((!$options->{'sav'}) || !$options->{'o'})) ||
- ($options->{'run'} && (!$options->{'sav'})));
+ _removeCode($obj) if (($options->{'e'}
+ && !$options->{'sav'}
+ && !$options->{'o'})
+ || ($options->{'run'} && !$options->{'sav'}));
}
else
{
(_print( "ERROR: In generating code for $file!\n", -1), return())
if ($errcode);
- _print( "Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
+ _print( "Compiling C($so) for $file!\n", 36 ) if (!$options->{'gen'});
my $errorcode =
_compileCode($file, $objfile, $obj, $so ) if (!$options->{'gen'});
if (@_ == 3) # just compiling a program
{
$return[0] =
- _ccharness($sourceprog, "-o", $output_executable, $generated_cfile);
+ _ccharness('static', $sourceprog, "-o", $output_executable, $generated_cfile);
$return[0];
}
else
{
my $object_file = $generated_cfile;
- $object_file =~ s"\.c$"\.o";
+ $object_file =~ s"\.c$"$Config{_o}";
- $return[0] = _ccharness($sourceprog, "-c", $generated_cfile);
+ $return[0] = _ccharness('compile', $sourceprog, "-c", $generated_cfile);
$return[1] = _ccharness
(
- $sourceprog, "-shared","-o",
+ 'dynamic',
+ $sourceprog, "-o",
$shared_object, $object_file
);
return(1) if (grep ($_, @return));
sub _ccharness
{
+ my $type = shift;
my (@args) = @_;
local($") = " ";
}
else
{
- $libdir = "-L..";
- $incdir = "-I..";
+ $libdir = "-L.. -L.";
+ $incdir = "-I.. -I.";
}
$libdir .= " -L$options->{L}" if (defined($options->{L}));
$incdir .= " -I$options->{L}" if (defined($options->{L}));
- my $linkargs;
+ my $linkargs = '';
- if (!grep(/^-[cS]$/, @ARGV))
+ if (!grep(/^-[cS]$/, @args))
{
- $linkargs = sprintf("%s $libdir -lperl %s",@Config{qw(ldflags libs)});
+ my $lperl = $^O eq 'os2' ? '-llibperl' : '-lperl';
+ my $flags = $type eq 'dynamic' ? $Config{lddlflags} : $Config{ldflags};
+ $linkargs = "$flags $libdir $lperl @Config{libs}";
}
my @sharedobjects = _getSharedObjects($sourceprog);
my $cccmd =
- "$Config{cc} $Config{ccflags} $incdir @sharedobjects @args $linkargs";
+ "$Config{cc} @Config{qw(ccflags optimize)} $incdir @sharedobjects @args $linkargs";
_print ("$cccmd\n", 36);
_print("$\18 -I@INC $tmpfile\n", 36);
_run("$\18 -I@INC $tmpfile", 9 );
- my $fd = new FileHandle ("$incfile");
+ $fd = new FileHandle ("$incfile");
my @lines = <$fd>;
unlink($tmpfile);
{
my ($regexp) = @_;
- grep(s"(^|[^\\])\."$1\x0\\."g, @$regexp);
- grep(s"(^|[^\x0])\\\."$1\."g, @$regexp);
- grep(s"\x0""g, @$regexp);
+ grep(s:(^|[^\\])\.:$1\x00\\.:g, @$regexp);
+ grep(s:(^|[^\x00])\\\.:$1\.:g, @$regexp);
+ grep(s:\x00::g, @$regexp);
}
close OUT or die "Can't close $file: $!";
chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
+chdir $origdir;