This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump Data::Dumper version
[perl5.git] / win32 / config_sh.PL
CommitLineData
2d7ad1b1
SH
1#!perl -w
2use strict;
8e232993 3use FindExt;
2d7ad1b1 4
80252599
GS
5# take a semicolon separated path list and turn it into a quoted
6# list of paths that Text::Parsewords will grok
7sub 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
7a958ec3
BS
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
20sub loadopts {
21 if ($ARGV[0] =~ /--cfgsh-option-file/) {
22 shift @ARGV;
23 my $optfile = shift @ARGV;
2d7ad1b1 24 local (*OPTF);
1ae6ead9 25 open OPTF, '<', $optfile or die "Can't open $optfile: $!\n";
7a958ec3
BS
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
d9f9953f
TC
40my $prebuilt; # are we making the prebuilt config used to bootstrap?
41if (@ARGV && $ARGV[0] eq '--prebuilt') {
42 ++$prebuilt;
43 shift;
44}
45
137443ea 46my %opt;
8e232993 47
7a958ec3
BS
48my $optref = loadopts();
49while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
50 $opt{$1}=$2;
51 shift(@{$optref});
52}
7bac28a0 53
338584c0 54FindExt::scan_ext("../cpan");
d284e2f9 55FindExt::scan_ext("../dist");
ca58f2ae 56FindExt::scan_ext("../ext");
6f062036 57FindExt::set_static_extensions(split ' ', $opt{static_ext});
1076f1fd 58
6f062036
SH
59$opt{nonxs_ext} = join(' ',FindExt::nonxs_ext()) || ' ';
60$opt{static_ext} = join(' ',FindExt::static_ext()) || ' ';
61$opt{dynamic_ext} = join(' ',FindExt::dynamic_ext()) || ' ';
62$opt{extensions} = join(' ',FindExt::extensions()) || ' ';
63$opt{known_extensions} = join(' ',FindExt::known_extensions()) || ' ';
8e232993 64
52b0428e
GS
65my $pl_h = '../patchlevel.h';
66
52b0428e 67if (-e $pl_h) {
1ae6ead9 68 open PL, "<", $pl_h or die "Can't open $pl_h: $!";
52b0428e
GS
69 while (<PL>) {
70 if (/^#\s*define\s+(PERL_\w+)\s+([\d.]+)/) {
71 $opt{$1} = $2;
72 }
73 }
74 close PL;
75}
e1f15930 76else {
273cf8d1 77 die "Can't find $pl_h: $!";
c90c0ff4 78}
a9277f44
SH
79
80my $patch_file = '../.patch';
81
82if (-e $patch_file) {
83 open my $fh, "<", $patch_file or die "Can't open $patch_file: $!";
84 chomp($opt{PERL_PATCHLEVEL} = <$fh>);
85 close $fh;
86}
87
6f062036
SH
88$opt{version} = "$opt{PERL_REVISION}.$opt{PERL_VERSION}.$opt{PERL_SUBVERSION}";
89$opt{version_patchlevel_string} = "version $opt{PERL_VERSION} subversion $opt{PERL_SUBVERSION}";
90$opt{version_patchlevel_string} .= " patch $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
52b0428e 91
d51fa99c 92my $ver = `ver 2>nul`;
43b354f1 93$opt{osvers} = $ver =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '4.0';
dbd14d13 94
2018b347 95if (exists $opt{cc}) {
378eeda7 96 # cl version detection borrowed from Test::Smoke's configsmoke.pl
a48cc4c4 97 if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
43b354f1
SH
98 my $output = `$opt{cc} 2>&1`;
99 $opt{ccversion} = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
2018b347 100 }
e08b586c
S
101 elsif ($opt{cc} =~ /\bgcc\b/) {
102 chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
2018b347
SH
103 }
104}
105
6f062036 106$opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
19253ae6
DD
107if (!$opt{cf_email}) {
108 my $computername = eval{(gethostbyname('localhost'))[0]};
109# gethostbyname might not be implemented in miniperl
110 $computername = $ENV{COMPUTERNAME} if $@;
111 $opt{cf_email} = $opt{cf_by} . '@' . $computername;
112}
6f062036 113$opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
d484a829 114
80252599
GS
115$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
116$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
117
683f916d 118my $int64;
a48cc4c4 119if ($opt{cc} =~ /\b(?:cl|icl)/) {
1f64ae15 120 $int64 = '__int64';
1f64ae15
SH
121}
122elsif ($opt{cc} =~ /\bgcc\b/) {
123 $int64 = 'long long';
1f64ae15
SH
124}
125
1f64ae15
SH
126# set 64-bit options
127if ($opt{WIN64} eq 'define') {
128 $opt{d_atoll} = 'define';
129 $opt{d_strtoll} = 'define';
130 $opt{d_strtoull} = 'define';
131 $opt{ptrsize} = 8;
132 $opt{sizesize} = 8;
133 $opt{ssizetype} = $int64;
134 $opt{st_ino_size} = 8;
135}
136else {
137 $opt{d_atoll} = 'undef';
138 $opt{d_strtoll} = 'undef';
139 $opt{d_strtoull} = 'undef';
140 $opt{ptrsize} = 4;
141 $opt{sizesize} = 4;
142 $opt{ssizetype} = 'int';
143 $opt{st_ino_size} = 4;
144}
890b5089
SH
145
146# set 64-bit-int options
1f64ae15 147if ($opt{use64bitint} eq 'define') {
5240fd95 148 if ($opt{uselongdouble} eq 'define' || $opt{usequadmath} eq 'define') {
890b5089
SH
149 $opt{d_nv_preserves_uv} = 'define';
150 $opt{nv_preserves_uv_bits} = 64;
151 }
152 else {
153 $opt{d_nv_preserves_uv} = 'undef';
154 $opt{nv_preserves_uv_bits} = 53;
155 }
683f916d 156 $opt{ivdformat} = qq{"I64d"};
1f64ae15
SH
157 $opt{ivsize} = 8;
158 $opt{ivtype} = $int64;
683f916d
SH
159 $opt{sPRIXU64} = qq{"I64X"};
160 $opt{sPRId64} = qq{"I64d"};
161 $opt{sPRIi64} = qq{"I64i"};
162 $opt{sPRIo64} = qq{"I64o"};
163 $opt{sPRIu64} = qq{"I64u"};
164 $opt{sPRIx64} = qq{"I64x"};
165 $opt{uvXUformat} = qq{"I64X"};
166 $opt{uvoformat} = qq{"I64o"};
1f64ae15
SH
167 $opt{uvsize} = 8;
168 $opt{uvtype} = qq{unsigned $int64};
683f916d
SH
169 $opt{uvuformat} = qq{"I64u"};
170 $opt{uvxformat} = qq{"I64x"};
1f64ae15
SH
171}
172else {
173 $opt{d_nv_preserves_uv} = 'define';
174 $opt{ivdformat} = '"ld"';
175 $opt{ivsize} = 4;
176 $opt{ivtype} = 'long';
177 $opt{nv_preserves_uv_bits} = 32;
178 $opt{sPRIXU64} = '"lX"';
179 $opt{sPRId64} = '"ld"';
180 $opt{sPRIi64} = '"li"';
181 $opt{sPRIo64} = '"lo"';
182 $opt{sPRIu64} = '"lu"';
183 $opt{sPRIx64} = '"lx"';
184 $opt{uvXUformat} = '"lX"';
185 $opt{uvoformat} = '"lo"';
186 $opt{uvsize} = 4;
187 $opt{uvtype} = 'unsigned long';
188 $opt{uvuformat} = '"lu"';
189 $opt{uvxformat} = '"lx"';
4a9d6100
GS
190}
191
c0bf9074
TC
192unless ($opt{cc} =~ /\bcl/) {
193 if ($opt{WIN64} eq 'define') {
194 $opt{longdblsize} = 16;
195 $opt{longdblinfbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00';
196 $opt{longdblnanbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00';
197 }
198 else {
199 $opt{longdblsize} = 12;
200 $opt{longdblinfbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00';
201 $opt{longdblnanbytes} = '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00';
202 }
203}
204
890b5089
SH
205# set long double options
206if ($opt{uselongdouble} eq 'define') {
207 $opt{d_Gconvert} = 'sprintf((b),"%.*""Lg",(n),(x))';
208 $opt{d_PRIEUldbl} = 'define';
209 $opt{d_PRIFUldbl} = 'define';
210 $opt{d_PRIGUldbl} = 'define';
890b5089 211 $opt{d_modflproto} = 'define';
890b5089
SH
212 $opt{d_strtold} = 'define';
213 $opt{d_PRIeldbl} = 'define';
214 $opt{d_PRIfldbl} = 'define';
215 $opt{d_PRIgldbl} = 'define';
216 $opt{d_SCNfldbl} = 'define';
c0bf9074 217 $opt{nvsize} = $opt{longdblsize};
890b5089
SH
218 $opt{nvtype} = 'long double';
219 $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';
220 $opt{nvEUformat} = '"LE"';
221 $opt{nvFUformat} = '"LF"';
222 $opt{nvGUformat} = '"LG"';
223 $opt{nveformat} = '"Le"';
224 $opt{nvfformat} = '"Lf"';
225 $opt{nvgformat} = '"Lg"';
39d5361c 226 $opt{nvmantbits} = 64;
c0bf9074
TC
227 $opt{longdblkind} = 3;
228 $opt{longdblmantbits} = 64;
890b5089 229}
5240fd95 230# set __float128 options
231elsif ($opt{usequadmath} eq 'define') {
232 $opt{d_Gconvert} = 'sprintf((b),"%.*""Lg",(n),(x))';
233 $opt{d_PRIEUldbl} = 'define';
234 $opt{d_PRIFUldbl} = 'define';
235 $opt{d_PRIGUldbl} = 'define';
236 $opt{d_modflproto} = 'define';
237 $opt{d_strtold} = 'define';
238 $opt{d_PRIeldbl} = 'define';
239 $opt{d_PRIfldbl} = 'define';
240 $opt{d_PRIgldbl} = 'define';
241 $opt{d_SCNfldbl} = 'define';
242 $opt{nv_overflows_integers_at} = '256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*256.0*2.0';
243 $opt{nvsize} = 16;
244 $opt{nvtype} = '__float128';
245 $opt{nvEUformat} = '"QE"';
246 $opt{nvFUformat} = '"QF"';
247 $opt{nvGUformat} = '"QG"';
248 $opt{nveformat} = '"Qe"';
249 $opt{nvfformat} = '"Qf"';
250 $opt{nvgformat} = '"Qg"';
251 $opt{nvmantbits} = 112;
252 $opt{longdblkind} = 3;
253 $opt{longdblmantbits} = 64;
254 $opt{i_quadmath} = 'define';
255}
890b5089
SH
256else {
257 $opt{d_Gconvert} = 'sprintf((b),"%.*g",(n),(x))';
258 $opt{d_PRIEUldbl} = 'undef';
259 $opt{d_PRIFUldbl} = 'undef';
260 $opt{d_PRIGUldbl} = 'undef';
76c38d91 261
262 if($opt{cc} =~ /\b(?:cl|icl)/) {
263 $opt{d_modflproto} = 'undef';
264 }
265 else {
266 $opt{d_modflproto} = 'define';
267 }
268
890b5089
SH
269 $opt{d_strtold} = 'undef';
270 $opt{d_PRIeldbl} = 'undef';
271 $opt{d_PRIfldbl} = 'undef';
272 $opt{d_PRIgldbl} = 'undef';
273 $opt{d_SCNfldbl} = 'undef';
274 $opt{nvsize} = 8;
275 $opt{nvtype} = 'double';
276 $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';
277 $opt{nvEUformat} = '"E"';
278 $opt{nvFUformat} = '"F"';
279 $opt{nvGUformat} = '"G"';
280 $opt{nveformat} = '"e"';
281 $opt{nvfformat} = '"f"';
282 $opt{nvgformat} = '"g"';
283}
284
1a9ff134 285# change some configuration variables based on compiler version
58ff4bd0 286if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
4b7e285e 287 my $ccversion = $1;
1a9ff134 288 if ($ccversion >= 14) { # VC8+
4b7e285e 289 $opt{sGMTIME_max} = 32535291599;
049aaf37 290 $opt{sLOCALTIME_max} = 32535244799;
4b7e285e 291 }
d9f9953f 292 if ($ccversion >= 16 && !$prebuilt) { # VC10+
1a9ff134 293 $opt{i_stdint} = 'define';
a9e3f359 294 }
1a9ff134 295 if ($ccversion >= 19) { # VC14+
1f664ef5
SH
296 $opt{stdio_base} = 'PERLIO_FILE_base(fp)';
297 $opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
298 $opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
299 $opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
d9f9953f 300 $opt{i_stdbool} = 'define' unless $prebuilt;
1f664ef5 301 }
4b7e285e 302}
1a9ff134 303# find out which MSVC this ICC is using
a48cc4c4 304elsif ($opt{cc} =~ /\bicl/) {
43b354f1
SH
305 my $output = `cl 2>&1`;
306 my $num_ver = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
1a9ff134 307 if ($num_ver =~ /^(\d+)/ && $1 >= 14) { # VC8+
a48cc4c4
DD
308 $opt{sGMTIME_max} = 32535291599;
309 $opt{sLOCALTIME_max} = 32535244799;
310 }
1a9ff134
SH
311 if ($num_ver =~ /^(\d+)/ && $1 >= 16) { # VC10+
312 $opt{i_stdint} = 'define';
313 }
314 if ($num_ver =~ /^(\d+)/ && $1 >= 19) { # VC14+
1f664ef5
SH
315 $opt{stdio_base} = 'PERLIO_FILE_base(fp)';
316 $opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
317 $opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
318 $opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
319 $opt{i_stdbool} = 'define';
320 }
a48cc4c4
DD
321 $opt{ar} ='xilib';
322}
4b7e285e 323
1fd1213a 324if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
27bdbd07
SH
325 $opt{d_pseudofork} = 'define';
326}
327
f9bbfafd
SH
328if ($opt{usecplusplus} eq 'define') {
329 $opt{d_cplusplus} = 'define';
330 $opt{extern_C} = 'extern "C"';
331}
332
a9e3f359
DD
333#if the fields above are defined, they override the defaults in the premade
334#config file
7a958ec3 335while (<>) {
2d7ad1b1 336 s/~([\w_]+)~/exists $opt{$1} ? $opt{$1} : ''/eg;
7a958ec3
BS
337 if (/^([\w_]+)=(.*)$/) {
338 my($k,$v) = ($1,$2);
339 # this depends on cf_time being empty in the template (or we'll
340 # get a loop)
341 if ($k eq 'cf_time') {
342 $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
343 }
344 elsif (exists $opt{$k}) {
345 $_ = "$k='$opt{$k}'\n";
346 }
dc050285 347 }
7a958ec3
BS
348 print;
349}