Synchronize the skippage message.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / Embed.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     unshift @INC, '../lib';
6 }
7 use Config;
8 use ExtUtils::Embed;
9 use File::Spec;
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";
17 my $cc = $Config{'cc'};
18 my $cl  = ($^O eq 'MSWin32' && $cc eq 'cl');
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
22 my $obj = 'embed_test' . $Config{'obj_ext'};
23 my $inc = File::Spec->updir;
24 my $lib = File::Spec->updir;
25 my $libperl_copied;
26 my $testlib;
27 my @cmd;
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) {
50     push(@cmd,$cc,"-Fe$exe");
51    }
52    else {
53     push(@cmd,$cc,'-o' => $exe);
54    }
55    push(@cmd,"-I$inc",ccopts(),'embed_test.c');
56    if ($^O eq 'MSWin32') {
57     $inc = File::Spec->catdir($inc,'win32');
58     push(@cmd,"-I$inc");
59     $inc = File::Spec->catdir($inc,'include');
60     push(@cmd,"-I$inc");
61     if ($cc eq 'cl') {
62         push(@cmd,'-link',"-libpath:$lib",$Config{'libperl'},$Config{'libc'});
63     }
64     else {
65         push(@cmd,"-L$lib",File::Spec->catfile($lib,$Config{'libperl'}),$Config{'libc'});
66     }
67    }
68    else {
69     push(@cmd,"-L$lib",'-lperl');
70    }
71    {
72     local $SIG{__WARN__} = sub {
73         warn $_[0] unless $_[0] =~ /No library found for -lperl/
74     };
75     push(@cmd, '-Zlinker', '/PM:VIO')   # Otherwise puts a warning to STDOUT!
76         if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
77     push(@cmd,ldopts());
78    }
79
80    if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
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     }
86    }
87    elsif ($^O eq 'cygwin') { # Cygwin needs the libperl copied
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
92    }
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;
102        my $lncmd = "$Config{'ln'} $srclib $testlib";
103        #print "# $lncmd\n";
104        $libperl_copied = 1      unless system($lncmd);
105      }
106    }
107 }
108 my $status;
109 my $display_cmd = "@cmd";
110 chomp($display_cmd); # where is the newline coming from? ldopts()?
111 print "# $display_cmd\n"; 
112 $status = system(join(' ',@cmd));
113 if ($^O eq 'VMS' && !$status) {
114   print "# @cmd2\n";
115   $status = system(join(' ',@cmd2)); 
116 }
117 print (($status? 'not ': '')."ok 1\n");
118
119 my $embed_test = File::Spec->catfile(File::Spec->curdir, $exe);
120 $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
121 print "# embed_test = $embed_test\n";
122 $status = system($embed_test);
123 print (($status? 'not ':'')."ok 9 # $status\n");
124 unlink($exe,"embed_test.c",$obj);
125 unlink("$exe$Config{exe_ext}") if $skip_exe;
126 unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
127 unlink(glob("./libperl*.dll")) if $^O eq 'cygwin';
128 unlink("../libperl.a")         if $^O eq 'cygwin';
129 unlink($testlib)               if $libperl_copied;
130
131 # gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
132
133 __END__
134
135 /* perl_test.c */
136
137 #include <EXTERN.h>
138 #include <perl.h>
139
140 #define my_puts(a) if(puts(a) < 0) exit(666)
141
142 char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
143
144 int main(int argc, char **argv, char **env)
145 {
146     PerlInterpreter *my_perl = perl_alloc();
147
148     my_puts("ok 2");
149
150     perl_construct(my_perl);
151
152     my_puts("ok 3");
153
154     perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
155
156     my_puts("ok 4");
157
158     fflush(stdout);
159
160     perl_run(my_perl);
161
162     my_puts("ok 6");
163
164     perl_destruct(my_perl);
165
166     my_puts("ok 7");
167
168     perl_free(my_perl);
169
170     my_puts("ok 8");
171
172     return 0;
173 }
174
175
176
177