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'}; |
9fb80172 |
20 | my $obj = 'embed_test' . $Config{'obj_ext'}; |
1091dea4 |
21 | my $inc = File::Spec->catdir($INC[0],".."); |
22 | my $lib = File::Spec->catdir($INC[0],".."); |
23 | my @cmd; |
20ebe338 |
24 | my (@cmd2) if $^O eq 'VMS'; |
25 | |
26 | if ($^O eq 'VMS') { |
27 | push(@cmd,$cc,"/Obj=$obj"); |
28 | my (@incs) = ($inc); |
29 | my $crazy = ccopts(); |
30 | if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) { |
31 | push(@incs,$1); |
32 | } |
33 | if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) { |
34 | push(@incs,$1); |
35 | } |
36 | $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i; |
37 | push(@cmd,"/Include=(".join(',',@incs).")"); |
38 | push(@cmd,$crazy); |
39 | push(@cmd,"embed_test.c"); |
40 | |
41 | push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe"); |
42 | push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt"); |
43 | |
44 | } else { |
45 | if ($cl) { |
1091dea4 |
46 | push(@cmd,$cc,"-Fe$exe"); |
20ebe338 |
47 | } |
48 | else { |
1091dea4 |
49 | push(@cmd,$cc,'-o' => $exe); |
20ebe338 |
50 | } |
51 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
52 | if ($^O eq 'MSWin32') { |
b1b2427f |
53 | $inc = File::Spec->catdir($inc,'win32'); |
1091dea4 |
54 | push(@cmd,"-I$inc"); |
b1b2427f |
55 | $inc = File::Spec->catdir($inc,'include'); |
1091dea4 |
56 | push(@cmd,"-I$inc"); |
57 | if ($cc eq 'cl') { |
b1b2427f |
58 | push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'}); |
1091dea4 |
59 | } |
60 | else { |
67bfc918 |
61 | push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); |
1091dea4 |
62 | } |
20ebe338 |
63 | } |
64 | else { |
1091dea4 |
65 | push(@cmd,"-L$lib",'-lperl'); |
20ebe338 |
66 | } |
67 | { |
fee3faea |
68 | local $SIG{__WARN__} = sub { |
69 | warn $_[0] unless $_[0] =~ /No library found for -lperl/ |
70 | }; |
71 | push(@cmd,ldopts()); |
20ebe338 |
72 | } |
1091dea4 |
73 | |
20ebe338 |
74 | if ($^O eq 'aix') { # AIX needs an explicit symbol export list. |
f490490f |
75 | my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp); |
76 | die "where is perl.exp?\n" unless defined $perl_exp; |
77 | for (@cmd) { |
78 | s!-bE:(\S+)!-bE:$perl_exp!; |
79 | } |
20ebe338 |
80 | } |
f490490f |
81 | } |
20ebe338 |
82 | my $status; |
8fe5b9ff |
83 | my $display_cmd = "@cmd"; |
84 | chomp($display_cmd); # where is the newline coming from? ldopts()? |
85 | print "# $display_cmd\n"; |
20ebe338 |
86 | $status = system(join(' ',@cmd)); |
87 | if ($^O eq 'VMS' && !$status) { |
88 | print "# @cmd2\n"; |
89 | $status = system(join(' ',@cmd2)); |
90 | } |
91 | print (($status? 'not ': '')."ok 1\n"); |
3be77bcf |
92 | |
93 | my $embed_test = File::Spec->catfile(File::Spec->curdir, "embed_test"); |
20ebe338 |
94 | $embed_test = "run/nodebug $exe" if $^O eq 'VMS'; |
3be77bcf |
95 | |
20ebe338 |
96 | $status = system($embed_test); |
97 | print (($status? 'not ':'')."ok 9\n"); |
9fb80172 |
98 | unlink($exe,"embed_test.c",$obj); |
99 | unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS'; |
f1feeb72 |
100 | |
94597104 |
101 | # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` |
f1feeb72 |
102 | |
103 | __END__ |
104 | |
105 | /* perl_test.c */ |
106 | |
107 | #include <EXTERN.h> |
108 | #include <perl.h> |
109 | |
110 | #define my_puts(a) if(puts(a) < 0) exit(666) |
111 | |
112 | char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL }; |
113 | |
114 | int main(int argc, char **argv, char **env) |
115 | { |
116 | PerlInterpreter *my_perl = perl_alloc(); |
117 | |
118 | my_puts("ok 2"); |
119 | |
120 | perl_construct(my_perl); |
121 | |
122 | my_puts("ok 3"); |
123 | |
124 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); |
125 | |
126 | my_puts("ok 4"); |
127 | |
128 | fflush(stdout); |
129 | |
130 | perl_run(my_perl); |
131 | |
132 | my_puts("ok 6"); |
133 | |
134 | perl_destruct(my_perl); |
135 | |
136 | my_puts("ok 7"); |
137 | |
138 | perl_free(my_perl); |
139 | |
140 | my_puts("ok 8"); |
141 | |
142 | return 0; |
143 | } |
144 | |
145 | |
146 | |
147 | |