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