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