xref: /openbsd-src/gnu/usr.bin/perl/win32/config_sh.PL (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#!perl -w
2use strict;
3use FindExt;
4
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
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;
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
40my %opt;
41
42my $optref = loadopts();
43while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
44    $opt{$1}=$2;
45    shift(@{$optref});
46}
47
48FindExt::scan_ext("../cpan");
49FindExt::scan_ext("../dist");
50FindExt::scan_ext("../ext");
51FindExt::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
59my $pl_h = '../patchlevel.h';
60
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}
70else {
71    die "Can't find $pl_h: $!";
72}
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
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
86my $ver = `ver 2>nul`;
87if ($ver =~ /Version (\d+\.\d+)/) {
88    $opt{osvers} = $1;
89}
90else {
91    $opt{osvers} = '4.0';
92}
93
94if (exists $opt{cc}) {
95    # cl version detection borrowed from Test::Smoke's configsmoke.pl
96    if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
97        my $output = `$opt{cc} --version 2>&1`;
98        $opt{ccversion} = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
99    }
100    elsif ($opt{cc} =~ /\bgcc\b/) {
101        chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
102    }
103}
104
105$opt{cf_by} = $ENV{USERNAME} unless $opt{cf_by};
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}
112$opt{usemymalloc} = 'y' if $opt{d_mymalloc} eq 'define';
113
114$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
115$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
116
117my($int64, $int64f);
118if ($opt{cc} =~ /\b(?:cl|icl)/) {
119    $int64  = '__int64';
120    $int64f = 'I64';
121}
122elsif ($opt{cc} =~ /\bgcc\b/) {
123    $int64  = 'long long';
124    $int64f = 'I64';
125}
126
127# set large files options
128if ($opt{uselargefiles} eq 'define') {
129    $opt{lseeksize} = 8;
130    $opt{lseektype} = $int64;
131}
132else {
133    $opt{lseeksize} = 4;
134    $opt{lseektype} = 'long';
135}
136
137# set 64-bit options
138if ($opt{WIN64} eq 'define') {
139    $opt{d_atoll} = 'define';
140    $opt{d_strtoll} = 'define';
141    $opt{d_strtoull} = 'define';
142    $opt{ptrsize} = 8;
143    $opt{sizesize} = 8;
144    $opt{ssizetype} = $int64;
145    $opt{st_ino_size} = 8;
146}
147else {
148    $opt{d_atoll} = 'undef';
149    $opt{d_strtoll} = 'undef';
150    $opt{d_strtoull} = 'undef';
151    $opt{ptrsize} = 4;
152    $opt{sizesize} = 4;
153    $opt{ssizetype} = 'int';
154    $opt{st_ino_size} = 4;
155}
156if ($opt{use64bitint} eq 'define') {
157    $opt{d_nv_preserves_uv} = 'undef';
158    $opt{ivdformat} = qq{"${int64f}d"};
159    $opt{ivsize} = 8;
160    $opt{ivtype} = $int64;
161    $opt{nv_preserves_uv_bits} = 53;
162    $opt{sPRIXU64} = qq{"${int64f}X"};
163    $opt{sPRId64} = qq{"${int64f}d"};
164    $opt{sPRIi64} = qq{"${int64f}i"};
165    $opt{sPRIo64} = qq{"${int64f}o"};
166    $opt{sPRIu64} = qq{"${int64f}u"};
167    $opt{sPRIx64} = qq{"${int64f}x"};
168    $opt{uvXUformat} = qq{"${int64f}X"};
169    $opt{uvoformat} = qq{"${int64f}o"};
170    $opt{uvsize} = 8;
171    $opt{uvtype} = qq{unsigned $int64};
172    $opt{uvuformat} = qq{"${int64f}u"};
173    $opt{uvxformat} = qq{"${int64f}x"};
174}
175else {
176    $opt{d_nv_preserves_uv} = 'define';
177    $opt{ivdformat} = '"ld"';
178    $opt{ivsize} = 4;
179    $opt{ivtype} = 'long';
180    $opt{nv_preserves_uv_bits} = 32;
181    $opt{sPRIXU64} = '"lX"';
182    $opt{sPRId64} = '"ld"';
183    $opt{sPRIi64} = '"li"';
184    $opt{sPRIo64} = '"lo"';
185    $opt{sPRIu64} = '"lu"';
186    $opt{sPRIx64} = '"lx"';
187    $opt{uvXUformat} = '"lX"';
188    $opt{uvoformat} = '"lo"';
189    $opt{uvsize} = 4;
190    $opt{uvtype} = 'unsigned long';
191    $opt{uvuformat} = '"lu"';
192    $opt{uvxformat} = '"lx"';
193}
194
195# change the s{GM|LOCAL}TIME_{min|max} for VS2005 (aka VC 8) and
196# VS2008 (aka VC 9) or higher (presuming that later versions will have
197# at least the range of that).
198if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
199    my $ccversion = $1;
200    if ($ccversion >= 14) {
201	$opt{sGMTIME_max} = 32535291599;
202	$opt{sLOCALTIME_max} = 32535244799;
203    }
204    if($ccversion < 13) { #VC6
205	$opt{ar} ='lib';
206    }
207}
208#find out which MSVC this ICC is using
209elsif ($opt{cc} =~ /\bicl/) {
210    my $output = `cl --version 2>&1`;
211    my $num_ver = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
212    if($num_ver =~ /^(\d+)/ && $1 >= 14) {
213	$opt{sGMTIME_max} = 32535291599;
214	$opt{sLOCALTIME_max} = 32535244799;
215    }
216    $opt{ar} ='xilib';
217}
218
219if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
220    $opt{d_pseudofork} = 'define';
221}
222
223#if the fields above are defined, they override the defaults in the premade
224#config file
225while (<>) {
226    s/~([\w_]+)~/exists $opt{$1} ? $opt{$1} : ''/eg;
227    if (/^([\w_]+)=(.*)$/) {
228	my($k,$v) = ($1,$2);
229	# this depends on cf_time being empty in the template (or we'll
230	# get a loop)
231	if ($k eq 'cf_time') {
232	    $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
233	}
234	elsif (exists $opt{$k}) {
235	    $_ = "$k='$opt{$k}'\n";
236	}
237    }
238    print;
239}
240