This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
create aTHXa, some unused dTHXs removed in /win32/*
[perl5.git] / win32 / config_h.PL
CommitLineData
2d7ad1b1
SH
1#!perl -w
2use strict;
3
1018e26f
NIS
4BEGIN { warn "Running ".__FILE__."\n" };
5BEGIN
6 {
7bd379e8
YO
7 require "Config.pm";
8 die "Config.pm:$@" if $@;
2d7ad1b1 9 Config->import;
1018e26f 10 }
137443ea 11use File::Compare qw(compare);
12use File::Copy qw(copy);
f3b9bb7d 13use File::Basename qw(fileparse);
2d7ad1b1 14
f3b9bb7d 15my ($name, $dir) = fileparse($0);
137443ea 16$name =~ s#^(.*)\.PL$#../$1.SH#;
e5a95ffb
GS
17my %opt;
18while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
19 {
20 $opt{$1}=$2;
21 shift(@ARGV);
22 }
38121b9e
GS
23
24$opt{CONFIG_H} ||= 'config.h';
7bd379e8 25$opt{CORE_DIR} ||= '../lib/CORE';
38121b9e 26
1018e26f
NIS
27warn "Writing $opt{CONFIG_H}\n";
28
137443ea 29open(SH,"<$name") || die "Cannot open $name:$!";
30while (<SH>)
31 {
a2b6a4d6 32 last if /^\s*sed/;
137443ea 33 }
2d7ad1b1 34my($term,$file,$pat) = /^\s*sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
137443ea 35
38121b9e
GS
36$file =~ s/^\$(\w+)$/$opt{$1}/g;
37
137443ea 38my $str = "sub munge\n{\n";
39
40while ($pat =~ s/-e\s+'([^']*)'\s*//)
41 {
42 my $e = $1;
43 $e =~ s/\\([\(\)])/$1/g;
44 $e =~ s/\\(\d)/\$$1/g;
45 $str .= "$e;\n";
46 }
47$str .= "}\n";
48
49eval $str;
50
51die "$str:$@" if $@;
52
53open(H,">$file.new") || die "Cannot open $file.new:$!";
54while (<SH>)
55 {
56 last if /^$term$/o;
57 s/\$([\w_]+)/Config($1)/eg;
58 s/`([^\`]*)`/BackTick($1)/eg;
59 munge();
60 s/\\\$/\$/g;
61 s#/[ *\*]*\*/#/**/#;
f3b9bb7d 62 s#(.)/\*\*/#$1/ **/# if(/^\/\*/); #avoid "/*" inside comments
4ea817c6 63 if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
acbc2db6 64 {
e6a0bbf8 65 $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "(PERL_VERSION_STRING, NULL))\t/**/\n";
acbc2db6 66 }
e5a95ffb 67 # incpush() handles archlibs, so disable them
4ea817c6 68 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
acbc2db6 69 {
f3b9bb7d 70 $_ = "/*#define ". $1 . "_EXP \"\"\t/ **/\n";
137443ea 71 }
7bef440c
SH
72 elsif (/^\s*#define\s+CPP(STDIN|RUN)\s+"gcc(.*)"\s*$/)
73 {
74 $_ = "#define CPP" . $1 . " \"" . $opt{ARCHPREFIX} . "gcc" . $2 . "\"\n";
75 }
137443ea 76 print H;
77 }
137443ea 78close(H);
79close(SH);
80
81
7bd379e8
YO
82chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
83copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
84chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");
137443ea 85
acfe0abc 86if (compare("$file.new",$file))
137443ea 87 {
88 warn "$file has changed\n";
89 chmod(0666,$file);
90 unlink($file);
91 rename("$file.new",$file);
137443ea 92 exit(1);
93 }
01f988be
GS
94else
95 {
96 unlink ("$file.new");
97 exit(0);
98 }
137443ea 99
100sub Config
101{
102 my $var = shift;
103 my $val = $Config{$var};
104 $val = 'undef' unless defined $val;
105 $val =~ s/\\/\\\\/g;
106 return $val;
107}
108
109sub BackTick
110{
111 my $cmd = shift;
112 if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
113 {
2d7ad1b1 114 my($data,$pat) = ($1,$2);
137443ea 115 $data =~ s/\s+/ /g;
116 eval "\$data =~ $pat";
117 return $data;
118 }
119 else
120 {
121 die "Cannot handle \`$cmd\`";
122 }
123 return $cmd;
124}