Allow several arguments to display().
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / 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');
b1b2427f 19my $exe = 'embed_test' . $Config{'exe_ext'};
9fb80172 20my $obj = 'embed_test' . $Config{'obj_ext'};
21f7eeb2 21my $inc = File::Spec->updir;
22my $lib = File::Spec->updir;
1091dea4 23my @cmd;
20ebe338 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 47 }
48 else {
1091dea4 49 push(@cmd,$cc,'-o' => $exe);
20ebe338 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 56 push(@cmd,"-I$inc");
57 if ($cc eq 'cl') {
b1b2427f 58 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
1091dea4 59 }
60 else {
67bfc918 61 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
1091dea4 62 }
20ebe338 63 }
64 else {
1091dea4 65 push(@cmd,"-L$lib",'-lperl');
20ebe338 66 }
67 {
fee3faea 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 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
e6de440e 81 system("cp ../$Config{'libperl'} ../libperl.dll"); # for test 1
20ebe338 82 }
f490490f 83}
20ebe338 84my $status;
8fe5b9ff 85my $display_cmd = "@cmd";
86chomp($display_cmd); # where is the newline coming from? ldopts()?
87print "# $display_cmd\n";
20ebe338 88$status = system(join(' ',@cmd));
89if ($^O eq 'VMS' && !$status) {
90 print "# @cmd2\n";
91 $status = system(join(' ',@cmd2));
92}
93print (($status? 'not ': '')."ok 1\n");
3be77bcf 94
144d6c83 95my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
20ebe338 96$embed_test = "run/nodebug $exe" if $^O eq 'VMS';
144d6c83 97print "# embed_test = $embed_test\n";
20ebe338 98$status = system($embed_test);
144d6c83 99print (($status? 'not ':'')."ok 9 # $status\n");
9fb80172 100unlink($exe,"embed_test.c",$obj);
101unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
e6de440e 102unlink("../libperl.dll") if $^O eq 'cygwin';
f1feeb72 103
94597104 104# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
f1feeb72 105
106__END__
107
108/* perl_test.c */
109
110#include <EXTERN.h>
111#include <perl.h>
112
113#define my_puts(a) if(puts(a) < 0) exit(666)
114
115char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
116
117int main(int argc, char **argv, char **env)
118{
119 PerlInterpreter *my_perl = perl_alloc();
120
121 my_puts("ok 2");
122
123 perl_construct(my_perl);
124
125 my_puts("ok 3");
126
127 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
128
129 my_puts("ok 4");
130
131 fflush(stdout);
132
133 perl_run(my_perl);
134
135 my_puts("ok 6");
136
137 perl_destruct(my_perl);
138
139 my_puts("ok 7");
140
141 perl_free(my_perl);
142
143 my_puts("ok 8");
144
145 return 0;
146}
147
148
149
150