This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence Win32 compiler warnings following change 25280
[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';
e2a02c1e 21$opt{CORE_DIR} ||= '../lib/CORE';
e1caacb4 22
18f68570
VK
23warn "Writing $opt{CONFIG_H}\n";
24
e1caacb4
JH
25my $patchlevel = $opt{INST_VER};
26$patchlevel =~ s|^[\\/]||;
27$patchlevel =~ s|~VERSION~|$Config{version}|g;
28$patchlevel ||= $Config{version};
29$patchlevel = qq["$patchlevel"];
30
31open(SH,"<$name") || die "Cannot open $name:$!";
32while (<SH>)
33 {
34 last if /^sed/;
35 }
36($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
37
38$file =~ s/^\$(\w+)$/$opt{$1}/g;
39
40my $str = "sub munge\n{\n";
41
42while ($pat =~ s/-e\s+'([^']*)'\s*//)
43 {
44 my $e = $1;
45 $e =~ s/\\([\(\)])/$1/g;
46 $e =~ s/\\(\d)/\$$1/g;
47 $str .= "$e;\n";
48 }
49$str .= "}\n";
50
51eval $str;
52
53die "$str:$@" if $@;
54
55open(H,">$file.new") || die "Cannot open $file.new:$!";
e2a02c1e 56binmode H; # no CRs (which cause a spurious rebuild)
e1caacb4
JH
57while (<SH>)
58 {
59 last if /^$term$/o;
60 s/\$([\w_]+)/Config($1)/eg;
61 s/`([^\`]*)`/BackTick($1)/eg;
62 munge();
63 s/\\\$/\$/g;
64 s#/[ *\*]*\*/#/**/#;
65 if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
66 {
67 $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "($patchlevel))\t/**/\n";
68 }
69 # incpush() handles archlibs, so disable them
70 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
71 {
72 $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
73 }
74 print H;
75 }
76close(H);
77close(SH);
78
79
e2a02c1e
VK
80chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
81copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
82chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");
e1caacb4 83
acfe0abc 84if (compare("$file.new",$file))
e1caacb4
JH
85 {
86 warn "$file has changed\n";
87 chmod(0666,$file);
88 unlink($file);
89 rename("$file.new",$file);
90 #chmod(0444,$file);
91 exit(1);
92 }
93else
94 {
95 unlink ("$file.new");
96 exit(0);
97 }
98
99sub Config
100{
101 my $var = shift;
102 my $val = $Config{$var};
103 $val = 'undef' unless defined $val;
104 $val =~ s/\\/\\\\/g;
105 return $val;
106}
107
108sub BackTick
109{
110 my $cmd = shift;
111 if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
112 {
113 local ($data,$pat) = ($1,$2);
114 $data =~ s/\s+/ /g;
115 eval "\$data =~ $pat";
116 return $data;
117 }
118 else
119 {
120 die "Cannot handle \`$cmd\`";
121 }
122 return $cmd;
123}