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