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