This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #120903] fix a typo
[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);
7a958ec3
BS
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
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
GS
61if (-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}
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
SH
86my $ver = `ver 2>nul`;
87if ($ver =~ /Version (\d+\.\d+)/) {
6f062036 88 $opt{osvers} = $1;
d51fa99c
SH
89}
90else {
6f062036 91 $opt{osvers} = '4.0';
d51fa99c 92}
dbd14d13 93
2018b347 94if (exists $opt{cc}) {
378eeda7 95 # cl version detection borrowed from Test::Smoke's configsmoke.pl
a48cc4c4 96 if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
58ff4bd0 97 my $output = `$opt{cc} --version 2>&1`;
2018b347
SH
98 $opt{ccversion} = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
99 }
e08b586c
S
100 elsif ($opt{cc} =~ /\bgcc\b/) {
101 chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
2018b347
SH
102 }
103}
104
6f062036 105$opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
19253ae6
DD
106if (!$opt{cf_email}) {
107 my $computername = eval{(gethostbyname('localhost'))[0]};
108# gethostbyname might not be implemented in miniperl
109 $computername = $ENV{COMPUTERNAME} if $@;
110 $opt{cf_email} = $opt{cf_by} . '@' . $computername;
111}
6f062036 112$opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
d484a829 113
80252599
GS
114$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
115$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
116
683f916d 117my $int64;
a48cc4c4 118if ($opt{cc} =~ /\b(?:cl|icl)/) {
1f64ae15 119 $int64 = '__int64';
1f64ae15
SH
120}
121elsif ($opt{cc} =~ /\bgcc\b/) {
122 $int64 = 'long long';
1f64ae15
SH
123}
124
125# set large files options
378eeda7 126if ($opt{uselargefiles} eq 'define') {
f7e8b52a 127 $opt{lseeksize} = 8;
1f64ae15
SH
128 $opt{lseektype} = $int64;
129}
130else {
131 $opt{lseeksize} = 4;
132 $opt{lseektype} = 'long';
133}
134
135# set 64-bit options
136if ($opt{WIN64} eq 'define') {
137 $opt{d_atoll} = 'define';
138 $opt{d_strtoll} = 'define';
139 $opt{d_strtoull} = 'define';
140 $opt{ptrsize} = 8;
141 $opt{sizesize} = 8;
142 $opt{ssizetype} = $int64;
143 $opt{st_ino_size} = 8;
144}
145else {
146 $opt{d_atoll} = 'undef';
147 $opt{d_strtoll} = 'undef';
148 $opt{d_strtoull} = 'undef';
149 $opt{ptrsize} = 4;
150 $opt{sizesize} = 4;
151 $opt{ssizetype} = 'int';
152 $opt{st_ino_size} = 4;
153}
890b5089
SH
154
155# set 64-bit-int options
1f64ae15 156if ($opt{use64bitint} eq 'define') {
890b5089
SH
157 if ($opt{uselongdouble} eq 'define') {
158 $opt{d_nv_preserves_uv} = 'define';
159 $opt{nv_preserves_uv_bits} = 64;
160 }
161 else {
162 $opt{d_nv_preserves_uv} = 'undef';
163 $opt{nv_preserves_uv_bits} = 53;
164 }
683f916d 165 $opt{ivdformat} = qq{"I64d"};
1f64ae15
SH
166 $opt{ivsize} = 8;
167 $opt{ivtype} = $int64;
683f916d
SH
168 $opt{sPRIXU64} = qq{"I64X"};
169 $opt{sPRId64} = qq{"I64d"};
170 $opt{sPRIi64} = qq{"I64i"};
171 $opt{sPRIo64} = qq{"I64o"};
172 $opt{sPRIu64} = qq{"I64u"};
173 $opt{sPRIx64} = qq{"I64x"};
174 $opt{uvXUformat} = qq{"I64X"};
175 $opt{uvoformat} = qq{"I64o"};
1f64ae15
SH
176 $opt{uvsize} = 8;
177 $opt{uvtype} = qq{unsigned $int64};
683f916d
SH
178 $opt{uvuformat} = qq{"I64u"};
179 $opt{uvxformat} = qq{"I64x"};
1f64ae15
SH
180}
181else {
182 $opt{d_nv_preserves_uv} = 'define';
183 $opt{ivdformat} = '"ld"';
184 $opt{ivsize} = 4;
185 $opt{ivtype} = 'long';
186 $opt{nv_preserves_uv_bits} = 32;
187 $opt{sPRIXU64} = '"lX"';
188 $opt{sPRId64} = '"ld"';
189 $opt{sPRIi64} = '"li"';
190 $opt{sPRIo64} = '"lo"';
191 $opt{sPRIu64} = '"lu"';
192 $opt{sPRIx64} = '"lx"';
193 $opt{uvXUformat} = '"lX"';
194 $opt{uvoformat} = '"lo"';
195 $opt{uvsize} = 4;
196 $opt{uvtype} = 'unsigned long';
197 $opt{uvuformat} = '"lu"';
198 $opt{uvxformat} = '"lx"';
4a9d6100
GS
199}
200
890b5089
SH
201# set long double options
202if ($opt{uselongdouble} eq 'define') {
203 $opt{d_Gconvert} = 'sprintf((b),"%.*""Lg",(n),(x))';
204 $opt{d_PRIEUldbl} = 'define';
205 $opt{d_PRIFUldbl} = 'define';
206 $opt{d_PRIGUldbl} = 'define';
207 $opt{d_frexpl} = 'define';
208 $opt{d_isnanl} = 'define';
209 $opt{d_modfl} = 'define';
210 $opt{d_modflproto} = 'define';
211 $opt{d_sqrtl} = 'define';
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';
82319b0c
SH
217 if ($opt{WIN64} eq 'define') {
218 $opt{longdblsize} = 16;
219 $opt{nvsize} = 16;
220 }
221 else {
222 $opt{longdblsize} = 12;
223 $opt{nvsize} = 12;
224 }
890b5089
SH
225 $opt{nvtype} = 'long double';
226 $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';
227 $opt{nvEUformat} = '"LE"';
228 $opt{nvFUformat} = '"LF"';
229 $opt{nvGUformat} = '"LG"';
230 $opt{nveformat} = '"Le"';
231 $opt{nvfformat} = '"Lf"';
232 $opt{nvgformat} = '"Lg"';
233}
234else {
235 $opt{d_Gconvert} = 'sprintf((b),"%.*g",(n),(x))';
236 $opt{d_PRIEUldbl} = 'undef';
237 $opt{d_PRIFUldbl} = 'undef';
238 $opt{d_PRIGUldbl} = 'undef';
239 $opt{d_frexpl} = 'undef';
240 $opt{d_isnanl} = 'undef';
241 $opt{d_modfl} = 'undef';
242 $opt{d_modflproto} = 'undef';
243 $opt{d_sqrtl} = 'undef';
244 $opt{d_strtold} = 'undef';
245 $opt{d_PRIeldbl} = 'undef';
246 $opt{d_PRIfldbl} = 'undef';
247 $opt{d_PRIgldbl} = 'undef';
248 $opt{d_SCNfldbl} = 'undef';
82319b0c 249 $opt{longdblsize} = 8;
890b5089
SH
250 $opt{nvsize} = 8;
251 $opt{nvtype} = 'double';
252 $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';
253 $opt{nvEUformat} = '"E"';
254 $opt{nvFUformat} = '"F"';
255 $opt{nvGUformat} = '"G"';
256 $opt{nveformat} = '"e"';
257 $opt{nvfformat} = '"f"';
258 $opt{nvgformat} = '"g"';
259}
260
049aaf37 261# change the s{GM|LOCAL}TIME_{min|max} for VS2005 (aka VC 8) and
4b7e285e
JD
262# VS2008 (aka VC 9) or higher (presuming that later versions will have
263# at least the range of that).
58ff4bd0 264if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
4b7e285e 265 my $ccversion = $1;
92e71c91 266 if ($ccversion >= 14) {
4b7e285e 267 $opt{sGMTIME_max} = 32535291599;
049aaf37 268 $opt{sLOCALTIME_max} = 32535244799;
4b7e285e 269 }
a9e3f359
DD
270 if($ccversion < 13) { #VC6
271 $opt{ar} ='lib';
272 }
4b7e285e 273}
a48cc4c4
DD
274#find out which MSVC this ICC is using
275elsif ($opt{cc} =~ /\bicl/) {
276 my $output = `cl --version 2>&1`;
277 my $num_ver = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
278 if($num_ver =~ /^(\d+)/ && $1 >= 14) {
279 $opt{sGMTIME_max} = 32535291599;
280 $opt{sLOCALTIME_max} = 32535244799;
281 }
282 $opt{ar} ='xilib';
283}
4b7e285e 284
1fd1213a 285if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
27bdbd07
SH
286 $opt{d_pseudofork} = 'define';
287}
288
f9bbfafd
SH
289if ($opt{usecplusplus} eq 'define') {
290 $opt{d_cplusplus} = 'define';
291 $opt{extern_C} = 'extern "C"';
292}
293
a9e3f359
DD
294#if the fields above are defined, they override the defaults in the premade
295#config file
7a958ec3 296while (<>) {
2d7ad1b1 297 s/~([\w_]+)~/exists $opt{$1} ? $opt{$1} : ''/eg;
7a958ec3
BS
298 if (/^([\w_]+)=(.*)$/) {
299 my($k,$v) = ($1,$2);
300 # this depends on cf_time being empty in the template (or we'll
301 # get a loop)
302 if ($k eq 'cf_time') {
303 $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
304 }
305 elsif (exists $opt{$k}) {
306 $_ = "$k='$opt{$k}'\n";
307 }
dc050285 308 }
7a958ec3
BS
309 print;
310}