This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Apply NetBSD patch-ae: another gcc sparc64 bug.
[perl5.git] / lib / ExtUtils / Embed.t
CommitLineData
f1feeb72
NIS
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
NIS
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
NIS
17my $cc = $Config{'cc'};
18my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
b1b2427f 19my $exe = 'embed_test' . $Config{'exe_ext'};
9fb80172 20my $obj = 'embed_test' . $Config{'obj_ext'};
21f7eeb2
JH
21my $inc = File::Spec->updir;
22my $lib = File::Spec->updir;
1091dea4 23my @cmd;
20ebe338
CL
24my (@cmd2) if $^O eq 'VMS';
25
26if ($^O eq 'VMS') {
27 push(@cmd,$cc,"/Obj=$obj");
28 my (@incs) = ($inc);
29 my $crazy = ccopts();
30 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
31 push(@incs,$1);
32 }
33 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
34 push(@incs,$1);
35 }
36 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
37 push(@cmd,"/Include=(".join(',',@incs).")");
38 push(@cmd,$crazy);
39 push(@cmd,"embed_test.c");
40
41 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
42 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
43
44} else {
45 if ($cl) {
1091dea4 46 push(@cmd,$cc,"-Fe$exe");
20ebe338
CL
47 }
48 else {
1091dea4 49 push(@cmd,$cc,'-o' => $exe);
20ebe338
CL
50 }
51 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
52 if ($^O eq 'MSWin32') {
b1b2427f 53 $inc = File::Spec->catdir($inc,'win32');
1091dea4 54 push(@cmd,"-I$inc");
b1b2427f 55 $inc = File::Spec->catdir($inc,'include');
1091dea4
NIS
56 push(@cmd,"-I$inc");
57 if ($cc eq 'cl') {
b1b2427f 58 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
1091dea4
NIS
59 }
60 else {
67bfc918 61 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
1091dea4 62 }
20ebe338
CL
63 }
64 else {
1091dea4 65 push(@cmd,"-L$lib",'-lperl');
20ebe338
CL
66 }
67 {
fee3faea
RGS
68 local $SIG{__WARN__} = sub {
69 warn $_[0] unless $_[0] =~ /No library found for -lperl/
70 };
71 push(@cmd,ldopts());
20ebe338 72 }
1091dea4 73
20ebe338 74 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
f490490f
JH
75 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
76 die "where is perl.exp?\n" unless defined $perl_exp;
77 for (@cmd) {
78 s!-bE:(\S+)!-bE:$perl_exp!;
79 }
144d6c83 80 } elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied
41f1c18b
GH
81 my $v_e_r_s = $Config{version};
82 $v_e_r_s =~ tr/./_/;
83 system("cp ../libperl$v_e_r_s.dll ./"); # for test 1
84 system("cp ../$Config{'libperl'} ../libperl.a"); # for test 1
20ebe338 85 }
f490490f 86}
20ebe338 87my $status;
8fe5b9ff
JH
88my $display_cmd = "@cmd";
89chomp($display_cmd); # where is the newline coming from? ldopts()?
90print "# $display_cmd\n";
20ebe338
CL
91$status = system(join(' ',@cmd));
92if ($^O eq 'VMS' && !$status) {
93 print "# @cmd2\n";
94 $status = system(join(' ',@cmd2));
95}
96print (($status? 'not ': '')."ok 1\n");
3be77bcf 97
144d6c83 98my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
20ebe338 99$embed_test = "run/nodebug $exe" if $^O eq 'VMS';
144d6c83 100print "# embed_test = $embed_test\n";
20ebe338 101$status = system($embed_test);
144d6c83 102print (($status? 'not ':'')."ok 9 # $status\n");
9fb80172
GS
103unlink($exe,"embed_test.c",$obj);
104unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
41f1c18b
GH
105unlink(glob("./libperl*.dll")) if $^O eq 'cygwin';
106unlink("../libperl.a") if $^O eq 'cygwin';
f1feeb72 107
94597104 108# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
f1feeb72
NIS
109
110__END__
111
112/* perl_test.c */
113
114#include <EXTERN.h>
115#include <perl.h>
116
117#define my_puts(a) if(puts(a) < 0) exit(666)
118
119char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
120
121int main(int argc, char **argv, char **env)
122{
123 PerlInterpreter *my_perl = perl_alloc();
124
125 my_puts("ok 2");
126
127 perl_construct(my_perl);
128
129 my_puts("ok 3");
130
131 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
132
133 my_puts("ok 4");
134
135 fflush(stdout);
136
137 perl_run(my_perl);
138
139 my_puts("ok 6");
140
141 perl_destruct(my_perl);
142
143 my_puts("ok 7");
144
145 perl_free(my_perl);
146
147 my_puts("ok 8");
148
149 return 0;
150}
151
152
153
154