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