Commit | Line | Data |
39234879 |
1 | #!/usr/bin/perl |
f1feeb72 |
2 | |
3 | BEGIN { |
39234879 |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't' if -d 't'; |
6 | @INC = '../lib'; |
7 | } |
f1feeb72 |
8 | } |
39234879 |
9 | chdir 't'; |
10 | |
f1feeb72 |
11 | use Config; |
12 | use ExtUtils::Embed; |
1091dea4 |
13 | use File::Spec; |
f1feeb72 |
14 | |
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'); |
2a8c1a1c |
23 | my $borl = ($^O eq 'MSWin32' && $cc eq 'bcc32'); |
dfcfdb64 |
24 | my $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/; |
25 | my $exe = 'embed_test'; |
26 | $exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it |
9fb80172 |
27 | my $obj = 'embed_test' . $Config{'obj_ext'}; |
21f7eeb2 |
28 | my $inc = File::Spec->updir; |
29 | my $lib = File::Spec->updir; |
88eeb692 |
30 | my $libperl_copied; |
31 | my $testlib; |
1091dea4 |
32 | my @cmd; |
20ebe338 |
33 | my (@cmd2) if $^O eq 'VMS'; |
34 | |
35 | if ($^O eq 'VMS') { |
36 | push(@cmd,$cc,"/Obj=$obj"); |
37 | my (@incs) = ($inc); |
38 | my $crazy = ccopts(); |
39 | if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) { |
40 | push(@incs,$1); |
41 | } |
42 | if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) { |
43 | push(@incs,$1); |
44 | } |
45 | $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i; |
46 | push(@cmd,"/Include=(".join(',',@incs).")"); |
47 | push(@cmd,$crazy); |
48 | push(@cmd,"embed_test.c"); |
49 | |
50 | push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe"); |
51 | push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt"); |
52 | |
53 | } else { |
54 | if ($cl) { |
1091dea4 |
55 | push(@cmd,$cc,"-Fe$exe"); |
20ebe338 |
56 | } |
2a8c1a1c |
57 | elsif ($borl) { |
58 | push(@cmd,$cc,"-o$exe"); |
59 | } |
20ebe338 |
60 | else { |
1091dea4 |
61 | push(@cmd,$cc,'-o' => $exe); |
20ebe338 |
62 | } |
14270b7a |
63 | if ($^O eq 'dec_osf' && !defined $Config{usedl}) { |
64 | # The -non_shared is needed in case of -Uusedl or otherwise |
65 | # the test application will try to use libperl.so |
66 | # instead of libperl.a. |
67 | push @cmd, "-non_shared"; |
68 | } |
20ebe338 |
69 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
70 | if ($^O eq 'MSWin32') { |
b1b2427f |
71 | $inc = File::Spec->catdir($inc,'win32'); |
1091dea4 |
72 | push(@cmd,"-I$inc"); |
b1b2427f |
73 | $inc = File::Spec->catdir($inc,'include'); |
1091dea4 |
74 | push(@cmd,"-I$inc"); |
75 | if ($cc eq 'cl') { |
c623ac67 |
76 | push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'}); |
1091dea4 |
77 | } |
78 | else { |
67bfc918 |
79 | push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); |
1091dea4 |
80 | } |
20ebe338 |
81 | } |
2f3efc97 |
82 | elsif ($^O eq 'os390' && $Config{usedl}) { |
83 | # Nothing for OS/390 (z/OS) dynamic. |
84 | } else { # Not MSWin32 or OS/390 (z/OS) dynamic. |
1091dea4 |
85 | push(@cmd,"-L$lib",'-lperl'); |
fee3faea |
86 | local $SIG{__WARN__} = sub { |
c623ac67 |
87 | warn $_[0] unless $_[0] =~ /No library found for .*perl/ |
fee3faea |
88 | }; |
dfcfdb64 |
89 | push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT! |
90 | if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/; |
fee3faea |
91 | push(@cmd,ldopts()); |
20ebe338 |
92 | } |
2a8c1a1c |
93 | if ($borl) { |
94 | @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd])); |
95 | } |
1091dea4 |
96 | |
20ebe338 |
97 | if ($^O eq 'aix') { # AIX needs an explicit symbol export list. |
f490490f |
98 | my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp); |
99 | die "where is perl.exp?\n" unless defined $perl_exp; |
100 | for (@cmd) { |
101 | s!-bE:(\S+)!-bE:$perl_exp!; |
102 | } |
88eeb692 |
103 | } |
b53432e4 |
104 | elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied |
41f1c18b |
105 | my $v_e_r_s = $Config{version}; |
106 | $v_e_r_s =~ tr/./_/; |
b53432e4 |
107 | system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1 |
20ebe338 |
108 | } |
88eeb692 |
109 | elsif ($Config{'libperl'} !~ /\Alibperl\./) { |
110 | # Everyone needs libperl copied if it's not found by '-lperl'. |
111 | $testlib = $Config{'libperl'}; |
112 | my $srclib = $testlib; |
c72f2af0 |
113 | $testlib =~ s/.+(?=\.[^.]*)/libperl/; |
88eeb692 |
114 | $testlib = File::Spec::->catfile($lib, $testlib); |
115 | $srclib = File::Spec::->catfile($lib, $srclib); |
116 | if (-f $srclib) { |
117 | unlink $testlib if -f $testlib; |
c7e0473b |
118 | my $ln_or_cp = $Config{'ln'} || $Config{'cp'}; |
119 | my $lncmd = "$ln_or_cp $srclib $testlib"; |
88eeb692 |
120 | #print "# $lncmd\n"; |
121 | $libperl_copied = 1 unless system($lncmd); |
122 | } |
123 | } |
f490490f |
124 | } |
20ebe338 |
125 | my $status; |
b2213df5 |
126 | # On OS/2 the linker will always emit an empty line to STDOUT; filter these |
2bf35fab |
127 | my $cmd = join ' ', @cmd; |
128 | chomp($cmd); # where is the newline coming from? ldopts()? |
129 | print "# $cmd\n"; |
130 | my @out = `$cmd`; |
131 | $status = $?; |
132 | print "# $_\n" foreach @out; |
b2213df5 |
133 | |
20ebe338 |
134 | if ($^O eq 'VMS' && !$status) { |
135 | print "# @cmd2\n"; |
136 | $status = system(join(' ',@cmd2)); |
137 | } |
138 | print (($status? 'not ': '')."ok 1\n"); |
3be77bcf |
139 | |
144d6c83 |
140 | my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe); |
20ebe338 |
141 | $embed_test = "run/nodebug $exe" if $^O eq 'VMS'; |
144d6c83 |
142 | print "# embed_test = $embed_test\n"; |
20ebe338 |
143 | $status = system($embed_test); |
7d63dedd |
144 | print (($status? 'not ':'')."ok 9 # system returned $status\n"); |
9fb80172 |
145 | unlink($exe,"embed_test.c",$obj); |
dfcfdb64 |
146 | unlink("$exe$Config{exe_ext}") if $skip_exe; |
9fb80172 |
147 | unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS'; |
b53432e4 |
148 | unlink(glob("./*.dll")) if $^O eq 'cygwin'; |
88eeb692 |
149 | unlink($testlib) if $libperl_copied; |
f1feeb72 |
150 | |
94597104 |
151 | # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` |
f1feeb72 |
152 | |
153 | __END__ |
154 | |
155 | /* perl_test.c */ |
156 | |
157 | #include <EXTERN.h> |
158 | #include <perl.h> |
159 | |
160 | #define my_puts(a) if(puts(a) < 0) exit(666) |
161 | |
9ac9d386 |
162 | static char *cmds[] = { "perl","-e", "$|=1; print qq[ok 5\\n]", NULL }; |
f1feeb72 |
163 | |
27da23d5 |
164 | #ifdef PERL_GLOBAL_STRUCT_PRIVATE |
165 | static struct perl_vars *my_plvarsp; |
166 | struct perl_vars* Perl_GetVarsPrivate(void) { return my_plvarsp; } |
167 | #endif |
168 | |
2f3efc97 |
169 | #ifdef NO_ENV_ARRAY_IN_MAIN |
170 | extern char **environ; |
171 | int main(int argc, char **argv) |
172 | #else |
f1feeb72 |
173 | int main(int argc, char **argv, char **env) |
2f3efc97 |
174 | #endif |
f1feeb72 |
175 | { |
1ccffcf5 |
176 | PerlInterpreter *my_perl; |
27da23d5 |
177 | #ifdef PERL_GLOBAL_STRUCT |
178 | dVAR; |
179 | struct perl_vars *plvarsp = init_global_struct(); |
180 | # ifdef PERL_GLOBAL_STRUCT_PRIVATE |
181 | my_vars = my_plvarsp = plvarsp; |
182 | # endif |
183 | #endif /* PERL_GLOBAL_STRUCT */ |
b7787f18 |
184 | |
185 | (void)argc; /* PERL_SYS_INIT3 may #define away their use */ |
186 | (void)argv; |
2f3efc97 |
187 | #ifdef NO_ENV_ARRAY_IN_MAIN |
188 | PERL_SYS_INIT3(&argc,&argv,&environ); |
189 | #else |
1ccffcf5 |
190 | PERL_SYS_INIT3(&argc,&argv,&env); |
2f3efc97 |
191 | #endif |
1ccffcf5 |
192 | |
193 | my_perl = perl_alloc(); |
f1feeb72 |
194 | |
195 | my_puts("ok 2"); |
196 | |
197 | perl_construct(my_perl); |
198 | |
199 | my_puts("ok 3"); |
200 | |
2f3efc97 |
201 | #ifdef NO_ENV_ARRAY_IN_MAIN |
202 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, environ); |
203 | #else |
f1feeb72 |
204 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); |
2f3efc97 |
205 | #endif |
f1feeb72 |
206 | |
207 | my_puts("ok 4"); |
208 | |
209 | fflush(stdout); |
210 | |
211 | perl_run(my_perl); |
212 | |
213 | my_puts("ok 6"); |
214 | |
215 | perl_destruct(my_perl); |
216 | |
217 | my_puts("ok 7"); |
218 | |
219 | perl_free(my_perl); |
220 | |
27da23d5 |
221 | #ifdef PERL_GLOBAL_STRUCT |
222 | free_global_struct(plvarsp); |
223 | #endif /* PERL_GLOBAL_STRUCT */ |
224 | |
f1feeb72 |
225 | my_puts("ok 8"); |
226 | |
1ccffcf5 |
227 | PERL_SYS_TERM(); |
228 | |
f1feeb72 |
229 | return 0; |
230 | } |