Commit | Line | Data |
---|---|---|
e1caacb4 | 1 | # |
18f68570 VK |
2 | BEGIN { warn "Running ".__FILE__."\n" }; |
3 | BEGIN | |
4 | { | |
3f2394f2 VK |
5 | require "Config.pm"; |
6 | die "Config.pm:$@" if $@; | |
18f68570 VK |
7 | Config::->import; |
8 | } | |
e1caacb4 JH |
9 | use File::Compare qw(compare); |
10 | use File::Copy qw(copy); | |
e1caacb4 JH |
11 | my $name = $0; |
12 | $name =~ s#^(.*)\.PL$#../$1.SH#; | |
13 | my %opt; | |
14 | while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/) | |
15 | { | |
16 | $opt{$1}=$2; | |
17 | shift(@ARGV); | |
18 | } | |
19 | ||
20 | $opt{CONFIG_H} ||= 'config.h'; | |
21 | ||
18f68570 VK |
22 | warn "Writing $opt{CONFIG_H}\n"; |
23 | ||
e1caacb4 JH |
24 | my $patchlevel = $opt{INST_VER}; |
25 | $patchlevel =~ s|^[\\/]||; | |
26 | $patchlevel =~ s|~VERSION~|$Config{version}|g; | |
27 | $patchlevel ||= $Config{version}; | |
28 | $patchlevel = qq["$patchlevel"]; | |
29 | ||
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 | ||
37 | $file =~ s/^\$(\w+)$/$opt{$1}/g; | |
38 | ||
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:$!"; | |
42d1cefd | 55 | #binmode H; # no CRs (which cause a spurious rebuild) |
e1caacb4 JH |
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#/[ *\*]*\*/#/**/#; | |
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 | } | |
75 | close(H); | |
76 | close(SH); | |
77 | ||
78 | ||
e2a02c1e VK |
79 | chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}"); |
80 | copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!"; | |
81 | chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}"); | |
e1caacb4 | 82 | |
acfe0abc | 83 | if (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 | } | |
92 | else | |
93 | { | |
94 | unlink ("$file.new"); | |
95 | exit(0); | |
96 | } | |
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 | } |