when PERL_USE_SAFE_PUTENV is defined environ will not
[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
0cb90816 11if ($^O eq 'VMS') {
12 print "1..0 # not on VMS\n";
13 exit 0;
14}
f1feeb72 15open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
16print $fh <DATA>;
17close($fh);
18
19$| = 1;
20print "1..9\n";
1091dea4 21my $cc = $Config{'cc'};
22my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
b1b2427f 23my $exe = 'embed_test' . $Config{'exe_ext'};
1091dea4 24my $inc = File::Spec->catdir($INC[0],"..");
25my $lib = File::Spec->catdir($INC[0],"..");
26my @cmd;
27if ($cl) {
28 push(@cmd,$cc,"-Fe$exe");
29}
30else {
31 push(@cmd,$cc,'-o' => $exe);
32}
33push(@cmd,"-I$inc",ccopts(),'embed_test.c');
34if ($^O eq 'MSWin32') {
b1b2427f 35 $inc = File::Spec->catdir($inc,'win32');
1091dea4 36 push(@cmd,"-I$inc");
b1b2427f 37 $inc = File::Spec->catdir($inc,'include');
1091dea4 38 push(@cmd,"-I$inc");
39 if ($cc eq 'cl') {
b1b2427f 40 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
1091dea4 41 }
42 else {
67bfc918 43 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
1091dea4 44 }
45}
46else {
47 push(@cmd,"-L$lib",'-lperl');
48}
fee3faea 49{
50 local $SIG{__WARN__} = sub {
51 warn $_[0] unless $_[0] =~ /No library found for -lperl/
52 };
53 push(@cmd,ldopts());
54}
1091dea4 55
f490490f 56if ($^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
94597104 64print "# @cmd"; # where is the newline coming from? ldopts()?
f1feeb72 65print "not " if system(join(' ',@cmd));
66print "ok 1\n";
3be77bcf 67
68my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test");
69
70print "not " if system($embed_test);
f1feeb72 71print "ok 9\n";
94597104 72
b1b2427f 73unlink($exe,"embed_test.c");
f1feeb72 74
94597104 75# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
f1feeb72 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
86char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
87
88int 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