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 ('.(
67 $1 eq 'PRIVLIB' ? 'PerlEnv_lib_path' :
68 $1 eq 'SITELIB' ? 'PerlEnv_sitelib_path' :
69 $1 eq 'VENDORLIB' ? 'PerlEnv_vendorlib_path' :
70 die "unknown *LIB_EXP define \"$1\""
71 ). "(PERL_VERSION_STRING, NULL))\t/**/\n";
73 # incpush() handles archlibs, so disable them
74 elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
76 $_ = "/*#define ". $1 . "_EXP \"\"\t/ **/\n";
78 elsif (/^\s*#define\s+CPP(STDIN|RUN)\s+"gcc(.*)"\s*$/)
80 $_ = "#define CPP" . $1 . " \"" . $opt{ARCHPREFIX} . "gcc" . $2 . "\"\n";
87 my $core_config_h = "$opt{CORE_DIR}/$opt{CONFIG_H}";
88 if (compare("$file.new", $core_config_h)) {
89 mkdir $opt{CORE_DIR} unless -d $opt{CORE_DIR};
90 chmod(0666,$core_config_h);
91 copy("$file.new",$core_config_h) || die "Cannot copy:$!";
92 chmod(0444,$core_config_h);
95 if (compare("$file.new",$file))
97 warn "$file has changed\n";
100 rename("$file.new",$file) || die "Cannot rename:$!";
104 unlink ("$file.new");
110 my $val = $Config{$var};
111 $val = 'undef' unless defined $val;
119 if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
121 my($data,$pat) = ($1,$2);
123 eval "\$data =~ $pat";
128 die "Cannot handle \`$cmd\`";