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