#!./perl -w
BEGIN {
require
"./test.pl"
;
unshift
@INC
,
".."
if
-f
"../TestInit.pm"
;
}
if
(
$Config
{
'usecrosscompile'
} && !can_run(
$Config
{
'cc'
})) {
skip_all(
"compiler not available (cross-compiling)"
);
}
else
{
plan(
tests
=> 1);
}
my
$VERBOSE
=
grep
{
$_
eq
'-v'
}
@ARGV
;
ok(try_compile_and_link(
<<'CODE'));
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
int main(int argc, char **argv) {
return 0;
}
CODE
sub
try_compile_and_link {
my
(
$c
,
%args
) =
@_
;
my
$ld_exeext
= ($^O eq
'cygwin'
|| $^O eq
'MSWin32'
||
$^O eq
'os2'
&&
$Config
{ldflags} =~ /-Zexe\b/) ?
'.exe'
:
(($^O eq
'vos'
) ?
$Config
{exe_ext} :
''
);
my
(
$ok
) = 0;
my
$tempdir
= tempfile();
my
$cwd
= getcwd();
mkdir
$tempdir
;
chdir
$tempdir
;
my
(
$tmp
) =
"temp"
;
my
$obj_ext
=
$Config
{obj_ext} ||
".o"
;
if
(
open
(
my
$tmpc
,
">$tmp.c"
)) {
print
$tmpc
$c
;
unless
(
close
(
$tmpc
)) {
chdir
(
$cwd
);
rmtree(
$tempdir
);
warn
"Failing closing code file: $!\n"
if
$VERBOSE
;
return
0;
}
my
$COREincdir
=
File::Spec->catdir(File::Spec->updir, File::Spec->updir);
my
$ccflags
=
$Config
{
'ccflags'
} .
' '
.
"-I$COREincdir"
.
' -DPERL_NO_INLINE_FUNCTIONS'
;
if
($^O eq
"MSWin32"
) {
$ccflags
.=
" -I../../win32 -I../../win32/include"
;
}
my
$libs
=
''
;
if
($^O eq
"MSWin32"
&&
$Config
{cc} =~ /\bcl\b/i) {
$libs
=
" /link $Config{'libs'}"
;
}
my
$null
= File::Spec->devnull;
my
$errornull
=
$VERBOSE
?
''
:
">$null 2>$null"
;
my
$out_opt
=
"-o "
;
if
($^O eq
"MSWin32"
&&
$Config
{cc} =~ /\bcl\b/i) {
$out_opt
=
"/Fe"
;
}
my
$tmp_exe
=
"$tmp$ld_exeext"
;
my
$cccmd
=
"$Config{'cc'} $out_opt$tmp_exe $ccflags $tmp.c $libs $errornull"
;
if
($^O eq
'VMS'
) {
$cccmd
=
"$Config{'cc'} /include=($COREincdir) $tmp.c"
;
}
if
($^O eq
'VMS'
) {
open
(
my
$cmdfile
,
">$tmp.com"
);
print
$cmdfile
"\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n"
;
print
$cmdfile
"\$ $cccmd\n"
;
print
$cmdfile
"\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"
;
close
$cmdfile
;
system
(
"\@ $tmp.com"
);
$ok
= $?==0;
chdir
(
$cwd
);
rmtree(
$tempdir
);
}
else
{
printf
"cccmd = $cccmd\n"
if
$VERBOSE
;
my
$res
=
system
(
$cccmd
);
$ok
=
defined
(
$res
) &&
$res
== 0 && -s
$tmp_exe
&& -x _;
chdir
(
$cwd
);
rmtree(
$tempdir
);
}
}
return
$ok
;
}