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