This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
AIX needs an explicit symbol export list.
[perl5.git] / lib / ExtUtils / 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'};
1091dea4
NIS
20my $inc = File::Spec->catdir($INC[0],"..");
21my $lib = File::Spec->catdir($INC[0],"..");
22my @cmd;
23if ($cl) {
24 push(@cmd,$cc,"-Fe$exe");
25}
26else {
27 push(@cmd,$cc,'-o' => $exe);
28}
29push(@cmd,"-I$inc",ccopts(),'embed_test.c');
30if ($^O eq 'MSWin32') {
b1b2427f 31 $inc = File::Spec->catdir($inc,'win32');
1091dea4 32 push(@cmd,"-I$inc");
b1b2427f 33 $inc = File::Spec->catdir($inc,'include');
1091dea4
NIS
34 push(@cmd,"-I$inc");
35 if ($cc eq 'cl') {
b1b2427f 36 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
1091dea4
NIS
37 }
38 else {
67bfc918 39 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
1091dea4
NIS
40 }
41}
42else {
43 push(@cmd,"-L$lib",'-lperl');
44}
45push(@cmd,ldopts());
46
f490490f
JH
47if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
48 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
49 die "where is perl.exp?\n" unless defined $perl_exp;
50 for (@cmd) {
51 s!-bE:(\S+)!-bE:$perl_exp!;
52 }
53}
54
94597104 55print "# @cmd"; # where is the newline coming from? ldopts()?
f1feeb72
NIS
56print "not " if system(join(' ',@cmd));
57print "ok 1\n";
3be77bcf
JH
58
59my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test");
60
61print "not " if system($embed_test);
f1feeb72 62print "ok 9\n";
94597104 63
b1b2427f 64unlink($exe,"embed_test.c");
f1feeb72 65
94597104 66# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
f1feeb72
NIS
67
68__END__
69
70/* perl_test.c */
71
72#include <EXTERN.h>
73#include <perl.h>
74
75#define my_puts(a) if(puts(a) < 0) exit(666)
76
77char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
78
79int main(int argc, char **argv, char **env)
80{
81 PerlInterpreter *my_perl = perl_alloc();
82
83 my_puts("ok 2");
84
85 perl_construct(my_perl);
86
87 my_puts("ok 3");
88
89 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
90
91 my_puts("ok 4");
92
93 fflush(stdout);
94
95 perl_run(my_perl);
96
97 my_puts("ok 6");
98
99 perl_destruct(my_perl);
100
101 my_puts("ok 7");
102
103 perl_free(my_perl);
104
105 my_puts("ok 8");
106
107 return 0;
108}
109
110
111
112