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 | } |
63 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
64 | if ($^O eq 'MSWin32') { |
b1b2427f |
65 | $inc = File::Spec->catdir($inc,'win32'); |
1091dea4 |
66 | push(@cmd,"-I$inc"); |
b1b2427f |
67 | $inc = File::Spec->catdir($inc,'include'); |
1091dea4 |
68 | push(@cmd,"-I$inc"); |
69 | if ($cc eq 'cl') { |
c623ac67 |
70 | push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'}); |
1091dea4 |
71 | } |
72 | else { |
67bfc918 |
73 | push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); |
1091dea4 |
74 | } |
20ebe338 |
75 | } |
29c2e10b |
76 | else { # Not MSWin32. |
1091dea4 |
77 | push(@cmd,"-L$lib",'-lperl'); |
fee3faea |
78 | local $SIG{__WARN__} = sub { |
c623ac67 |
79 | warn $_[0] unless $_[0] =~ /No library found for .*perl/ |
fee3faea |
80 | }; |
dfcfdb64 |
81 | push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT! |
82 | if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/; |
fee3faea |
83 | push(@cmd,ldopts()); |
20ebe338 |
84 | } |
2a8c1a1c |
85 | if ($borl) { |
86 | @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd])); |
87 | } |
1091dea4 |
88 | |
20ebe338 |
89 | if ($^O eq 'aix') { # AIX needs an explicit symbol export list. |
f490490f |
90 | my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp); |
91 | die "where is perl.exp?\n" unless defined $perl_exp; |
92 | for (@cmd) { |
93 | s!-bE:(\S+)!-bE:$perl_exp!; |
94 | } |
88eeb692 |
95 | } |
b53432e4 |
96 | elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied |
41f1c18b |
97 | my $v_e_r_s = $Config{version}; |
98 | $v_e_r_s =~ tr/./_/; |
b53432e4 |
99 | system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1 |
20ebe338 |
100 | } |
88eeb692 |
101 | elsif ($Config{'libperl'} !~ /\Alibperl\./) { |
102 | # Everyone needs libperl copied if it's not found by '-lperl'. |
103 | $testlib = $Config{'libperl'}; |
104 | my $srclib = $testlib; |
c72f2af0 |
105 | $testlib =~ s/.+(?=\.[^.]*)/libperl/; |
88eeb692 |
106 | $testlib = File::Spec::->catfile($lib, $testlib); |
107 | $srclib = File::Spec::->catfile($lib, $srclib); |
108 | if (-f $srclib) { |
109 | unlink $testlib if -f $testlib; |
c7e0473b |
110 | my $ln_or_cp = $Config{'ln'} || $Config{'cp'}; |
111 | my $lncmd = "$ln_or_cp $srclib $testlib"; |
88eeb692 |
112 | #print "# $lncmd\n"; |
113 | $libperl_copied = 1 unless system($lncmd); |
114 | } |
115 | } |
f490490f |
116 | } |
20ebe338 |
117 | my $status; |
b2213df5 |
118 | # On OS/2 the linker will always emit an empty line to STDOUT; filter these |
2bf35fab |
119 | my $cmd = join ' ', @cmd; |
120 | chomp($cmd); # where is the newline coming from? ldopts()? |
121 | print "# $cmd\n"; |
122 | my @out = `$cmd`; |
123 | $status = $?; |
124 | print "# $_\n" foreach @out; |
b2213df5 |
125 | |
20ebe338 |
126 | if ($^O eq 'VMS' && !$status) { |
127 | print "# @cmd2\n"; |
128 | $status = system(join(' ',@cmd2)); |
129 | } |
130 | print (($status? 'not ': '')."ok 1\n"); |
3be77bcf |
131 | |
144d6c83 |
132 | my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe); |
20ebe338 |
133 | $embed_test = "run/nodebug $exe" if $^O eq 'VMS'; |
144d6c83 |
134 | print "# embed_test = $embed_test\n"; |
20ebe338 |
135 | $status = system($embed_test); |
7d63dedd |
136 | print (($status? 'not ':'')."ok 9 # system returned $status\n"); |
9fb80172 |
137 | unlink($exe,"embed_test.c",$obj); |
dfcfdb64 |
138 | unlink("$exe$Config{exe_ext}") if $skip_exe; |
9fb80172 |
139 | unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS'; |
b53432e4 |
140 | unlink(glob("./*.dll")) if $^O eq 'cygwin'; |
88eeb692 |
141 | unlink($testlib) if $libperl_copied; |
f1feeb72 |
142 | |
94597104 |
143 | # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` |
f1feeb72 |
144 | |
145 | __END__ |
146 | |
147 | /* perl_test.c */ |
148 | |
149 | #include <EXTERN.h> |
150 | #include <perl.h> |
151 | |
152 | #define my_puts(a) if(puts(a) < 0) exit(666) |
153 | |
9ac9d386 |
154 | static char *cmds[] = { "perl","-e", "$|=1; print qq[ok 5\\n]", NULL }; |
f1feeb72 |
155 | |
156 | int main(int argc, char **argv, char **env) |
157 | { |
1ccffcf5 |
158 | PerlInterpreter *my_perl; |
159 | |
160 | PERL_SYS_INIT3(&argc,&argv,&env); |
161 | |
162 | my_perl = perl_alloc(); |
f1feeb72 |
163 | |
164 | my_puts("ok 2"); |
165 | |
166 | perl_construct(my_perl); |
167 | |
168 | my_puts("ok 3"); |
169 | |
170 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); |
171 | |
172 | my_puts("ok 4"); |
173 | |
174 | fflush(stdout); |
175 | |
176 | perl_run(my_perl); |
177 | |
178 | my_puts("ok 6"); |
179 | |
180 | perl_destruct(my_perl); |
181 | |
182 | my_puts("ok 7"); |
183 | |
184 | perl_free(my_perl); |
185 | |
186 | my_puts("ok 8"); |
187 | |
1ccffcf5 |
188 | PERL_SYS_TERM(); |
189 | |
f1feeb72 |
190 | return 0; |
191 | } |