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 $exe = 'embed_test' . $Config{'exe_ext'};
20 my $obj = 'embed_test' . $Config{'obj_ext'};
21 my $inc = File::Spec->updir;
22 my $lib = File::Spec->updir;
26 my (@cmd2) if $^O eq 'VMS';
29 push(@cmd,$cc,"/Obj=$obj");
32 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
35 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
38 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
39 push(@cmd,"/Include=(".join(',',@incs).")");
41 push(@cmd,"embed_test.c");
43 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
44 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
48 push(@cmd,$cc,"-Fe$exe");
51 push(@cmd,$cc,'-o' => $exe);
53 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
54 if ($^O eq 'MSWin32') {
55 $inc = File::Spec->catdir($inc,'win32');
57 $inc = File::Spec->catdir($inc,'include');
60 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
63 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
67 push(@cmd,"-L$lib",'-lperl');
70 local $SIG{__WARN__} = sub {
71 warn $_[0] unless $_[0] =~ /No library found for -lperl/
76 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
77 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
78 die "where is perl.exp?\n" unless defined $perl_exp;
80 s!-bE:(\S+)!-bE:$perl_exp!;
83 elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied
84 my $v_e_r_s = $Config{version};
86 system("cp ../libperl$v_e_r_s.dll ./"); # for test 1
87 system("cp ../$Config{'libperl'} ../libperl.a"); # for test 1
89 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
90 # Everyone needs libperl copied if it's not found by '-lperl'.
91 $testlib = $Config{'libperl'};
92 my $srclib = $testlib;
93 $testlib =~ s/^[^.]+/libperl/;
94 $testlib = File::Spec::->catfile($lib, $testlib);
95 $srclib = File::Spec::->catfile($lib, $srclib);
97 unlink $testlib if -f $testlib;
98 my $lncmd = "$Config{'ln'} $srclib $testlib";
100 $libperl_copied = 1 unless system($lncmd);
105 my $display_cmd = "@cmd";
106 chomp($display_cmd); # where is the newline coming from? ldopts()?
107 print "# $display_cmd\n";
108 $status = system(join(' ',@cmd));
109 if ($^O eq 'VMS' && !$status) {
111 $status = system(join(' ',@cmd2));
113 print (($status? 'not ': '')."ok 1\n");
115 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
116 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
117 print "# embed_test = $embed_test\n";
118 $status = system($embed_test);
119 print (($status? 'not ':'')."ok 9 # $status\n");
120 unlink($exe,"embed_test.c",$obj);
121 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
122 unlink(glob("./libperl*.dll")) if $^O eq 'cygwin';
123 unlink("../libperl.a") if $^O eq 'cygwin';
124 unlink($testlib) if $libperl_copied;
126 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
135 #define my_puts(a) if(puts(a) < 0) exit(666)
137 char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
139 int main(int argc, char **argv, char **env)
141 PerlInterpreter *my_perl = perl_alloc();
145 perl_construct(my_perl);
149 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
159 perl_destruct(my_perl);