This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert change #22520 (optimise away my $foo = undef and similar
[perl5.git] / wince / config_h.PL
CommitLineData
e1caacb4 1#
18f68570
VK
2BEGIN { warn "Running ".__FILE__."\n" };
3BEGIN
4 {
3f2394f2
VK
5 require "Config.pm";
6 die "Config.pm:$@" if $@;
18f68570
VK
7 Config::->import;
8 }
e1caacb4
JH
9use File::Compare qw(compare);
10use File::Copy qw(copy);
e1caacb4
JH
11my $name = $0;
12$name =~ s#^(.*)\.PL$#../$1.SH#;
13my %opt;
14while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
15 {
16 $opt{$1}=$2;
17 shift(@ARGV);
18 }
19
20$opt{CONFIG_H} ||= 'config.h';
21
18f68570
VK
22warn "Writing $opt{CONFIG_H}\n";
23
e1caacb4
JH
24my $patchlevel = $opt{INST_VER};
25$patchlevel =~ s|^[\\/]||;
26$patchlevel =~ s|~VERSION~|$Config{version}|g;
27$patchlevel ||= $Config{version};
28$patchlevel = qq["$patchlevel"];
29
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
37$file =~ s/^\$(\w+)$/$opt{$1}/g;
38
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:$!";
42d1cefd 55#binmode H; # no CRs (which cause a spurious rebuild)
e1caacb4
JH
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#/[ *\*]*\*/#/**/#;
64 if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
65 {
66 $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "($patchlevel))\t/**/\n";
67 }
68 # incpush() handles archlibs, so disable them
69 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
70 {
71 $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
72 }
73 print H;
74 }
75close(H);
76close(SH);
77
78
e2a02c1e
VK
79chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
80copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
81chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");
e1caacb4 82
acfe0abc 83if (compare("$file.new",$file))
e1caacb4
JH
84 {
85 warn "$file has changed\n";
86 chmod(0666,$file);
87 unlink($file);
88 rename("$file.new",$file);
89 #chmod(0444,$file);
90 exit(1);
91 }
92else
93 {
94 unlink ("$file.new");
95 exit(0);
96 }
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}