The Embed test requires a major rewrite for VMS
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / Embed.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     unshift @INC, '../lib';
6 }
7 use Config;
8 use ExtUtils::Embed;
9 use File::Spec;
10
11 if ($^O eq 'VMS') {
12    print "1..0  # not on VMS\n"; 
13    exit 0;
14 }
15 open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
16 print $fh <DATA>;
17 close($fh);
18
19 $| = 1;
20 print "1..9\n";
21 my $cc = $Config{'cc'};
22 my $cl  = ($^O eq 'MSWin32' && $cc eq 'cl');
23 my $exe = 'embed_test' . $Config{'exe_ext'};
24 my $inc = File::Spec->catdir($INC[0],"..");
25 my $lib = File::Spec->catdir($INC[0],"..");
26 my @cmd;
27 if ($cl) {
28     push(@cmd,$cc,"-Fe$exe");
29 }
30 else {
31     push(@cmd,$cc,'-o' => $exe);
32 }
33 push(@cmd,"-I$inc",ccopts(),'embed_test.c');
34 if ($^O eq 'MSWin32') {
35     $inc = File::Spec->catdir($inc,'win32');
36     push(@cmd,"-I$inc");
37     $inc = File::Spec->catdir($inc,'include');
38     push(@cmd,"-I$inc");
39     if ($cc eq 'cl') {
40         push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
41     }
42     else {
43         push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
44     }
45 }
46 else {
47     push(@cmd,"-L$lib",'-lperl');
48 }
49 {
50     local $SIG{__WARN__} = sub {
51         warn $_[0] unless $_[0] =~ /No library found for -lperl/
52     };
53     push(@cmd,ldopts());
54 }
55
56 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
57     my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
58     die "where is perl.exp?\n" unless defined $perl_exp;
59     for (@cmd) {
60         s!-bE:(\S+)!-bE:$perl_exp!;
61     }
62 }
63
64 print "# @cmd"; # where is the newline coming from? ldopts()?
65 print "not " if system(join(' ',@cmd));
66 print "ok 1\n";
67
68 my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test");
69
70 print "not " if system($embed_test);
71 print "ok 9\n";
72
73 unlink($exe,"embed_test.c");
74
75 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
76
77 __END__
78
79 /* perl_test.c */
80
81 #include <EXTERN.h>
82 #include <perl.h>
83
84 #define my_puts(a) if(puts(a) < 0) exit(666)
85
86 char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
87
88 int main(int argc, char **argv, char **env)
89 {
90     PerlInterpreter *my_perl = perl_alloc();
91
92     my_puts("ok 2");
93
94     perl_construct(my_perl);
95
96     my_puts("ok 3");
97
98     perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
99
100     my_puts("ok 4");
101
102     fflush(stdout);
103
104     perl_run(my_perl);
105
106     my_puts("ok 6");
107
108     perl_destruct(my_perl);
109
110     my_puts("ok 7");
111
112     perl_free(my_perl);
113
114     my_puts("ok 8");
115
116     return 0;
117 }
118
119
120
121