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