4 if( $ENV{PERL_CORE} ) {
15 open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
21 my $cc = $Config{'cc'};
22 my $cl = ($^O eq 'MSWin32' && $cc eq 'cl');
23 my $borl = ($^O eq 'MSWin32' && $cc eq 'bcc32');
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
27 my $obj = 'embed_test' . $Config{'obj_ext'};
28 my $inc = File::Spec->updir;
29 my $lib = File::Spec->updir;
33 my (@cmd2) if $^O eq 'VMS';
34 # Don't use ccopts() here as we may want to overwrite an existing
35 # perl with a new one with inconsistent header files, meaning
36 # the usual value for perl_inc(), which is used by ccopts(),
39 push(@cmd,$cc,"/Obj=$obj");
41 my $crazy = ccflags();
42 if ($crazy =~ s#/inc[^=/]*=([\w\$\_\-\.\[\]\:]+)##i) {
45 if ($crazy =~ s/-I([a-zA-Z0-9\$\_\-\.\[\]\:]*)//) {
48 $crazy =~ s#/Obj[^=/]*=[\w\$\_\-\.\[\]\:]+##i;
49 push(@cmd,"/Include=(".join(',',@incs).")");
51 push(@cmd,"embed_test.c");
53 push(@cmd2,$Config{'ld'}, $Config{'ldflags'}, "/exe=$exe");
54 push(@cmd2,"$obj,[-]perlshr.opt/opt,[-]perlshr_attr.opt/opt");
58 push(@cmd,$cc,"-Fe$exe");
61 push(@cmd,$cc,"-o$exe");
64 push(@cmd,$cc,'-o' => $exe);
66 if ($^O eq 'dec_osf' && !defined $Config{usedl}) {
67 # The -non_shared is needed in case of -Uusedl or otherwise
68 # the test application will try to use libperl.so
69 # instead of libperl.a.
70 push @cmd, "-non_shared";
73 push(@cmd,"-I$inc",ccflags(),'embed_test.c');
74 if ($^O eq 'MSWin32') {
75 $inc = File::Spec->catdir($inc,'win32');
77 $inc = File::Spec->catdir($inc,'include');
80 push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libs'});
83 push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
86 elsif ($^O eq 'os390' && $Config{usedl}) {
87 # Nothing for OS/390 (z/OS) dynamic.
88 } else { # Not MSWin32 or OS/390 (z/OS) dynamic.
89 push(@cmd,"-L$lib",'-lperl');
90 local $SIG{__WARN__} = sub {
91 warn $_[0] unless $_[0] =~ /No library found for .*perl/
93 push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
94 if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
98 @cmd = ($cmd[0],(grep{/^-[LI]/}@cmd[1..$#cmd]),(grep{!/^-[LI]/}@cmd[1..$#cmd]));
101 if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
102 my ($perl_exp) = grep { -f } qw(perl.exp ../perl.exp);
103 die "where is perl.exp?\n" unless defined $perl_exp;
105 s!-bE:(\S+)!-bE:$perl_exp!;
108 elsif ($^O eq 'cygwin') { # Cygwin needs the shared libperl copied
109 my $v_e_r_s = $Config{version};
111 system("cp ../cygperl$v_e_r_s.dll ./"); # for test 1
113 elsif ($Config{'libperl'} !~ /\Alibperl\./) {
114 # Everyone needs libperl copied if it's not found by '-lperl'.
115 $testlib = $Config{'libperl'};
116 my $srclib = $testlib;
117 $testlib =~ s/.+(?=\.[^.]*)/libperl/;
118 $testlib = File::Spec::->catfile($lib, $testlib);
119 $srclib = File::Spec::->catfile($lib, $srclib);
121 unlink $testlib if -f $testlib;
122 my $ln_or_cp = $Config{'ln'} || $Config{'cp'};
123 my $lncmd = "$ln_or_cp $srclib $testlib";
125 $libperl_copied = 1 unless system($lncmd);
130 # On OS/2 the linker will always emit an empty line to STDOUT; filter these
131 my $cmd = join ' ', @cmd;
132 chomp($cmd); # where is the newline coming from? ldopts()?
136 print "# $_\n" foreach @out;
138 if ($^O eq 'VMS' && !$status) {
140 $status = system(join(' ',@cmd2));
142 print (($status? 'not ': '')."ok 1\n");
144 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
145 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
146 print "# embed_test = $embed_test\n";
147 $status = system($embed_test);
148 print (($status? 'not ':'')."ok 9 # system returned $status\n");
149 unlink($exe,"embed_test.c",$obj);
150 unlink("$exe.manifest") if $cl and $Config{'ccversion'} =~ /^(\d+)/ and $1 >= 14;
151 unlink("$exe$Config{exe_ext}") if $skip_exe;
152 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
153 unlink(glob("./*.dll")) if $^O eq 'cygwin';
154 unlink($testlib) if $libperl_copied;
156 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccflags -e ldopts`
164 #define my_puts(a) if(puts(a) < 0) exit(666)
166 static char *cmds[] = { "perl","-e", "$|=1; print qq[ok 5\\n]", NULL };
168 #ifdef PERL_GLOBAL_STRUCT_PRIVATE
169 static struct perl_vars *my_plvarsp;
170 struct perl_vars* Perl_GetVarsPrivate(void) { return my_plvarsp; }
173 #ifdef NO_ENV_ARRAY_IN_MAIN
174 extern char **environ;
175 int main(int argc, char **argv)
177 int main(int argc, char **argv, char **env)
180 PerlInterpreter *my_perl;
181 #ifdef PERL_GLOBAL_STRUCT
183 struct perl_vars *plvarsp = init_global_struct();
184 # ifdef PERL_GLOBAL_STRUCT_PRIVATE
185 my_vars = my_plvarsp = plvarsp;
187 #endif /* PERL_GLOBAL_STRUCT */
189 (void)argc; /* PERL_SYS_INIT3 may #define away their use */
191 #ifdef NO_ENV_ARRAY_IN_MAIN
192 PERL_SYS_INIT3(&argc,&argv,&environ);
194 PERL_SYS_INIT3(&argc,&argv,&env);
197 my_perl = perl_alloc();
201 perl_construct(my_perl);
205 #ifdef NO_ENV_ARRAY_IN_MAIN
206 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, environ);
208 perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
219 perl_destruct(my_perl);
225 #ifdef PERL_GLOBAL_STRUCT
226 free_global_struct(plvarsp);
227 #endif /* PERL_GLOBAL_STRUCT */