This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #61392] Method call documentation in perlobj.pod
[perl5.git] / win32 / config_h.PL
CommitLineData
137443ea 1#
1018e26f
NIS
2BEGIN { warn "Running ".__FILE__."\n" };
3BEGIN
4 {
7bd379e8
YO
5 require "Config.pm";
6 die "Config.pm:$@" if $@;
1018e26f
NIS
7 Config::->import;
8 }
137443ea 9use File::Compare qw(compare);
10use File::Copy qw(copy);
11my $name = $0;
12$name =~ s#^(.*)\.PL$#../$1.SH#;
e5a95ffb
GS
13my %opt;
14while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
15 {
16 $opt{$1}=$2;
17 shift(@ARGV);
18 }
38121b9e
GS
19
20$opt{CONFIG_H} ||= 'config.h';
7bd379e8 21$opt{CORE_DIR} ||= '../lib/CORE';
38121b9e 22
1018e26f
NIS
23warn "Writing $opt{CONFIG_H}\n";
24
e5a95ffb 25my $patchlevel = $opt{INST_VER};
66aa1127 26$patchlevel =~ s|^[\\/]||;
273cf8d1
GS
27$patchlevel =~ s|~VERSION~|$Config{version}|g;
28$patchlevel ||= $Config{version};
e5a95ffb
GS
29$patchlevel = qq["$patchlevel"];
30
137443ea 31open(SH,"<$name") || die "Cannot open $name:$!";
32while (<SH>)
33 {
a2b6a4d6 34 last if /^\s*sed/;
137443ea 35 }
a2b6a4d6 36($term,$file,$pat) = /^\s*sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
137443ea 37
38121b9e
GS
38$file =~ s/^\$(\w+)$/$opt{$1}/g;
39
137443ea 40my $str = "sub munge\n{\n";
41
42while ($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
51eval $str;
52
53die "$str:$@" if $@;
54
55open(H,">$file.new") || die "Cannot open $file.new:$!";
8c8a4ace 56#binmode H; # no CRs (which cause a spurious rebuild)
137443ea 57while (<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#/[ *\*]*\*/#/**/#;
4ea817c6 65 if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
acbc2db6 66 {
c5be433b 67 $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "($patchlevel))\t/**/\n";
acbc2db6 68 }
e5a95ffb 69 # incpush() handles archlibs, so disable them
4ea817c6 70 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
acbc2db6 71 {
e5a95ffb 72 $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
137443ea 73 }
74 print H;
75 }
137443ea 76close(H);
77close(SH);
78
79
7bd379e8
YO
80chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
81copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
82chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");
137443ea 83
acfe0abc 84if (compare("$file.new",$file))
137443ea 85 {
86 warn "$file has changed\n";
87 chmod(0666,$file);
88 unlink($file);
89 rename("$file.new",$file);
924b3ec4 90 #chmod(0444,$file);
137443ea 91 exit(1);
92 }
01f988be
GS
93else
94 {
95 unlink ("$file.new");
96 exit(0);
97 }
137443ea 98
99sub 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
108sub 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}