This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate Mainline
[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');
19my $exe = 'embedtest' . $Config{'exe_ext'};
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') {
31 $inc = File::Spec->catdir($inc,'win32');
32 push(@cmd,"-I$inc");
33 $inc = File::Spec->catdir($inc,'include');
34 push(@cmd,"-I$inc");
35 if ($cc eq 'cl') {
36 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
37 }
38 else {
39 push(@cmd,"-L$lib",'-lperl',$Config{'libc'});
40 }
41}
42else {
43 push(@cmd,"-L$lib",'-lperl');
44}
45push(@cmd,ldopts());
46
47
48print "#@cmd\n";
f1feeb72
NIS
49print "not " if system(join(' ',@cmd));
50print "ok 1\n";
51print "not " if system("embed_test");
52print "ok 9\n";
53unlink("embed_test","embed_test.c");
54
55#gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
56
57__END__
58
59/* perl_test.c */
60
61#include <EXTERN.h>
62#include <perl.h>
63
64#define my_puts(a) if(puts(a) < 0) exit(666)
65
66char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
67
68int main(int argc, char **argv, char **env)
69{
70 PerlInterpreter *my_perl = perl_alloc();
71
72 my_puts("ok 2");
73
74 perl_construct(my_perl);
75
76 my_puts("ok 3");
77
78 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
79
80 my_puts("ok 4");
81
82 fflush(stdout);
83
84 perl_run(my_perl);
85
86 my_puts("ok 6");
87
88 perl_destruct(my_perl);
89
90 my_puts("ok 7");
91
92 perl_free(my_perl);
93
94 my_puts("ok 8");
95
96 return 0;
97}
98
99
100
101