1*0Sstevel@tonic-gate#!/usr/bin/perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate if( $ENV{PERL_CORE} ) { 5*0Sstevel@tonic-gate chdir 't' if -d 't'; 6*0Sstevel@tonic-gate @INC = '../lib'; 7*0Sstevel@tonic-gate } 8*0Sstevel@tonic-gate} 9*0Sstevel@tonic-gatechdir 't'; 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gateuse Config; 12*0Sstevel@tonic-gateuse ExtUtils::Embed; 13*0Sstevel@tonic-gateuse File::Spec; 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gateopen(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!"; 16*0Sstevel@tonic-gateprint $fh <DATA>; 17*0Sstevel@tonic-gateclose($fh); 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gate$| = 1; 20*0Sstevel@tonic-gateprint "1..9\n"; 21*0Sstevel@tonic-gatemy $cc = $Config{'cc'}; 22*0Sstevel@tonic-gatemy $cl = ($^O eq 'MSWin32' && $cc eq 'cl'); 23*0Sstevel@tonic-gatemy $borl = ($^O eq 'MSWin32' && $cc eq 'bcc32'); 24*0Sstevel@tonic-gatemy $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/; 25*0Sstevel@tonic-gatemy $exe = 'embed_test'; 26*0Sstevel@tonic-gate$exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it 27*0Sstevel@tonic-gatemy $obj = 'embed_test' . $Config{'obj_ext'}; 28*0Sstevel@tonic-gatemy $inc = File::Spec->updir; 29*0Sstevel@tonic-gatemy $lib = File::Spec->updir; 30*0Sstevel@tonic-gatemy $libperl_copied; 31*0Sstevel@tonic-gatemy $testlib; 32*0Sstevel@tonic-gatemy @cmd; 33*0Sstevel@tonic-gatemy (@cmd2) if $^O eq 'VMS'; 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gateif ($^O eq 'VMS') { 36*0Sstevel@tonic-gate push(@cmd,$cc,"/Obj=$obj"); 37*0Sstevel@tonic-gate my (@incs) = ($inc); 38*0Sstevel@tonic-gate my $crazy = ccopts(); 39*0Sstevel@tonic-gate if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) { 40*0Sstevel@tonic-gate push(@incs,$1); 41*0Sstevel@tonic-gate } 42*0Sstevel@tonic-gate if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) { 43*0Sstevel@tonic-gate push(@incs,$1); 44*0Sstevel@tonic-gate } 45*0Sstevel@tonic-gate $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i; 46*0Sstevel@tonic-gate push(@cmd,"/Include=(".join(',',@incs).")"); 47*0Sstevel@tonic-gate push(@cmd,$crazy); 48*0Sstevel@tonic-gate push(@cmd,"embed_test.c"); 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe"); 51*0Sstevel@tonic-gate push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt"); 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate} else { 54*0Sstevel@tonic-gate if ($cl) { 55*0Sstevel@tonic-gate push(@cmd,$cc,"-Fe$exe"); 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate elsif ($borl) { 58*0Sstevel@tonic-gate push(@cmd,$cc,"-o$exe"); 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate else { 61*0Sstevel@tonic-gate push(@cmd,$cc,'-o' => $exe); 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate push(@cmd,"-I$inc",ccopts(),'embed_test.c'); 64*0Sstevel@tonic-gate if ($^O eq 'MSWin32') { 65*0Sstevel@tonic-gate $inc = File::Spec->catdir($inc,'win32'); 66*0Sstevel@tonic-gate push(@cmd,"-I$inc"); 67*0Sstevel@tonic-gate $inc = File::Spec->catdir($inc,'include'); 68*0Sstevel@tonic-gate push(@cmd,"-I$inc"); 69*0Sstevel@tonic-gate if ($cc eq 'cl') { 70*0Sstevel@tonic-gate push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'}); 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate else { 73*0Sstevel@tonic-gate push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate else { # Not MSWin32. 77*0Sstevel@tonic-gate push(@cmd,"-L$lib",'-lperl'); 78*0Sstevel@tonic-gate local $SIG{__WARN__} = sub { 79*0Sstevel@tonic-gate warn $_[0] unless $_[0] =~ /No library found for .*perl/ 80*0Sstevel@tonic-gate }; 81*0Sstevel@tonic-gate push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT! 82*0Sstevel@tonic-gate if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/; 83*0Sstevel@tonic-gate push(@cmd,ldopts()); 84*0Sstevel@tonic-gate } 85*0Sstevel@tonic-gate if ($borl) { 86*0Sstevel@tonic-gate @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd])); 87*0Sstevel@tonic-gate } 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate if ($^O eq 'aix') { # AIX needs an explicit symbol export list. 90*0Sstevel@tonic-gate my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp); 91*0Sstevel@tonic-gate die "where is perl.exp?\n" unless defined $perl_exp; 92*0Sstevel@tonic-gate for (@cmd) { 93*0Sstevel@tonic-gate s!-bE:(\S+)!-bE:$perl_exp!; 94*0Sstevel@tonic-gate } 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied 97*0Sstevel@tonic-gate my $v_e_r_s = $Config{version}; 98*0Sstevel@tonic-gate $v_e_r_s =~ tr/./_/; 99*0Sstevel@tonic-gate system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate elsif ($Config{'libperl'} !~ /\Alibperl\./) { 102*0Sstevel@tonic-gate # Everyone needs libperl copied if it's not found by '-lperl'. 103*0Sstevel@tonic-gate $testlib = $Config{'libperl'}; 104*0Sstevel@tonic-gate my $srclib = $testlib; 105*0Sstevel@tonic-gate $testlib =~ s/.+(?=\.[^.]*)/libperl/; 106*0Sstevel@tonic-gate $testlib = File::Spec::->catfile($lib, $testlib); 107*0Sstevel@tonic-gate $srclib = File::Spec::->catfile($lib, $srclib); 108*0Sstevel@tonic-gate if (-f $srclib) { 109*0Sstevel@tonic-gate unlink $testlib if -f $testlib; 110*0Sstevel@tonic-gate my $ln_or_cp = $Config{'ln'} || $Config{'cp'}; 111*0Sstevel@tonic-gate my $lncmd = "$ln_or_cp $srclib $testlib"; 112*0Sstevel@tonic-gate #print "# $lncmd\n"; 113*0Sstevel@tonic-gate $libperl_copied = 1 unless system($lncmd); 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate} 117*0Sstevel@tonic-gatemy $status; 118*0Sstevel@tonic-gate# On OS/2 the linker will always emit an empty line to STDOUT; filter these 119*0Sstevel@tonic-gatemy $cmd = join ' ', @cmd; 120*0Sstevel@tonic-gatechomp($cmd); # where is the newline coming from? ldopts()? 121*0Sstevel@tonic-gateprint "# $cmd\n"; 122*0Sstevel@tonic-gatemy @out = `$cmd`; 123*0Sstevel@tonic-gate$status = $?; 124*0Sstevel@tonic-gateprint "# $_\n" foreach @out; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gateif ($^O eq 'VMS' && !$status) { 127*0Sstevel@tonic-gate print "# @cmd2\n"; 128*0Sstevel@tonic-gate $status = system(join(' ',@cmd2)); 129*0Sstevel@tonic-gate} 130*0Sstevel@tonic-gateprint (($status? 'not ': '')."ok 1\n"); 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gatemy $embed_test = File::Spec->catfile(File::Spec->curdir, $exe); 133*0Sstevel@tonic-gate$embed_test = "run/nodebug $exe" if $^O eq 'VMS'; 134*0Sstevel@tonic-gateprint "# embed_test = $embed_test\n"; 135*0Sstevel@tonic-gate$status = system($embed_test); 136*0Sstevel@tonic-gateprint (($status? 'not ':'')."ok 9 # system returned $status\n"); 137*0Sstevel@tonic-gateunlink($exe,"embed_test.c",$obj); 138*0Sstevel@tonic-gateunlink("$exe$Config{exe_ext}") if $skip_exe; 139*0Sstevel@tonic-gateunlink("embed_test.map","embed_test.lis") if $^O eq 'VMS'; 140*0Sstevel@tonic-gateunlink(glob("./*.dll")) if $^O eq 'cygwin'; 141*0Sstevel@tonic-gateunlink($testlib) if $libperl_copied; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate__END__ 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate/* perl_test.c */ 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate#include <EXTERN.h> 150*0Sstevel@tonic-gate#include <perl.h> 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate#define my_puts(a) if(puts(a) < 0) exit(666) 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gatestatic char *cmds[] = { "perl","-e", "$|=1; print qq[ok 5\\n]", NULL }; 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gateint main(int argc, char **argv, char **env) 157*0Sstevel@tonic-gate{ 158*0Sstevel@tonic-gate PerlInterpreter *my_perl; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate PERL_SYS_INIT3(&argc,&argv,&env); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate my_perl = perl_alloc(); 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate my_puts("ok 2"); 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate perl_construct(my_perl); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate my_puts("ok 3"); 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate my_puts("ok 4"); 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate fflush(stdout); 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate perl_run(my_perl); 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate my_puts("ok 6"); 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate perl_destruct(my_perl); 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate my_puts("ok 7"); 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate perl_free(my_perl); 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate my_puts("ok 8"); 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate PERL_SYS_TERM(); 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate return 0; 191*0Sstevel@tonic-gate} 192