Commit | Line | Data |
f1feeb72 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | unshift @INC, '../lib'; |
6 | } |
7 | use Config; |
8 | use ExtUtils::Embed; |
1091dea4 |
9 | use File::Spec; |
f1feeb72 |
10 | |
11 | open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!"; |
12 | print $fh <DATA>; |
13 | close($fh); |
14 | |
15 | $| = 1; |
16 | print "1..9\n"; |
1091dea4 |
17 | my $cc = $Config{'cc'}; |
18 | my $cl = ($^O eq 'MSWin32' && $cc eq 'cl'); |
b1b2427f |
19 | my $exe = 'embed_test' . $Config{'exe_ext'}; |
1091dea4 |
20 | my $inc = File::Spec->catdir($INC[0],".."); |
21 | my $lib = File::Spec->catdir($INC[0],".."); |
22 | my @cmd; |
23 | if ($cl) { |
24 | push(@cmd,$cc,"-Fe$exe"); |
25 | } |
26 | else { |
27 | push(@cmd,$cc,'-o' => $exe); |
28 | } |
29 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
30 | if ($^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 |
34 | push(@cmd,"-I$inc"); |
35 | if ($cc eq 'cl') { |
b1b2427f |
36 | push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'}); |
1091dea4 |
37 | } |
38 | else { |
67bfc918 |
39 | push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); |
1091dea4 |
40 | } |
41 | } |
42 | else { |
43 | push(@cmd,"-L$lib",'-lperl'); |
44 | } |
45 | push(@cmd,ldopts()); |
46 | |
94597104 |
47 | print "# @cmd"; # where is the newline coming from? ldopts()? |
f1feeb72 |
48 | print "not " if system(join(' ',@cmd)); |
49 | print "ok 1\n"; |
3be77bcf |
50 | |
51 | my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test"); |
52 | |
53 | print "not " if system($embed_test); |
f1feeb72 |
54 | print "ok 9\n"; |
94597104 |
55 | |
b1b2427f |
56 | unlink($exe,"embed_test.c"); |
f1feeb72 |
57 | |
94597104 |
58 | # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` |
f1feeb72 |
59 | |
60 | __END__ |
61 | |
62 | /* perl_test.c */ |
63 | |
64 | #include <EXTERN.h> |
65 | #include <perl.h> |
66 | |
67 | #define my_puts(a) if(puts(a) < 0) exit(666) |
68 | |
69 | char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL }; |
70 | |
71 | int main(int argc, char **argv, char **env) |
72 | { |
73 | PerlInterpreter *my_perl = perl_alloc(); |
74 | |
75 | my_puts("ok 2"); |
76 | |
77 | perl_construct(my_perl); |
78 | |
79 | my_puts("ok 3"); |
80 | |
81 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); |
82 | |
83 | my_puts("ok 4"); |
84 | |
85 | fflush(stdout); |
86 | |
87 | perl_run(my_perl); |
88 | |
89 | my_puts("ok 6"); |
90 | |
91 | perl_destruct(my_perl); |
92 | |
93 | my_puts("ok 7"); |
94 | |
95 | perl_free(my_perl); |
96 | |
97 | my_puts("ok 8"); |
98 | |
99 | return 0; |
100 | } |
101 | |
102 | |
103 | |
104 | |