Commit | Line | Data |
137443ea |
1 | # |
1018e26f |
2 | BEGIN { warn "Running ".__FILE__."\n" }; |
3 | BEGIN |
4 | { |
5 | require "../lib/Config.pm"; |
6 | die "../Config.pm:$@" if $@; |
7 | Config::->import; |
8 | } |
137443ea |
9 | use File::Compare qw(compare); |
10 | use File::Copy qw(copy); |
11 | my $name = $0; |
12 | $name =~ s#^(.*)\.PL$#../$1.SH#; |
e5a95ffb |
13 | my %opt; |
14 | while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/) |
15 | { |
16 | $opt{$1}=$2; |
17 | shift(@ARGV); |
18 | } |
38121b9e |
19 | |
20 | $opt{CONFIG_H} ||= 'config.h'; |
21 | |
1018e26f |
22 | warn "Writing $opt{CONFIG_H}\n"; |
23 | |
e5a95ffb |
24 | my $patchlevel = $opt{INST_VER}; |
66aa1127 |
25 | $patchlevel =~ s|^[\\/]||; |
273cf8d1 |
26 | $patchlevel =~ s|~VERSION~|$Config{version}|g; |
27 | $patchlevel ||= $Config{version}; |
e5a95ffb |
28 | $patchlevel = qq["$patchlevel"]; |
29 | |
137443ea |
30 | open(SH,"<$name") || die "Cannot open $name:$!"; |
31 | while (<SH>) |
32 | { |
33 | last if /^sed/; |
34 | } |
35 | ($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/; |
36 | |
38121b9e |
37 | $file =~ s/^\$(\w+)$/$opt{$1}/g; |
38 | |
137443ea |
39 | my $str = "sub munge\n{\n"; |
40 | |
41 | while ($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 | |
50 | eval $str; |
51 | |
52 | die "$str:$@" if $@; |
53 | |
54 | open(H,">$file.new") || die "Cannot open $file.new:$!"; |
8c8a4ace |
55 | #binmode H; # no CRs (which cause a spurious rebuild) |
137443ea |
56 | while (<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 |
75 | close(H); |
76 | close(SH); |
77 | |
78 | |
79 | chmod(0666,"../lib/CORE/config.h"); |
80 | copy("$file.new","../lib/CORE/config.h") || die "Cannot copy:$!"; |
81 | chmod(0444,"../lib/CORE/config.h"); |
82 | |
acfe0abc |
83 | if (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 |
92 | else |
93 | { |
94 | unlink ("$file.new"); |
95 | exit(0); |
96 | } |
137443ea |
97 | |
98 | sub 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 | |
107 | sub 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 | } |