Commit | Line | Data |
---|---|---|
2d7ad1b1 SH |
1 | #!perl -w |
2 | use strict; | |
3 | ||
1018e26f NIS |
4 | BEGIN { warn "Running ".__FILE__."\n" }; |
5 | BEGIN | |
6 | { | |
7bd379e8 YO |
7 | require "Config.pm"; |
8 | die "Config.pm:$@" if $@; | |
2d7ad1b1 | 9 | Config->import; |
1018e26f | 10 | } |
137443ea | 11 | use File::Compare qw(compare); |
12 | use File::Copy qw(copy); | |
f3b9bb7d | 13 | use File::Basename qw(fileparse); |
2d7ad1b1 | 14 | |
f3b9bb7d | 15 | my ($name, $dir) = fileparse($0); |
137443ea | 16 | $name =~ s#^(.*)\.PL$#../$1.SH#; |
e5a95ffb GS |
17 | my %opt; |
18 | while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/) | |
19 | { | |
20 | $opt{$1}=$2; | |
21 | shift(@ARGV); | |
22 | } | |
38121b9e GS |
23 | |
24 | $opt{CONFIG_H} ||= 'config.h'; | |
7bd379e8 | 25 | $opt{CORE_DIR} ||= '../lib/CORE'; |
3c21fb41 | 26 | $opt{CORE_CONFIG_H} ||= $opt{CORE_DIR} . '/config.h'; |
38121b9e | 27 | |
1018e26f NIS |
28 | warn "Writing $opt{CONFIG_H}\n"; |
29 | ||
1ae6ead9 | 30 | open(SH, "<", $name) || die "Cannot open $name:$!"; |
137443ea | 31 | while (<SH>) |
32 | { | |
a2b6a4d6 | 33 | last if /^\s*sed/; |
137443ea | 34 | } |
2d7ad1b1 | 35 | my($term,$file,$pat) = /^\s*sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/; |
137443ea | 36 | |
38121b9e GS |
37 | $file =~ s/^\$(\w+)$/$opt{$1}/g; |
38 | ||
137443ea | 39 | my $str = "sub munge\n{\n"; |
40 | ||
41 | while ($pat =~ s/-e\s+'([^']*)'\s*//) | |
42 | { | |
43 | my $e = $1; | |
44 | $e =~ s/\\([\(\)])/$1/g; | |
45 | $e =~ s/\\(\d)/\$$1/g; | |
46 | $str .= "$e;\n"; | |
47 | } | |
48 | $str .= "}\n"; | |
49 | ||
50 | eval $str; | |
51 | ||
52 | die "$str:$@" if $@; | |
53 | ||
1ae6ead9 | 54 | open(H, ">", "$file.new") || die "Cannot open $file.new:$!"; |
884a09e7 | 55 | binmode(H); |
137443ea | 56 | while (<SH>) |
57 | { | |
58 | last if /^$term$/o; | |
59 | s/\$([\w_]+)/Config($1)/eg; | |
60 | s/`([^\`]*)`/BackTick($1)/eg; | |
61 | munge(); | |
62 | s/\\\$/\$/g; | |
63 | s#/[ *\*]*\*/#/**/#; | |
f3b9bb7d | 64 | s#(.)/\*\*/#$1/ **/# if(/^\/\*/); #avoid "/*" inside comments |
4ea817c6 | 65 | if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/) |
acbc2db6 | 66 | { |
1c68cbf7 DD |
67 | $_ = '#define '. $1 . '_EXP ('.( |
68 | $1 eq 'PRIVLIB' ? 'PerlEnv_lib_path' : | |
69 | $1 eq 'SITELIB' ? 'PerlEnv_sitelib_path' : | |
70 | $1 eq 'VENDORLIB' ? 'PerlEnv_vendorlib_path' : | |
71 | die "unknown *LIB_EXP define \"$1\"" | |
72 | ). "(PERL_VERSION_STRING, NULL))\t/**/\n"; | |
acbc2db6 | 73 | } |
e5a95ffb | 74 | # incpush() handles archlibs, so disable them |
4ea817c6 | 75 | elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/) |
acbc2db6 | 76 | { |
f3b9bb7d | 77 | $_ = "/*#define ". $1 . "_EXP \"\"\t/ **/\n"; |
137443ea | 78 | } |
7bef440c SH |
79 | elsif (/^\s*#define\s+CPP(STDIN|RUN)\s+"gcc(.*)"\s*$/) |
80 | { | |
81 | $_ = "#define CPP" . $1 . " \"" . $opt{ARCHPREFIX} . "gcc" . $2 . "\"\n"; | |
82 | } | |
137443ea | 83 | print H; |
84 | } | |
137443ea | 85 | close(H); |
86 | close(SH); | |
87 | ||
3c21fb41 | 88 | my $core_config_h = $opt{CORE_CONFIG_H}; |
bf543eaf DD |
89 | if (compare("$file.new", $core_config_h)) { |
90 | mkdir $opt{CORE_DIR} unless -d $opt{CORE_DIR}; | |
91 | chmod(0666,$core_config_h); | |
3c21fb41 | 92 | copy("$file.new",$core_config_h) || die "Cannot copy $file.new $core_config_h:$!"; |
bf543eaf | 93 | chmod(0444,$core_config_h); |
989c251f | 94 | } |
137443ea | 95 | |
acfe0abc | 96 | if (compare("$file.new",$file)) |
137443ea | 97 | { |
98 | warn "$file has changed\n"; | |
99 | chmod(0666,$file); | |
100 | unlink($file); | |
bf543eaf | 101 | rename("$file.new",$file) || die "Cannot rename:$!"; |
137443ea | 102 | } |
01f988be GS |
103 | else |
104 | { | |
105 | unlink ("$file.new"); | |
01f988be | 106 | } |
137443ea | 107 | |
108 | sub Config | |
109 | { | |
110 | my $var = shift; | |
111 | my $val = $Config{$var}; | |
112 | $val = 'undef' unless defined $val; | |
113 | $val =~ s/\\/\\\\/g; | |
114 | return $val; | |
115 | } | |
116 | ||
117 | sub BackTick | |
118 | { | |
119 | my $cmd = shift; | |
120 | if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/) | |
121 | { | |
2d7ad1b1 | 122 | my($data,$pat) = ($1,$2); |
137443ea | 123 | $data =~ s/\s+/ /g; |
124 | eval "\$data =~ $pat"; | |
125 | return $data; | |
126 | } | |
127 | else | |
128 | { | |
129 | die "Cannot handle \`$cmd\`"; | |
130 | } | |
131 | return $cmd; | |
132 | } |