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