This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse.pm: handle optimised-away keys() better
[perl5.git] / win32 / config_sh.PL
1 #!perl -w
2 use strict;
3 use FindExt;
4
5 # take a semicolon separated path list and turn it into a quoted
6 # list of paths that Text::Parsewords will grok
7 sub mungepath {
8     my $p = shift;
9     # remove leading/trailing semis/spaces
10     $p =~ s/^[ ;]+//;
11     $p =~ s/[ ;]+$//;
12     $p =~ s/'/"/g;
13     my @p = map { $_ = "\"$_\"" if /\s/ and !/^".*"$/; $_ } split /;/, $p;
14     return join(' ', @p);
15 }
16
17 # generate an array of option strings from command-line args
18 # or an option file
19 #    -- added by BKS, 10-17-1999 to fix command-line overflow problems
20 sub loadopts {
21     if ($ARGV[0] =~ /--cfgsh-option-file/) {
22         shift @ARGV;
23         my $optfile = shift @ARGV;
24         local (*OPTF);
25         open OPTF, '<', $optfile or die "Can't open $optfile: $!\n";
26         my @opts;
27         chomp(my $line = <OPTF>);
28         my @vars = split(/\t+~\t+/, $line);
29         for (@vars) {
30             push(@opts, $_) unless (/^\s*$/);
31         }
32         close OPTF;
33         return \@opts;
34     }
35     else {
36         return \@ARGV;
37     }
38 }
39
40 my %opt;
41
42 my $optref = loadopts();
43 while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
44     $opt{$1}=$2;
45     shift(@{$optref});
46 }
47
48 FindExt::scan_ext("../cpan");
49 FindExt::scan_ext("../dist");
50 FindExt::scan_ext("../ext");
51 FindExt::set_static_extensions(split ' ', $opt{static_ext});
52
53 $opt{nonxs_ext}        = join(' ',FindExt::nonxs_ext()) || ' ';
54 $opt{static_ext}       = join(' ',FindExt::static_ext()) || ' ';
55 $opt{dynamic_ext}      = join(' ',FindExt::dynamic_ext()) || ' ';
56 $opt{extensions}       = join(' ',FindExt::extensions()) || ' ';
57 $opt{known_extensions} = join(' ',FindExt::known_extensions()) || ' ';
58
59 my $pl_h = '../patchlevel.h';
60
61 if (-e $pl_h) {
62     open PL, "<", $pl_h or die "Can't open $pl_h: $!";
63     while (<PL>) {
64         if (/^#\s*define\s+(PERL_\w+)\s+([\d.]+)/) {
65             $opt{$1} = $2;
66         }
67     }
68     close PL;
69 }
70 else {
71     die "Can't find $pl_h: $!";
72 }
73
74 my $patch_file = '../.patch';
75
76 if (-e $patch_file) {
77     open my $fh, "<", $patch_file or die "Can't open $patch_file: $!";
78     chomp($opt{PERL_PATCHLEVEL} = <$fh>);
79     close $fh;
80 }
81
82 $opt{version} = "$opt{PERL_REVISION}.$opt{PERL_VERSION}.$opt{PERL_SUBVERSION}";
83 $opt{version_patchlevel_string} = "version $opt{PERL_VERSION} subversion $opt{PERL_SUBVERSION}";
84 $opt{version_patchlevel_string} .= " patch $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
85
86 my $ver = `ver 2>nul`;
87 $opt{osvers} = $ver =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '4.0';
88
89 if (exists $opt{cc}) {
90     # cl version detection borrowed from Test::Smoke's configsmoke.pl
91     if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
92         my $output = `$opt{cc} 2>&1`;
93         $opt{ccversion} = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
94     }
95     elsif ($opt{cc} =~ /\bgcc\b/) {
96         chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
97     }
98 }
99
100 $opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
101 if (!$opt{cf_email}) {
102     my $computername = eval{(gethostbyname('localhost'))[0]};
103 # gethostbyname might not be implemented in miniperl
104     $computername = $ENV{COMPUTERNAME} if $@;    
105     $opt{cf_email} = $opt{cf_by} . '@' . $computername;
106 }
107 $opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
108
109 $opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
110 $opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
111
112 my $int64;
113 if ($opt{cc} =~ /\b(?:cl|icl)/) {
114     $int64  = '__int64';
115 }
116 elsif ($opt{cc} =~ /\bgcc\b/) {
117     $int64  = 'long long';
118 }
119
120 # set large files options
121 if ($opt{uselargefiles} eq 'define') {
122     $opt{lseeksize} = 8;
123     $opt{lseektype} = $int64;
124 }
125 else {
126     $opt{lseeksize} = 4;
127     $opt{lseektype} = 'long';
128 }
129
130 # set 64-bit options
131 if ($opt{WIN64} eq 'define') {
132     $opt{d_atoll} = 'define';
133     $opt{d_strtoll} = 'define';
134     $opt{d_strtoull} = 'define';
135     $opt{ptrsize} = 8;
136     $opt{sizesize} = 8;
137     $opt{ssizetype} = $int64;
138     $opt{st_ino_size} = 8;
139 }
140 else {
141     $opt{d_atoll} = 'undef';
142     $opt{d_strtoll} = 'undef';
143     $opt{d_strtoull} = 'undef';
144     $opt{ptrsize} = 4;
145     $opt{sizesize} = 4;
146     $opt{ssizetype} = 'int';
147     $opt{st_ino_size} = 4;
148 }
149
150 # set 64-bit-int options
151 if ($opt{use64bitint} eq 'define') {
152     if ($opt{uselongdouble} eq 'define') {
153         $opt{d_nv_preserves_uv} = 'define';
154         $opt{nv_preserves_uv_bits} = 64;
155     }
156     else {
157         $opt{d_nv_preserves_uv} = 'undef';
158         $opt{nv_preserves_uv_bits} = 53;
159     }
160     $opt{ivdformat} = qq{"I64d"};
161     $opt{ivsize} = 8;
162     $opt{ivtype} = $int64;
163     $opt{sPRIXU64} = qq{"I64X"};
164     $opt{sPRId64} = qq{"I64d"};
165     $opt{sPRIi64} = qq{"I64i"};
166     $opt{sPRIo64} = qq{"I64o"};
167     $opt{sPRIu64} = qq{"I64u"};
168     $opt{sPRIx64} = qq{"I64x"};
169     $opt{uvXUformat} = qq{"I64X"};
170     $opt{uvoformat} = qq{"I64o"};
171     $opt{uvsize} = 8;
172     $opt{uvtype} = qq{unsigned $int64};
173     $opt{uvuformat} = qq{"I64u"};
174     $opt{uvxformat} = qq{"I64x"};
175 }
176 else {
177     $opt{d_nv_preserves_uv} = 'define';
178     $opt{ivdformat} = '"ld"';
179     $opt{ivsize} = 4;
180     $opt{ivtype} = 'long';
181     $opt{nv_preserves_uv_bits} = 32;
182     $opt{sPRIXU64} = '"lX"';
183     $opt{sPRId64} = '"ld"';
184     $opt{sPRIi64} = '"li"';
185     $opt{sPRIo64} = '"lo"';
186     $opt{sPRIu64} = '"lu"';
187     $opt{sPRIx64} = '"lx"';
188     $opt{uvXUformat} = '"lX"';
189     $opt{uvoformat} = '"lo"';
190     $opt{uvsize} = 4;
191     $opt{uvtype} = 'unsigned long';
192     $opt{uvuformat} = '"lu"';
193     $opt{uvxformat} = '"lx"';
194 }
195
196 unless ($opt{cc} =~ /\bcl/) {
197     if ($opt{WIN64} eq 'define') {
198         $opt{longdblsize} = 16;
199         $opt{longdblinfbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00';
200         $opt{longdblnanbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00';
201     }
202     else {
203         $opt{longdblsize} = 12;
204         $opt{longdblinfbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00';
205         $opt{longdblnanbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00';
206     }
207 }
208
209 # set long double options
210 if ($opt{uselongdouble} eq 'define') {
211     $opt{d_Gconvert} = 'sprintf((b),"%.*""Lg",(n),(x))';
212     $opt{d_PRIEUldbl} = 'define';
213     $opt{d_PRIFUldbl} = 'define';
214     $opt{d_PRIGUldbl} = 'define';
215     $opt{d_frexpl} = 'define';
216     $opt{d_isnanl} = 'define';
217     $opt{d_modfl} = 'define';
218     $opt{d_modflproto} = 'define';
219     $opt{d_sqrtl} = 'define';
220     $opt{d_strtold} = 'define';
221     $opt{d_PRIeldbl} = 'define';
222     $opt{d_PRIfldbl} = 'define';
223     $opt{d_PRIgldbl} = 'define';
224     $opt{d_SCNfldbl} = 'define';
225     $opt{nvsize} = $opt{longdblsize};
226     $opt{nvtype} = 'long double';
227     $opt{nv_overflows_integers_at} = '256.0*256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0*2.0';
228     $opt{nvEUformat} = '"LE"';
229     $opt{nvFUformat} = '"LF"';
230     $opt{nvGUformat} = '"LG"';
231     $opt{nveformat} = '"Le"';
232     $opt{nvfformat} = '"Lf"';
233     $opt{nvgformat} = '"Lg"';
234     $opt{longdblkind} = 3;
235     $opt{longdblmantbits} = 64;
236 }
237 else {
238     $opt{d_Gconvert} = 'sprintf((b),"%.*g",(n),(x))';
239     $opt{d_PRIEUldbl} = 'undef';
240     $opt{d_PRIFUldbl} = 'undef';
241     $opt{d_PRIGUldbl} = 'undef';
242     $opt{d_frexpl} = 'undef';
243     $opt{d_isnanl} = 'undef';
244     $opt{d_modfl} = 'undef';
245     $opt{d_modflproto} = 'undef';
246     $opt{d_sqrtl} = 'undef';
247     $opt{d_strtold} = 'undef';
248     $opt{d_PRIeldbl} = 'undef';
249     $opt{d_PRIfldbl} = 'undef';
250     $opt{d_PRIgldbl} = 'undef';
251     $opt{d_SCNfldbl} = 'undef';
252     $opt{nvsize} = 8;
253     $opt{nvtype} = 'double';
254     $opt{nv_overflows_integers_at} = '256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0';
255     $opt{nvEUformat} = '"E"';
256     $opt{nvFUformat} = '"F"';
257     $opt{nvGUformat} = '"G"';
258     $opt{nveformat} = '"e"';
259     $opt{nvfformat} = '"f"';
260     $opt{nvgformat} = '"g"';
261 }
262
263 # change the s{GM|LOCAL}TIME_{min|max} for VS2005 (aka VC 8) and
264 # VS2008 (aka VC 9) or higher (presuming that later versions will have
265 # at least the range of that).
266 if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
267     my $ccversion = $1;
268     if ($ccversion >= 14) {
269         $opt{sGMTIME_max} = 32535291599;
270         $opt{sLOCALTIME_max} = 32535244799;
271     }
272     if ($ccversion < 13) { #VC6
273         $opt{ar} ='lib';
274     }
275     if ($ccversion >= 19) { # VC14
276         $opt{stdio_base} = 'PERLIO_FILE_base(fp)';
277         $opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
278         $opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
279         $opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
280         $opt{i_stdbool} = 'define';
281     }
282 }
283 #find out which MSVC this ICC is using
284 elsif ($opt{cc} =~ /\bicl/) {
285     my $output = `cl 2>&1`;
286     my $num_ver = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
287     if ($num_ver =~ /^(\d+)/ && $1 >= 14) {
288         $opt{sGMTIME_max} = 32535291599;
289         $opt{sLOCALTIME_max} = 32535244799;
290     }
291     if ($num_ver =~ /^(\d+)/ && $1 >= 19) { # VC14
292         $opt{stdio_base} = 'PERLIO_FILE_base(fp)';
293         $opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
294         $opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
295         $opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
296         $opt{i_stdbool} = 'define';
297     }
298     $opt{ar} ='xilib';
299 }
300
301 if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
302     $opt{d_pseudofork} = 'define';
303 }
304
305 if ($opt{usecplusplus} eq 'define') {
306     $opt{d_cplusplus} = 'define';
307     $opt{extern_C} = 'extern "C"';
308 }
309
310 #if the fields above are defined, they override the defaults in the premade
311 #config file
312 while (<>) {
313     s/~([\w_]+)~/exists $opt{$1} ? $opt{$1} : ''/eg;
314     if (/^([\w_]+)=(.*)$/) {
315         my($k,$v) = ($1,$2);
316         # this depends on cf_time being empty in the template (or we'll
317         # get a loop)
318         if ($k eq 'cf_time') {
319             $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
320         }
321         elsif (exists $opt{$k}) {
322             $_ = "$k='$opt{$k}'\n";
323         }
324     }
325     print;
326 }