Add the fruits of Larry Shatzer's version verifying script.
[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'};
20ebe338 20my $obj = 'embed_test' . $Config{'obj_ext'} if $^O eq 'VMS';
1091dea4 21my $inc = File::Spec->catdir($INC[0],"..");
22my $lib = File::Spec->catdir($INC[0],"..");
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 }
20ebe338 80 }
f490490f 81}
20ebe338 82my $status;
8fe5b9ff 83my $display_cmd = "@cmd";
84chomp($display_cmd); # where is the newline coming from? ldopts()?
85print "# $display_cmd\n";
20ebe338 86$status = system(join(' ',@cmd));
87if ($^O eq 'VMS' && !$status) {
88 print "# @cmd2\n";
89 $status = system(join(' ',@cmd2));
90}
91print (($status? 'not ': '')."ok 1\n");
3be77bcf 92
93my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test");
20ebe338 94$embed_test = "run/nodebug $exe" if $^O eq 'VMS';
3be77bcf 95
20ebe338 96$status = system($embed_test);
97print (($status? 'not ':'')."ok 9\n");
b1b2427f 98unlink($exe,"embed_test.c");
20ebe338 99unlink($obj,"embed_test.map","embed_test.lis") if $^O eq 'VMS'
f1feeb72 100
94597104 101# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
f1feeb72 102
103__END__
104
105/* perl_test.c */
106
107#include <EXTERN.h>
108#include <perl.h>
109
110#define my_puts(a) if(puts(a) < 0) exit(666)
111
112char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
113
114int main(int argc, char **argv, char **env)
115{
116 PerlInterpreter *my_perl = perl_alloc();
117
118 my_puts("ok 2");
119
120 perl_construct(my_perl);
121
122 my_puts("ok 3");
123
124 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
125
126 my_puts("ok 4");
127
128 fflush(stdout);
129
130 perl_run(my_perl);
131
132 my_puts("ok 6");
133
134 perl_destruct(my_perl);
135
136 my_puts("ok 7");
137
138 perl_free(my_perl);
139
140 my_puts("ok 8");
141
142 return 0;
143}
144
145
146
147