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