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 | |
0cb90816 |
11 | if ($^O eq 'VMS') { |
12 | print "1..0 # not on VMS\n"; |
13 | exit 0; |
14 | } |
f1feeb72 |
15 | open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!"; |
16 | print $fh <DATA>; |
17 | close($fh); |
18 | |
19 | $| = 1; |
20 | print "1..9\n"; |
1091dea4 |
21 | my $cc = $Config{'cc'}; |
22 | my $cl = ($^O eq 'MSWin32' && $cc eq 'cl'); |
b1b2427f |
23 | my $exe = 'embed_test' . $Config{'exe_ext'}; |
1091dea4 |
24 | my $inc = File::Spec->catdir($INC[0],".."); |
25 | my $lib = File::Spec->catdir($INC[0],".."); |
26 | my @cmd; |
27 | if ($cl) { |
28 | push(@cmd,$cc,"-Fe$exe"); |
29 | } |
30 | else { |
31 | push(@cmd,$cc,'-o' => $exe); |
32 | } |
33 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
34 | if ($^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 | } |
46 | else { |
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 |
56 | if ($^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 |
64 | print "# @cmd"; # where is the newline coming from? ldopts()? |
f1feeb72 |
65 | print "not " if system(join(' ',@cmd)); |
66 | print "ok 1\n"; |
3be77bcf |
67 | |
68 | my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test"); |
69 | |
70 | print "not " if system($embed_test); |
f1feeb72 |
71 | print "ok 9\n"; |
94597104 |
72 | |
b1b2427f |
73 | unlink($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 | |
86 | char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL }; |
87 | |
88 | int 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 | |