5 unshift @INC, '../lib';
11 open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
17 my $cc = $Config{'cc'};
18 my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
19 my $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/;
20 my $exe = 'embed_test';
21 $exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it
22 my $obj = 'embed_test' . $Config{'obj_ext'};
23 my $inc = File::Spec->updir;
24 my $lib = File::Spec->updir;
28 my (@cmd2) if $^O eq 'VMS';
31 push(@cmd,$cc,"/Obj=$obj");
34 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
37 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
40 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
41 push(@cmd,"/Include=(".join(',',@incs).")");
43 push(@cmd,"embed_test.c");
45 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
46 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
50 push(@cmd,$cc,"-Fe$exe");
53 push(@cmd,$cc,'-o' => $exe);
55 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
56 if ($^O eq 'MSWin32') {
57 $inc = File::Spec->catdir($inc,'win32');
59 $inc = File::Spec->catdir($inc,'include');
62 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
65 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
69 push(@cmd,"-L$lib",'-lperl');
72 local $SIG{__WARN__} = sub {
73 warn $_[0] unless $_[0] =~ /No library found for -lperl/
75 push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
76 if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
80 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
81 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
82 die "where is perl.exp?\n" unless defined $perl_exp;
84 s!-bE:(\S+)!-bE:$perl_exp!;
87 elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied
88 my $v_e_r_s = $Config{version};
90 system("cp ../libperl$v_e_r_s.dll ./"); # for test 1
91 system("cp ../$Config{'libperl'} ../libperl.a"); # for test 1
93 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
94 # Everyone needs libperl copied if it's not found by '-lperl'.
95 $testlib = $Config{'libperl'};
96 my $srclib = $testlib;
97 $testlib =~ s/^[^.]+/libperl/;
98 $testlib = File::Spec::->catfile($lib, $testlib);
99 $srclib = File::Spec::->catfile($lib, $srclib);
101 unlink $testlib if -f $testlib;
102 my $lncmd = "$Config{'ln'} $srclib $testlib";
104 $libperl_copied = 1 unless system($lncmd);
109 my $display_cmd = "@cmd";
110 chomp($display_cmd); # where is the newline coming from? ldopts()?
111 print "# $display_cmd\n";
112 $status = system(join(' ',@cmd));
113 if ($^O eq 'VMS' && !$status) {
115 $status = system(join(' ',@cmd2));
117 print (($status? 'not ': '')."ok 1\n");
119 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
120 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
121 print "# embed_test = $embed_test\n";
122 $status = system($embed_test);
123 print (($status? 'not ':'')."ok 9 # $status\n");
124 unlink($exe,"embed_test.c",$obj);
125 unlink("$exe$Config{exe_ext}") if $skip_exe;
126 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
127 unlink(glob("./libperl*.dll")) if $^O eq 'cygwin';
128 unlink("../libperl.a") if $^O eq 'cygwin';
129 unlink($testlib) if $libperl_copied;
131 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
140 #define my_puts(a) if(puts(a) < 0) exit(666)
142 char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
144 int main(int argc, char **argv, char **env)
146 PerlInterpreter *my_perl = perl_alloc();
150 perl_construct(my_perl);
154 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
164 perl_destruct(my_perl);