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'; | |
e2a02c1e | 21 | $opt{CORE_DIR} ||= '../lib/CORE'; |
e1caacb4 | 22 | |
18f68570 VK |
23 | warn "Writing $opt{CONFIG_H}\n"; |
24 | ||
e1caacb4 JH |
25 | my $patchlevel = $opt{INST_VER}; |
26 | $patchlevel =~ s|^[\\/]||; | |
27 | $patchlevel =~ s|~VERSION~|$Config{version}|g; | |
28 | $patchlevel ||= $Config{version}; | |
29 | $patchlevel = qq["$patchlevel"]; | |
30 | ||
31 | open(SH,"<$name") || die "Cannot open $name:$!"; | |
32 | while (<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 | ||
40 | my $str = "sub munge\n{\n"; | |
41 | ||
42 | while ($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 | ||
51 | eval $str; | |
52 | ||
53 | die "$str:$@" if $@; | |
54 | ||
55 | open(H,">$file.new") || die "Cannot open $file.new:$!"; | |
e2a02c1e | 56 | binmode H; # no CRs (which cause a spurious rebuild) |
e1caacb4 JH |
57 | while (<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 | } | |
76 | close(H); | |
77 | close(SH); | |
78 | ||
79 | ||
e2a02c1e VK |
80 | chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}"); |
81 | copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!"; | |
82 | chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}"); | |
e1caacb4 | 83 | |
acfe0abc | 84 | if (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 | } | |
93 | else | |
94 | { | |
95 | unlink ("$file.new"); | |
96 | exit(0); | |
97 | } | |
98 | ||
99 | sub 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 | ||
108 | sub 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 | } |