4 BEGIN { warn "Running ".__FILE__."\n" };
8 die "Config.pm:$@" if $@;
11 use File::Compare qw(compare);
12 use File::Copy qw(copy);
13 use File::Basename qw(fileparse);
15 my ($name, $dir) = fileparse($0);
16 $name =~ s#^(.*)\.PL$#../$1.SH#;
18 while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
24 $opt{CONFIG_H} ||= 'config.h';
25 $opt{CORE_DIR} ||= '../lib/CORE';
27 warn "Writing $opt{CONFIG_H}\n";
29 open(SH,"<$name") || die "Cannot open $name:$!";
34 my($term,$file,$pat) = /^\s*sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
36 $file =~ s/^\$(\w+)$/$opt{$1}/g;
38 my $str = "sub munge\n{\n";
40 while ($pat =~ s/-e\s+'([^']*)'\s*//)
43 $e =~ s/\\([\(\)])/$1/g;
44 $e =~ s/\\(\d)/\$$1/g;
53 open(H,">$file.new") || die "Cannot open $file.new:$!";
58 s/\$([\w_]+)/Config($1)/eg;
59 s/`([^\`]*)`/BackTick($1)/eg;
63 s#(.)/\*\*/#$1/ **/# if(/^\/\*/); #avoid "/*" inside comments
64 if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
66 $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "(PERL_VERSION_STRING, NULL))\t/**/\n";
68 # incpush() handles archlibs, so disable them
69 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
71 $_ = "/*#define ". $1 . "_EXP \"\"\t/ **/\n";
73 elsif (/^\s*#define\s+CPP(STDIN|RUN)\s+"gcc(.*)"\s*$/)
75 $_ = "#define CPP" . $1 . " \"" . $opt{ARCHPREFIX} . "gcc" . $2 . "\"\n";
83 chmod(0666,"$opt{CORE_DIR}/$opt{CONFIG_H}");
84 copy("$file.new","$opt{CORE_DIR}/$opt{CONFIG_H}") || die "Cannot copy:$!";
85 chmod(0444,"$opt{CORE_DIR}/$opt{CONFIG_H}");
87 if (compare("$file.new",$file))
89 warn "$file has changed\n";
92 rename("$file.new",$file);
104 my $val = $Config{$var};
105 $val = 'undef' unless defined $val;
113 if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
115 my($data,$pat) = ($1,$2);
117 eval "\$data =~ $pat";
122 die "Cannot handle \`$cmd\`";