4 if( $ENV{PERL_CORE} ) {
15 open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
21 my $cc = $Config{'cc'};
22 my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
23 my $borl = ($^O eq 'MSWin32' && $cc eq 'bcc32');
24 my $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/;
25 my $exe = 'embed_test';
26 $exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it
27 my $obj = 'embed_test' . $Config{'obj_ext'};
28 my $inc = File::Spec->updir;
29 my $lib = File::Spec->updir;
33 my (@cmd2) if $^O eq 'VMS';
36 push(@cmd,$cc,"/Obj=$obj");
39 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
42 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
45 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
46 push(@cmd,"/Include=(".join(',',@incs).")");
48 push(@cmd,"embed_test.c");
50 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
51 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
55 push(@cmd,$cc,"-Fe$exe");
58 push(@cmd,$cc,"-o$exe");
61 push(@cmd,$cc,'-o' => $exe);
63 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
64 if ($^O eq 'MSWin32') {
65 $inc = File::Spec->catdir($inc,'win32');
67 $inc = File::Spec->catdir($inc,'include');
70 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'});
73 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
77 push(@cmd,"-L$lib",'-lperl');
78 local $SIG{__WARN__} = sub {
79 warn $_[0] unless $_[0] =~ /No library found for .*perl/
81 push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
82 if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
86 @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd]));
89 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
90 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
91 die "where is perl.exp?\n" unless defined $perl_exp;
93 s!-bE:(\S+)!-bE:$perl_exp!;
96 elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied
97 my $v_e_r_s = $Config{version};
99 system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1
101 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
102 # Everyone needs libperl copied if it's not found by '-lperl'.
103 $testlib = $Config{'libperl'};
104 my $srclib = $testlib;
105 $testlib =~ s/.+(?=\.[^.]*)/libperl/;
106 $testlib = File::Spec::->catfile($lib, $testlib);
107 $srclib = File::Spec::->catfile($lib, $srclib);
109 unlink $testlib if -f $testlib;
110 my $ln_or_cp = $Config{'ln'} || $Config{'cp'};
111 my $lncmd = "$ln_or_cp $srclib $testlib";
113 $libperl_copied = 1 unless system($lncmd);
118 # On OS/2 the linker will always emit an empty line to STDOUT; filter these
119 my $cmd = join ' ', @cmd;
120 chomp($cmd); # where is the newline coming from? ldopts()?
124 print "# $_\n" foreach @out;
126 if ($^O eq 'VMS' && !$status) {
128 $status = system(join(' ',@cmd2));
130 print (($status? 'not ': '')."ok 1\n");
132 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
133 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
134 print "# embed_test = $embed_test\n";
135 $status = system($embed_test);
136 print (($status? 'not ':'')."ok 9 # system returned $status\n");
137 unlink($exe,"embed_test.c",$obj);
138 unlink("$exe$Config{exe_ext}") if $skip_exe;
139 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
140 unlink(glob("./*.dll")) if $^O eq 'cygwin';
141 unlink($testlib) if $libperl_copied;
143 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
152 #define my_puts(a) if(puts(a) < 0) exit(666)
154 static char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
156 int main(int argc, char **argv, char **env)
158 PerlInterpreter *my_perl;
160 PERL_SYS_INIT3(&argc,&argv,&env);
162 my_perl = perl_alloc();
166 perl_construct(my_perl);
170 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
180 perl_destruct(my_perl);