#!/usr/bin/perl
BEGIN {
if
(
$ENV
{PERL_CORE} ) {
chdir
't'
if
-d
't'
;
@INC
=
'../lib'
;
}
}
chdir
't'
;
my
$cc
=
$Config
{
'cc'
};
if
(
$Config
{usecrosscompile} && !can_run(
$cc
) ) {
print
"1..0 # SKIP Cross-compiling and the target doesn't have $cc"
;
exit
;
}
if
(
ord
(
"A"
) != 65) {
print
"1..0 # SKIP EBCDIC platform doesn't currently work"
;
exit
;
}
open
(
my
$fh
,
">embed_test.c"
) ||
die
"Cannot open embed_test.c:$!"
;
print
$fh
<DATA>;
close
(
$fh
);
$| = 1;
print
"1..10\n"
;
my
$cl
= ($^O eq
'MSWin32'
&&
$cc
eq
'cl'
);
my
$skip_exe
= $^O eq
'os2'
&&
$Config
{ldflags} =~ /(?<!\S)-Zexe\b/;
my
$exe
=
'embed_test'
;
$exe
.=
$Config
{
'exe_ext'
}
unless
$skip_exe
;
my
$obj
=
'embed_test'
.
$Config
{
'obj_ext'
};
my
$inc
= File::Spec->updir;
my
$lib
= File::Spec->updir;
my
$libperl_copied
;
my
$testlib
;
my
@cmd
;
my
(
@cmd2
)
if
$^O eq
'VMS'
;
if
($^O eq
'VMS'
) {
push
(
@cmd
,
$cc
,
"/Obj=$obj"
);
my
(
@incs
) = (
$inc
);
my
$crazy
= ccflags();
if
(
$crazy
=~ s
push
(
@incs
,$1);
}
if
(
$crazy
=~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
push
(
@incs
,$1);
}
$crazy
=~ s
push
(
@cmd
,
"/Include=("
.
join
(
','
,
@incs
).
")"
);
push
(
@cmd
,
$crazy
);
push
(
@cmd
,
"embed_test.c"
);
push
(
@cmd2
,
$Config
{
'ld'
},
$Config
{
'ldflags'
},
"/exe=$exe"
);
push
(
@cmd2
,
"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt"
);
}
else
{
if
(
$cl
) {
push
(
@cmd
,
$cc
,
"-Fe$exe"
);
}
else
{
push
(
@cmd
,
$cc
,
'-o'
=>
$exe
);
}
if
($^O eq
'dec_osf'
&& !
defined
$Config
{usedl}) {
push
@cmd
,
"-non_shared"
;
}
my
$ccflags
= ccflags();
$ccflags
=~ s/-D_FORTIFY_SOURCE=\d+//
if
$Config
{optimize} =~ /-O/;
push
(
@cmd
,
"-I$inc"
,
$ccflags
,
'embed_test.c'
);
if
($^O eq
'MSWin32'
) {
$inc
= File::Spec->catdir(
$inc
,
'win32'
);
push
(
@cmd
,
"-I$inc"
);
my
$full
= File::Spec->catdir(
$inc
,
'full'
);
push
(
@cmd
,
"-I$full"
);
$inc
= File::Spec->catdir(
$inc
,
'include'
);
push
(
@cmd
,
"-I$inc"
);
if
(
$cc
eq
'cl'
) {
push
(
@cmd
,
'-link'
,
"-libpath:$lib\\lib\\CORE"
,
$Config
{
'libperl'
},
$Config
{
'libs'
});
}
else
{
push
(
@cmd
,
"-L$lib"
,
$lib
.
'\lib\CORE\\'
.
$Config
{
'libperl'
},
$Config
{
'libc'
});
}
}
elsif
($^O eq
'os390'
&&
$Config
{usedl}) {
push
(
@cmd
,
"-L$lib"
, ldopts());
}
else
{
push
(
@cmd
,
"-L$lib"
,
'-lperl'
);
local
$SIG
{__WARN__} =
sub
{
warn
$_
[0]
unless
$_
[0] =~ /No library found
for
.
*perl
/
};
push
(
@cmd
,
'-Zlinker'
,
'/PM:VIO'
)
if
$^O eq
'os2'
and
$Config
{ldflags} =~ /(?<!\S)-Zomf\b/;
push
(
@cmd
,ldopts());
}
if
($^O eq
'aix'
) {
my
(
$perl_exp
) =
grep
{ -f }
qw(perl.exp ../perl.exp)
;
die
"where is perl.exp?\n"
unless
defined
$perl_exp
;
for
(
@cmd
) {
s!-bE:(\S+)!-bE:
$perl_exp
!;
}
}
elsif
($^O eq
'cygwin'
) {
;
}
elsif
(
$Config
{
'libperl'
} !~ /\Alibperl\./) {
$testlib
=
$Config
{
'libperl'
};
my
$srclib
=
$testlib
;
$testlib
=~ s/.+(?=\.[^.]*)/libperl/;
$testlib
= File::Spec::->catfile(
$lib
,
$testlib
);
$srclib
= File::Spec::->catfile(
$lib
,
$srclib
);
if
(-f
$srclib
) {
unlink
$testlib
if
-f
$testlib
;
my
$ln_or_cp
=
$Config
{
'ln'
} ||
$Config
{
'cp'
};
my
$lncmd
=
"$ln_or_cp $srclib $testlib"
;
$libperl_copied
= 1
unless
system
(
$lncmd
);
}
}
}
my
$status
;
my
$cmd
=
join
' '
,
@cmd
;
chomp
(
$cmd
);
print
"# $cmd\n"
;
my
@out
= `
$cmd
`;
$status
= $?;
print
"# $_\n"
foreach
@out
;
if
($^O eq
'VMS'
&& !
$status
) {
print
"# @cmd2\n"
;
$status
=
system
(
join
(
' '
,
@cmd2
));
}
print
((
$status
?
'not '
:
''
).
"ok 1\n"
);
my
$embed_test
= File::Spec->catfile(File::Spec->curdir,
$exe
);
$embed_test
=
"run/nodebug $exe"
if
$^O eq
'VMS'
;
print
"# embed_test = $embed_test\n"
;
$status
=
system
(
$embed_test
);
print
((
$status
?
'not '
:
''
).
"ok 10 # system returned $status\n"
);
unlink
(
$exe
,
"embed_test.c"
,
$obj
);
unlink
(
"$exe.manifest"
)
if
$cl
and
$Config
{
'ccversion'
} =~ /^(\d+)/ and $1 >= 14;
unlink
(
"$exe$Config{exe_ext}"
)
if
$skip_exe
;
unlink
(
"embed_test.map"
,
"embed_test.lis"
)
if
$^O eq
'VMS'
;
unlink
(
glob
(
"./*.dll"
))
if
$^O eq
'cygwin'
;
unlink
(
$testlib
)
if
$libperl_copied
;