Viewing File: /usr/local/cpanel/3rdparty/perl/536/bin/cc_harness
#!/usr/local/cpanel/3rdparty/perl/536/bin/perl
use Config;
use ExtUtils::Embed;
my $coredir = $ENV{PERL_SRC} || "$Config{archlib}/CORE"; # XXX was installarchlib
my $libdir = "$Config{prefix}/lib";
my $useshrplib = $Config{useshrplib} eq 'true';
my $libs = $Config{libs};
my $so = $Config{so};
my ( $linkargs, $quiet, $debug );
my $stash = q{};
if ( grep { $_ eq '-q' or $_ eq '--quiet' } @ARGV ) {
$quiet++;
@ARGV = grep { $_ ne '-q' and $_ ne '--quiet' } @ARGV;
}
if ( grep { $_ eq '-d' or $_ eq '--debug' } @ARGV ) {
$debug++;
@ARGV = grep { $_ ne '-d' and $_ ne '--debug' } @ARGV;
}
eval { require B::C::Flags; };
if ( grep( /^-[cES]$/, @ARGV ) ) { # compile-only with -c -E or -S
;
}
elsif ( grep( /^-Bdynamic$/, @ARGV ) ) { # force dynamic linking with -Bdynamic
@ARGV = grep { !/^-Bdynamic$/o } @ARGV;
$linkargs = ldopts;
}
elsif ( grep( /^-Bstatic$/, @ARGV ) ) { # force static linking with -Bstatic
@ARGV = grep { !/^-Bstatic$/o } @ARGV;
$linkargs = ldopts("-std");
for my $lib ( "$libdir/libperl.a", "$coredir/libperl.a" ) {
if ( -e $lib ) {
$linkargs =~ s|-lperl |$lib |;
push @ARGV, ("$coredir/DynaLoader.o") if -e "$coredir/DynaLoader.o";
#$linkargs .= " $coredir/Win32CORE.o" if $^O eq 'cygwin' and -e "$coredir/Win32CORE.o";
last;
}
}
}
elsif ( -e "$coredir/$Config{libperl}" and $Config{libperl} !~ /\.$so$/ ) {
$linkargs = ldopts("-std"); # importlib or static
}
elsif ( $useshrplib and -e "$libdir/$Config{libperl}" ) {
# debian: /usr/lib/libperl.so.5.10.1 and broken ExtUtils::Embed::ldopts
$linkargs = ldopts('-std');
$linkargs =~ s|-lperl |$libdir/$Config{libperl} |;
}
elsif ( $useshrplib and -e "$coredir/$Config{libperl}" ) {
# just help cygwin debugging
$linkargs = ldopts('-std');
$linkargs =~ s|-lperl |$coredir/$Config{libperl} |;
}
else { # try dynamic lib if no static lib exists
@ARGV = grep { !/^-Bdynamic$/o } @ARGV;
$linkargs = ldopts('-std');
}
# old perlcc arg --staticxs. Now standard.
$linkargs .= q{ -DSTATICXS};
# find the c file
my @c_files = grep { $_ =~ qr{\.c$} && -f $_ } @ARGV;
die "Unsupported multiple .c files: " . join( ', ', @c_files ) if scalar @c_files > 1;
if ( my $c_file = $c_files[0] ) {
my $lst_file = $c_file;
$lst_file .= q{.lst};
$B::C::Flags::extra_libs //= q{};
if ( -f $lst_file ) {
debug("Reading .so files from $lst_file");
{ # read the lst file
open( my $fh, '<', $lst_file ) or die "Cannot read $lst_file: $!";
foreach my $line ( readline $fh ) {
my ( $s, $l ) = $line =~ m/^([^\t]+)(.*)$/;
die "Invalid line '$line' in $lst_file" unless length $s && length $l;
$stash .= ",-u$s";
$B::C::Flags::extra_libs .= " " . $l;
}
close($fh);
}
}
}
# Note (probably harmless): No library found for -lnsl
$linkargs = $B::C::Flags::extra_libs . " " . $linkargs;
$linkargs .= " $libs" if index( $linkargs, $libs ) == -1;
sub debug {
my (@txt) = @_;
return if $quiet;
print join( ' ', map { $_ // 'undef' } '[cc_harness]', @txt ) . "\n";
}
sub cc_harness_msvc {
my @ARGV = @_;
my $obj = "${Output}.obj";
my $compile = ccopts . " -c -Fo$obj @ARGV ";
my $link = "-out:$Output $obj ";
if ($debug) {
$compile .= "/Wall " if !$quiet;
# remove conflicting flags
$compile .= "-g ";
$compile =~ s/ -O.? / -Od /;
$compile =~ s/ -DNDEBUG / -DDEBUG /;
}
$compile .= $B::C::Flags::extra_cflags;
$compile .= " -I" . $_ for split /\s+/, opt(I);
$link .= " -libpath:" . $_ for split /\s+/, opt(L);
# TODO: -shared,-static,-sharedxs,-staticxs
$link .= ( " " . $B::C::Flags::extra_libs );
if ($stash) {
my @mods = split /-?u /, $stash;
$link .= " " . ldopts( "-std", \@mods );
}
else {
$link .= " " . ldopts("-std");
}
if ($debug) {
$link .= " /DEBUG";
}
$link .= " perl5$Config{PERL_VERSION}.lib kernel32.lib msvcrt.lib";
debug("running $Config{cc} $compile");
system("$Config{cc} $compile");
debug("running $Config{ld} $link");
system("$Config{ld} $link");
}
if ( $^O =~ m/^MSWin/ && $Config{cc} =~ m/^cl/i ) {
cc_harness_msvc(@ARGV);
exit;
}
# ActivePerl 5.10.0.1004 claims to use MSVC6 but used MSVC8
#if ($Config::Config{ccversion} eq '12.0.8804' and $Config::Config{cc} eq 'cl') {
# $linkargs =~ s/ -opt:ref,icf//;
#}
my $ccflags = $Config{ccflags};
# crashes on cygwin
if ( $^O eq 'cygwin' and $ccflags =~ /-fstack-protector\b/ and $linkargs =~ /-fstack-protector\b/ ) {
$linkargs =~ s/-fstack-protector\b//;
}
#-pedantic -Wextra -Wconversion
if ( $debug and $Config{cc} =~ /gcc/ ) {
$ccflags .= " -ansi -Wall -Wshadow -Wcast-qual -Wwrite-strings"
if !$quiet;
# remove conflicting flags, esp. -s for strip
$ccflags =~ s/ -O.? / /;
$ccflags =~ s/ -s / /;
$linkargs =~ s/-s / /;
}
$ccflags .= " --no-warn -Wl,--warn-once"
if $Config{cc} =~ /gcc/
and $quiet
and $^O ne 'darwin';
$ccflags .= $B::C::Flags::extra_cflags;
my $cccmd = "$Config{cc} $ccflags -I$coredir @ARGV $linkargs";
$cccmd =~ s/\t/ /msg;
$cccmd =~ s/\s\s+/ /msg;
debug("Running: $cccmd");
exec $cccmd;
Back to Directory
File Manager