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 $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/;
24 my $exe = 'embed_test';
25 $exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it
26 my $obj = 'embed_test' . $Config{'obj_ext'};
27 my $inc = File::Spec->updir;
28 my $lib = File::Spec->updir;
32 my (@cmd2) if $^O eq 'VMS';
35 push(@cmd,$cc,"/Obj=$obj");
38 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
41 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
44 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
45 push(@cmd,"/Include=(".join(',',@incs).")");
47 push(@cmd,"embed_test.c");
49 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
50 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
54 push(@cmd,$cc,"-Fe$exe");
57 push(@cmd,$cc,'-o' => $exe);
59 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
60 if ($^O eq 'MSWin32') {
61 $inc = File::Spec->catdir($inc,'win32');
63 $inc = File::Spec->catdir($inc,'include');
66 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
69 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
73 push(@cmd,"-L$lib",'-lperl');
76 local $SIG{__WARN__} = sub {
77 warn $_[0] unless $_[0] =~ /No library found for -lperl/
79 push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
80 if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
84 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
85 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
86 die "where is perl.exp?\n" unless defined $perl_exp;
88 s!-bE:(\S+)!-bE:$perl_exp!;
91 elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied
92 my $v_e_r_s = $Config{version};
94 system("cp ../libperl$v_e_r_s.dll ./"); # for test 1
95 system("cp ../$Config{'libperl'} ../libperl.a"); # for test 1
97 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
98 # Everyone needs libperl copied if it's not found by '-lperl'.
99 $testlib = $Config{'libperl'};
100 my $srclib = $testlib;
101 $testlib =~ s/^[^.]+/libperl/;
102 $testlib = File::Spec::->catfile($lib, $testlib);
103 $srclib = File::Spec::->catfile($lib, $srclib);
105 unlink $testlib if -f $testlib;
106 my $ln_or_cp = $Config{'ln'} || $Config{'cp'};
107 my $lncmd = "$ln_or_cp $srclib $testlib";
109 $libperl_copied = 1 unless system($lncmd);
114 my $display_cmd = "@cmd";
115 chomp($display_cmd); # where is the newline coming from? ldopts()?
116 print "# $display_cmd\n";
117 $status = system(join(' ',@cmd));
118 if ($^O eq 'VMS' && !$status) {
120 $status = system(join(' ',@cmd2));
122 print (($status? 'not ': '')."ok 1\n");
124 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
125 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
126 print "# embed_test = $embed_test\n";
127 $status = system($embed_test);
128 print (($status? 'not ':'')."ok 9 # $status\n");
129 unlink($exe,"embed_test.c",$obj);
130 unlink("$exe$Config{exe_ext}") if $skip_exe;
131 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
132 unlink(glob("./libperl*.dll")) if $^O eq 'cygwin';
133 unlink("../libperl.a") if $^O eq 'cygwin';
134 unlink($testlib) if $libperl_copied;
136 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
145 #define my_puts(a) if(puts(a) < 0) exit(666)
147 static char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
149 int main(int argc, char **argv, char **env)
151 PerlInterpreter *my_perl = perl_alloc();
155 perl_construct(my_perl);
159 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
169 perl_destruct(my_perl);