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