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'); |
dfcfdb64 |
19 | my $skip_exe = $^O eq 'os2' && $Config{ldflags} =~ /(?<!\S)-Zexe\b/; |
20 | my $exe = 'embed_test'; |
21 | $exe .= $Config{'exe_ext'} unless $skip_exe; # Linker will auto-append it |
9fb80172 |
22 | my $obj = 'embed_test' . $Config{'obj_ext'}; |
21f7eeb2 |
23 | my $inc = File::Spec->updir; |
24 | my $lib = File::Spec->updir; |
88eeb692 |
25 | my $libperl_copied; |
26 | my $testlib; |
1091dea4 |
27 | my @cmd; |
20ebe338 |
28 | my (@cmd2) if $^O eq 'VMS'; |
29 | |
30 | if ($^O eq 'VMS') { |
31 | push(@cmd,$cc,"/Obj=$obj"); |
32 | my (@incs) = ($inc); |
33 | my $crazy = ccopts(); |
34 | if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) { |
35 | push(@incs,$1); |
36 | } |
37 | if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) { |
38 | push(@incs,$1); |
39 | } |
40 | $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i; |
41 | push(@cmd,"/Include=(".join(',',@incs).")"); |
42 | push(@cmd,$crazy); |
43 | push(@cmd,"embed_test.c"); |
44 | |
45 | push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe"); |
46 | push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt"); |
47 | |
48 | } else { |
49 | if ($cl) { |
1091dea4 |
50 | push(@cmd,$cc,"-Fe$exe"); |
20ebe338 |
51 | } |
52 | else { |
1091dea4 |
53 | push(@cmd,$cc,'-o' => $exe); |
20ebe338 |
54 | } |
55 | push(@cmd,"-I$inc",ccopts(),'embed_test.c'); |
56 | if ($^O eq 'MSWin32') { |
b1b2427f |
57 | $inc = File::Spec->catdir($inc,'win32'); |
1091dea4 |
58 | push(@cmd,"-I$inc"); |
b1b2427f |
59 | $inc = File::Spec->catdir($inc,'include'); |
1091dea4 |
60 | push(@cmd,"-I$inc"); |
61 | if ($cc eq 'cl') { |
b1b2427f |
62 | push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'}); |
1091dea4 |
63 | } |
64 | else { |
67bfc918 |
65 | push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'}); |
1091dea4 |
66 | } |
20ebe338 |
67 | } |
68 | else { |
1091dea4 |
69 | push(@cmd,"-L$lib",'-lperl'); |
20ebe338 |
70 | } |
71 | { |
fee3faea |
72 | local $SIG{__WARN__} = sub { |
73 | warn $_[0] unless $_[0] =~ /No library found for -lperl/ |
74 | }; |
dfcfdb64 |
75 | push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT! |
76 | if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/; |
fee3faea |
77 | push(@cmd,ldopts()); |
20ebe338 |
78 | } |
1091dea4 |
79 | |
20ebe338 |
80 | if ($^O eq 'aix') { # AIX needs an explicit symbol export list. |
f490490f |
81 | my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp); |
82 | die "where is perl.exp?\n" unless defined $perl_exp; |
83 | for (@cmd) { |
84 | s!-bE:(\S+)!-bE:$perl_exp!; |
85 | } |
88eeb692 |
86 | } |
87 | elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied |
41f1c18b |
88 | my $v_e_r_s = $Config{version}; |
89 | $v_e_r_s =~ tr/./_/; |
90 | system("cp ../libperl$v_e_r_s.dll ./"); # for test 1 |
91 | system("cp ../$Config{'libperl'} ../libperl.a"); # for test 1 |
20ebe338 |
92 | } |
88eeb692 |
93 | elsif ($Config{'libperl'} !~ /\Alibperl\./) { |
94 | # Everyone needs libperl copied if it's not found by '-lperl'. |
95 | $testlib = $Config{'libperl'}; |
96 | my $srclib = $testlib; |
97 | $testlib =~ s/^[^.]+/libperl/; |
98 | $testlib = File::Spec::->catfile($lib, $testlib); |
99 | $srclib = File::Spec::->catfile($lib, $srclib); |
100 | if (-f $srclib) { |
101 | unlink $testlib if -f $testlib; |
c7e0473b |
102 | my $ln_or_cp = $Config{'ln'} || $Config{'cp'}; |
103 | my $lncmd = "$ln_or_cp $srclib $testlib"; |
88eeb692 |
104 | #print "# $lncmd\n"; |
105 | $libperl_copied = 1 unless system($lncmd); |
106 | } |
107 | } |
f490490f |
108 | } |
20ebe338 |
109 | my $status; |
8fe5b9ff |
110 | my $display_cmd = "@cmd"; |
111 | chomp($display_cmd); # where is the newline coming from? ldopts()? |
112 | print "# $display_cmd\n"; |
20ebe338 |
113 | $status = system(join(' ',@cmd)); |
114 | if ($^O eq 'VMS' && !$status) { |
115 | print "# @cmd2\n"; |
116 | $status = system(join(' ',@cmd2)); |
117 | } |
118 | print (($status? 'not ': '')."ok 1\n"); |
3be77bcf |
119 | |
144d6c83 |
120 | my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe); |
20ebe338 |
121 | $embed_test = "run/nodebug $exe" if $^O eq 'VMS'; |
144d6c83 |
122 | print "# embed_test = $embed_test\n"; |
20ebe338 |
123 | $status = system($embed_test); |
144d6c83 |
124 | print (($status? 'not ':'')."ok 9 # $status\n"); |
9fb80172 |
125 | unlink($exe,"embed_test.c",$obj); |
dfcfdb64 |
126 | unlink("$exe$Config{exe_ext}") if $skip_exe; |
9fb80172 |
127 | unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS'; |
41f1c18b |
128 | unlink(glob("./libperl*.dll")) if $^O eq 'cygwin'; |
129 | unlink("../libperl.a") if $^O eq 'cygwin'; |
88eeb692 |
130 | unlink($testlib) if $libperl_copied; |
f1feeb72 |
131 | |
94597104 |
132 | # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts` |
f1feeb72 |
133 | |
134 | __END__ |
135 | |
136 | /* perl_test.c */ |
137 | |
138 | #include <EXTERN.h> |
139 | #include <perl.h> |
140 | |
141 | #define my_puts(a) if(puts(a) < 0) exit(666) |
142 | |
d37d8ed3 |
143 | static char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL }; |
f1feeb72 |
144 | |
145 | int main(int argc, char **argv, char **env) |
146 | { |
147 | PerlInterpreter *my_perl = perl_alloc(); |
148 | |
149 | my_puts("ok 2"); |
150 | |
151 | perl_construct(my_perl); |
152 | |
153 | my_puts("ok 3"); |
154 | |
155 | perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env); |
156 | |
157 | my_puts("ok 4"); |
158 | |
159 | fflush(stdout); |
160 | |
161 | perl_run(my_perl); |
162 | |
163 | my_puts("ok 6"); |
164 | |
165 | perl_destruct(my_perl); |
166 | |
167 | my_puts("ok 7"); |
168 | |
169 | perl_free(my_perl); |
170 | |
171 | my_puts("ok 8"); |
172 | |
173 | return 0; |
174 | } |
175 | |
176 | |
177 | |
178 | |