Add a --chdir option to configpm, and use this in the Win32 Makfiles.
[p5sagit/p5-mst-13.2.git] / win32 / config_sh.PL
CommitLineData
8e232993 1use FindExt;
80252599 2# take a semicolon separated path list and turn it into a quoted
3# list of paths that Text::Parsewords will grok
4sub mungepath {
5 my $p = shift;
6 # remove leading/trailing semis/spaces
7 $p =~ s/^[ ;]+//;
8 $p =~ s/[ ;]+$//;
9 $p =~ s/'/"/g;
10 my @p = map { $_ = "\"$_\"" if /\s/ and !/^".*"$/; $_ } split /;/, $p;
11 return join(' ', @p);
12}
13
7a958ec3 14# generate an array of option strings from command-line args
15# or an option file
16# -- added by BKS, 10-17-1999 to fix command-line overflow problems
17sub loadopts {
18 if ($ARGV[0] =~ /--cfgsh-option-file/) {
19 shift @ARGV;
20 my $optfile = shift @ARGV;
21 local (*F);
22 open OPTF, $optfile or die "Can't open $optfile: $!\n";
23 my @opts;
24 chomp(my $line = <OPTF>);
25 my @vars = split(/\t+~\t+/, $line);
26 for (@vars) {
27 push(@opts, $_) unless (/^\s*$/);
28 }
29 close OPTF;
30 return \@opts;
31 }
32 else {
33 return \@ARGV;
34 }
35}
36
137443ea 37my %opt;
8e232993 38
7a958ec3 39my $optref = loadopts();
40while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
41 $opt{$1}=$2;
42 shift(@{$optref});
43}
7bac28a0 44
ca58f2ae 45FindExt::scan_ext("../ext");
46FindExt::set_static_extensions(split ' ', $opt{'static_ext'});
1076f1fd 47
ca58f2ae 48$opt{'nonxs_ext'} = join(' ',FindExt::nonxs_ext()) || ' ';
49$opt{'static_ext'} = join(' ',FindExt::static_ext()) || ' ';
47f9f84c 50$opt{'dynamic_ext'} = join(' ',FindExt::dynamic_ext()) || ' ';
51$opt{'extensions'} = join(' ',FindExt::extensions()) || ' ';
ca58f2ae 52$opt{'known_extensions'} = join(' ',FindExt::known_extensions()) || ' ';
8e232993 53
52b0428e 54my $pl_h = '../patchlevel.h';
55
52b0428e 56if (-e $pl_h) {
57 open PL, "<$pl_h" or die "Can't open $pl_h: $!";
58 while (<PL>) {
59 if (/^#\s*define\s+(PERL_\w+)\s+([\d.]+)/) {
60 $opt{$1} = $2;
61 }
62 }
63 close PL;
64}
e1f15930 65else {
273cf8d1 66 die "Can't find $pl_h: $!";
c90c0ff4 67}
a9277f44 68
69my $patch_file = '../.patch';
70
71if (-e $patch_file) {
72 open my $fh, "<", $patch_file or die "Can't open $patch_file: $!";
73 chomp($opt{PERL_PATCHLEVEL} = <$fh>);
74 close $fh;
75}
76
273cf8d1 77$opt{VERSION} = "$opt{PERL_REVISION}.$opt{PERL_VERSION}.$opt{PERL_SUBVERSION}";
78$opt{INST_VER} =~ s|~VERSION~|$opt{VERSION}|g;
fd390a00 79$opt{'version_patchlevel_string'} = "version $opt{PERL_VERSION} subversion $opt{PERL_SUBVERSION}";
79a3ac15 80$opt{'version_patchlevel_string'} .= " patch $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
52b0428e 81
d51fa99c 82my $ver = `ver 2>nul`;
83if ($ver =~ /Version (\d+\.\d+)/) {
84 $opt{'osvers'} = $1;
85}
86else {
87 $opt{'osvers'} = '4.0';
88}
dbd14d13 89
2018b347 90if (exists $opt{cc}) {
91 # cl and bcc32 version detection borrowed from Test::Smoke's configsmoke.pl
92 if ($opt{cc} eq 'cl') {
93 my $output = `cl --version 2>&1`;
94 $opt{ccversion} = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
95 }
96 elsif ($opt{cc} eq 'bcc32') {
97 my $output = `bcc32 --version 2>&1`;
645ff3cb 98 $opt{ccversion} = $output =~ /([\d.]+)/ ? $1 : '?';
2018b347 99 }
100 elsif ($opt{cc} eq 'gcc') {
101 chomp($opt{gccversion} = `gcc -dumpversion`);
102 }
103}
104
d484a829 105$opt{'cf_by'} = $ENV{USERNAME} unless $opt{'cf_by'};
106$opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
107 unless $opt{'cf_email'};
852c2e52 108$opt{'usemymalloc'} = 'y' if $opt{'d_mymalloc'} eq 'define';
d484a829 109
80252599 110$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
111$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
112
108967c2 113# some functions are not available on Win9x
cf2f24a4 114unless (defined $ENV{SYSTEMROOT}) { # SystemRoot has been introduced by WinNT
108967c2 115 $opt{d_flock} = 'undef';
116 $opt{d_link} = 'undef';
117}
118
f7e8b52a 119# change the lseeksize and lseektype from their canned default values (which
120# are set-up for a non-uselargefiles build) if we are building with
121# uselargefiles. don't do this for bcc32: the code contains special handling
122# for bcc32 and the lseeksize and lseektype should not be changed.
123if ($opt{uselargefiles} eq 'define' and $opt{cc} ne 'bcc32') {
124 $opt{lseeksize} = 8;
125 if ($opt{cc} eq 'cl') {
126 $opt{lseektype} = '__int64';
127 }
128 elsif ($opt{cc} eq 'gcc') {
129 $opt{lseektype} = 'long long';
130 }
4a9d6100 131}
132
049aaf37 133# change the s{GM|LOCAL}TIME_{min|max} for VS2005 (aka VC 8) and
4b7e285e 134# VS2008 (aka VC 9) or higher (presuming that later versions will have
135# at least the range of that).
136if ($opt{cc} eq 'cl' and $opt{ccversion} =~ /^(\d+)/) {
137 my $ccversion = $1;
92e71c91 138 if ($ccversion >= 14) {
4b7e285e 139 $opt{sGMTIME_max} = 32535291599;
049aaf37 140 $opt{sLOCALTIME_max} = 32535244799;
4b7e285e 141 }
142}
143
1fd1213a 144if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
27bdbd07 145 $opt{d_pseudofork} = 'define';
146}
147
7a958ec3 148while (<>) {
149 s/~([\w_]+)~/$opt{$1}/g;
150 if (/^([\w_]+)=(.*)$/) {
151 my($k,$v) = ($1,$2);
152 # this depends on cf_time being empty in the template (or we'll
153 # get a loop)
154 if ($k eq 'cf_time') {
155 $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
156 }
157 elsif (exists $opt{$k}) {
158 $_ = "$k='$opt{$k}'\n";
159 }
dc050285 160 }
7a958ec3 161 print;
162}