This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fixing a Perl_my_dirfd() related test failure.
[perl5.git] / win32 / config_sh.PL
CommitLineData
8e232993 1use FindExt;
80252599
GS
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
BS
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
BS
39my $optref = loadopts();
40while (@{$optref} && $optref->[0] =~ /^([\w_]+)=(.*)$/) {
41 $opt{$1}=$2;
42 shift(@{$optref});
43}
7bac28a0 44
ca58f2ae 45FindExt::scan_ext("../ext");
78ff2d7b 46FindExt::scan_ext("ext") if -d 'ext'; # also look in win32/ext/ if it exists
ca58f2ae 47FindExt::set_static_extensions(split ' ', $opt{'static_ext'});
1076f1fd 48
0eff23c1
SH
49my @dynamic_ext = grep(!/Thread/,FindExt::dynamic_ext());
50my @extensions = grep(!/Thread/,FindExt::extensions());
ca58f2ae
YST
51$opt{'nonxs_ext'} = join(' ',FindExt::nonxs_ext()) || ' ';
52$opt{'static_ext'} = join(' ',FindExt::static_ext()) || ' ';
0eff23c1
SH
53$opt{'dynamic_ext'} = join(' ',@dynamic_ext) || ' ';
54$opt{'extensions'} = join(' ',@extensions) || ' ';
ca58f2ae 55$opt{'known_extensions'} = join(' ',FindExt::known_extensions()) || ' ';
8e232993 56
52b0428e
GS
57my $pl_h = '../patchlevel.h';
58
52b0428e
GS
59if (-e $pl_h) {
60 open PL, "<$pl_h" or die "Can't open $pl_h: $!";
61 while (<PL>) {
62 if (/^#\s*define\s+(PERL_\w+)\s+([\d.]+)/) {
63 $opt{$1} = $2;
64 }
65 }
66 close PL;
67}
e1f15930 68else {
273cf8d1 69 die "Can't find $pl_h: $!";
c90c0ff4 70}
273cf8d1
GS
71$opt{VERSION} = "$opt{PERL_REVISION}.$opt{PERL_VERSION}.$opt{PERL_SUBVERSION}";
72$opt{INST_VER} =~ s|~VERSION~|$opt{VERSION}|g;
fd390a00
JH
73$opt{'version_patchlevel_string'} = "version $opt{PERL_VERSION} subversion $opt{PERL_SUBVERSION}";
74$opt{'version_patchlevel_string'} .= " patchlevel $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
52b0428e 75
d51fa99c
SH
76my $ver = `ver 2>nul`;
77if ($ver =~ /Version (\d+\.\d+)/) {
78 $opt{'osvers'} = $1;
79}
80else {
81 $opt{'osvers'} = '4.0';
82}
dbd14d13 83
2018b347
SH
84if (exists $opt{cc}) {
85 # cl and bcc32 version detection borrowed from Test::Smoke's configsmoke.pl
86 if ($opt{cc} eq 'cl') {
87 my $output = `cl --version 2>&1`;
88 $opt{ccversion} = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
89 }
90 elsif ($opt{cc} eq 'bcc32') {
91 my $output = `bcc32 --version 2>&1`;
645ff3cb 92 $opt{ccversion} = $output =~ /([\d.]+)/ ? $1 : '?';
2018b347
SH
93 }
94 elsif ($opt{cc} eq 'gcc') {
95 chomp($opt{gccversion} = `gcc -dumpversion`);
96 }
97}
98
d484a829
GS
99$opt{'cf_by'} = $ENV{USERNAME} unless $opt{'cf_by'};
100$opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
101 unless $opt{'cf_email'};
852c2e52 102$opt{'usemymalloc'} = 'y' if $opt{'d_mymalloc'} eq 'define';
d484a829 103
80252599
GS
104$opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
105$opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
106
108967c2 107# some functions are not available on Win9x
cf2f24a4 108unless (defined $ENV{SYSTEMROOT}) { # SystemRoot has been introduced by WinNT
108967c2
GS
109 $opt{d_flock} = 'undef';
110 $opt{d_link} = 'undef';
111}
112
4a9d6100
GS
113if ($opt{uselargefiles} ne 'define') {
114 $opt{lseeksize} = 4;
115 $opt{lseektype} = 'off_t';
116}
117
1fd1213a 118if ($opt{useithreads} eq 'define' && $opt{ccflags} =~ /-DPERL_IMPLICIT_SYS\b/) {
27bdbd07
SH
119 $opt{d_pseudofork} = 'define';
120}
121
7a958ec3
BS
122while (<>) {
123 s/~([\w_]+)~/$opt{$1}/g;
124 if (/^([\w_]+)=(.*)$/) {
125 my($k,$v) = ($1,$2);
126 # this depends on cf_time being empty in the template (or we'll
127 # get a loop)
128 if ($k eq 'cf_time') {
129 $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
130 }
131 elsif (exists $opt{$k}) {
132 $_ = "$k='$opt{$k}'\n";
133 }
dc050285 134 }
7a958ec3
BS
135 print;
136}