Thread::Queue 2.03
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Embed.t
CommitLineData
39234879 1#!/usr/bin/perl
f1feeb72 2
3BEGIN {
39234879 4 if( $ENV{PERL_CORE} ) {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
f1feeb72 8}
39234879 9chdir 't';
10
f1feeb72 11use Config;
12use ExtUtils::Embed;
1091dea4 13use File::Spec;
f1feeb72 14
15open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
16print $fh <DATA>;
17close($fh);
18
19$| = 1;
20print "1..9\n";
1091dea4 21my $cc = $Config{'cc'};
22my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
2a8c1a1c 23my $borl = ($^O eq 'MSWin32' && $cc eq 'bcc32');
dfcfdb64 24my $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/;
25my $exe = 'embed_test';
26$exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it
9fb80172 27my $obj = 'embed_test' . $Config{'obj_ext'};
21f7eeb2 28my $inc = File::Spec->updir;
29my $lib = File::Spec->updir;
88eeb692 30my $libperl_copied;
31my $testlib;
1091dea4 32my @cmd;
20ebe338 33my (@cmd2) if $^O eq 'VMS';
92a665d6 34# Don't use ccopts() here as we may want to overwrite an existing
35# perl with a new one with inconsistent header files, meaning
36# the usual value for perl_inc(), which is used by ccopts(),
37# will be wrong.
20ebe338 38if ($^O eq 'VMS') {
39 push(@cmd,$cc,"/Obj=$obj");
40 my (@incs) = ($inc);
92a665d6 41 my $crazy = ccflags();
20ebe338 42 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
43 push(@incs,$1);
44 }
45 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
46 push(@incs,$1);
47 }
48 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
49 push(@cmd,"/Include=(".join(',',@incs).")");
50 push(@cmd,$crazy);
51 push(@cmd,"embed_test.c");
52
53 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
54 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
55
56} else {
57 if ($cl) {
1091dea4 58 push(@cmd,$cc,"-Fe$exe");
20ebe338 59 }
2a8c1a1c 60 elsif ($borl) {
61 push(@cmd,$cc,"-o$exe");
62 }
20ebe338 63 else {
1091dea4 64 push(@cmd,$cc,'-o' => $exe);
20ebe338 65 }
14270b7a 66 if ($^O eq 'dec_osf' && !defined $Config{usedl}) {
67 # The -non_shared is needed in case of -Uusedl or otherwise
68 # the test application will try to use libperl.so
69 # instead of libperl.a.
70 push @cmd, "-non_shared";
71 }
92a665d6 72
73 push(@cmd,"-I$inc",ccflags(),'embed_test.c');
20ebe338 74 if ($^O eq 'MSWin32') {
b1b2427f 75 $inc = File::Spec->catdir($inc,'win32');
1091dea4 76 push(@cmd,"-I$inc");
b1b2427f 77 $inc = File::Spec->catdir($inc,'include');
1091dea4 78 push(@cmd,"-I$inc");
79 if ($cc eq 'cl') {
c623ac67 80 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'});
1091dea4 81 }
82 else {
67bfc918 83 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
1091dea4 84 }
20ebe338 85 }
2f3efc97 86 elsif ($^O eq 'os390' && $Config{usedl}) {
87 # Nothing for OS/390 (z/OS) dynamic.
88 } else { # Not MSWin32 or OS/390 (z/OS) dynamic.
1091dea4 89 push(@cmd,"-L$lib",'-lperl');
fee3faea 90 local $SIG{__WARN__} = sub {
c623ac67 91 warn $_[0] unless $_[0] =~ /No library found for .*perl/
fee3faea 92 };
dfcfdb64 93 push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
94 if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
fee3faea 95 push(@cmd,ldopts());
20ebe338 96 }
2a8c1a1c 97 if ($borl) {
98 @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd]));
99 }
1091dea4 100
20ebe338 101 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
f490490f 102 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
103 die "where is perl.exp?\n" unless defined $perl_exp;
104 for (@cmd) {
105 s!-bE:(\S+)!-bE:$perl_exp!;
106 }
88eeb692 107 }
b53432e4 108 elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied
41f1c18b 109 my $v_e_r_s = $Config{version};
110 $v_e_r_s =~ tr/./_/;
b53432e4 111 system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1
20ebe338 112 }
88eeb692 113 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
114 # Everyone needs libperl copied if it's not found by '-lperl'.
115 $testlib = $Config{'libperl'};
116 my $srclib = $testlib;
c72f2af0 117 $testlib =~ s/.+(?=\.[^.]*)/libperl/;
88eeb692 118 $testlib = File::Spec::->catfile($lib, $testlib);
119 $srclib = File::Spec::->catfile($lib, $srclib);
120 if (-f $srclib) {
121 unlink $testlib if -f $testlib;
c7e0473b 122 my $ln_or_cp = $Config{'ln'} || $Config{'cp'};
123 my $lncmd = "$ln_or_cp $srclib $testlib";
88eeb692 124 #print "# $lncmd\n";
125 $libperl_copied = 1 unless system($lncmd);
126 }
127 }
f490490f 128}
20ebe338 129my $status;
b2213df5 130# On OS/2 the linker will always emit an empty line to STDOUT; filter these
2bf35fab 131my $cmd = join ' ', @cmd;
132chomp($cmd); # where is the newline coming from? ldopts()?
133print "# $cmd\n";
134my @out = `$cmd`;
135$status = $?;
136print "# $_\n" foreach @out;
b2213df5 137
20ebe338 138if ($^O eq 'VMS' && !$status) {
139 print "# @cmd2\n";
140 $status = system(join(' ',@cmd2));
141}
142print (($status? 'not ': '')."ok 1\n");
3be77bcf 143
144d6c83 144my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
20ebe338 145$embed_test = "run/nodebug $exe" if $^O eq 'VMS';
144d6c83 146print "# embed_test = $embed_test\n";
20ebe338 147$status = system($embed_test);
7d63dedd 148print (($status? 'not ':'')."ok 9 # system returned $status\n");
9fb80172 149unlink($exe,"embed_test.c",$obj);
d59896ca 150unlink("$exe.manifest") if $cl and $Config{'ccversion'} =~ /^(\d+)/ and $1 >= 14;
dfcfdb64 151unlink("$exe$Config{exe_ext}") if $skip_exe;
9fb80172 152unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
b53432e4 153unlink(glob("./*.dll")) if $^O eq 'cygwin';
88eeb692 154unlink($testlib) if $libperl_copied;
f1feeb72 155
92a665d6 156# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccflags -e ldopts`
f1feeb72 157__END__
158
159/* perl_test.c */
160
161#include <EXTERN.h>
162#include <perl.h>
163
164#define my_puts(a) if(puts(a) < 0) exit(666)
165
9ac9d386 166static char *cmds[] = { "perl","-e", "$|=1; print qq[ok 5\\n]", NULL };
f1feeb72 167
27da23d5 168#ifdef PERL_GLOBAL_STRUCT_PRIVATE
169static struct perl_vars *my_plvarsp;
170struct perl_vars* Perl_GetVarsPrivate(void) { return my_plvarsp; }
171#endif
172
2f3efc97 173#ifdef NO_ENV_ARRAY_IN_MAIN
174extern char **environ;
175int main(int argc, char **argv)
176#else
f1feeb72 177int main(int argc, char **argv, char **env)
2f3efc97 178#endif
f1feeb72 179{
1ccffcf5 180 PerlInterpreter *my_perl;
27da23d5 181#ifdef PERL_GLOBAL_STRUCT
182 dVAR;
183 struct perl_vars *plvarsp = init_global_struct();
184# ifdef PERL_GLOBAL_STRUCT_PRIVATE
185 my_vars = my_plvarsp = plvarsp;
186# endif
187#endif /* PERL_GLOBAL_STRUCT */
b7787f18 188
189 (void)argc; /* PERL_SYS_INIT3 may #define away their use */
190 (void)argv;
2f3efc97 191#ifdef NO_ENV_ARRAY_IN_MAIN
192 PERL_SYS_INIT3(&argc,&argv,&environ);
193#else
1ccffcf5 194 PERL_SYS_INIT3(&argc,&argv,&env);
2f3efc97 195#endif
1ccffcf5 196
197 my_perl = perl_alloc();
f1feeb72 198
199 my_puts("ok 2");
200
201 perl_construct(my_perl);
202
203 my_puts("ok 3");
204
2f3efc97 205#ifdef NO_ENV_ARRAY_IN_MAIN
206 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, environ);
207#else
f1feeb72 208 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
2f3efc97 209#endif
f1feeb72 210
211 my_puts("ok 4");
212
213 fflush(stdout);
214
215 perl_run(my_perl);
216
217 my_puts("ok 6");
218
219 perl_destruct(my_perl);
220
221 my_puts("ok 7");
222
223 perl_free(my_perl);
224
27da23d5 225#ifdef PERL_GLOBAL_STRUCT
226 free_global_struct(plvarsp);
227#endif /* PERL_GLOBAL_STRUCT */
228
f1feeb72 229 my_puts("ok 8");
230
1ccffcf5 231 PERL_SYS_TERM();
232
f1feeb72 233 return 0;
234}