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