summaryrefslogtreecommitdiff
path: root/lib/ExtUtils/Embed.t
blob: 08c7cabcc581a3e489b68c96266567ee361ba1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!./perl

BEGIN {
    chdir 't' if -d 't';
    unshift @INC, '../lib';
}
use Config;
use ExtUtils::Embed;
use File::Spec;

open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
print $fh <DATA>;
close($fh);

$| = 1;
print "1..9\n";
my $cc = $Config{'cc'};
my $cl  = ($^O eq 'MSWin32' && $cc eq 'cl');
my $exe = 'embed_test' . $Config{'exe_ext'};
my $inc = File::Spec->catdir($INC[0],"..");
my $lib = File::Spec->catdir($INC[0],"..");
my @cmd;
if ($cl) {
    push(@cmd,$cc,"-Fe$exe");
}
else {
    push(@cmd,$cc,'-o' => $exe);
}
push(@cmd,"-I$inc",ccopts(),'embed_test.c');
if ($^O eq 'MSWin32') {
    $inc = File::Spec->catdir($inc,'win32');
    push(@cmd,"-I$inc");
    $inc = File::Spec->catdir($inc,'include');
    push(@cmd,"-I$inc");
    if ($cc eq 'cl') {
	push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
    }
    else {
	push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
    }
}
else {
    push(@cmd,"-L$lib",'-lperl');
}
push(@cmd,ldopts());

print "# @cmd"; # where is the newline coming from? ldopts()?
print "not " if system(join(' ',@cmd));
print "ok 1\n";

my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test");

print "not " if system($embed_test);
print "ok 9\n";

unlink($exe,"embed_test.c");

# gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`

__END__

/* perl_test.c */

#include <EXTERN.h>
#include <perl.h>

#define my_puts(a) if(puts(a) < 0) exit(666)

char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };

int main(int argc, char **argv, char **env)
{
    PerlInterpreter *my_perl = perl_alloc();

    my_puts("ok 2");

    perl_construct(my_perl);

    my_puts("ok 3");

    perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);

    my_puts("ok 4");

    fflush(stdout);

    perl_run(my_perl);

    my_puts("ok 6");

    perl_destruct(my_perl);

    my_puts("ok 7");

    perl_free(my_perl);

    my_puts("ok 8");

    return 0;
}