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'; |
38121b9e | 26 | |
1018e26f NIS |
27 | warn "Writing $opt{CONFIG_H}\n"; |
28 | ||
1ae6ead9 | 29 | open(SH, "<", $name) || die "Cannot open $name:$!"; |
137443ea | 30 | while (<SH>) |
31 | { | |
a2b6a4d6 | 32 | last if /^\s*sed/; |
137443ea | 33 | } |
2d7ad1b1 | 34 | my($term,$file,$pat) = /^\s*sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/; |
137443ea | 35 | |
38121b9e GS |
36 | $file =~ s/^\$(\w+)$/$opt{$1}/g; |
37 | ||
137443ea | 38 | my $str = "sub munge\n{\n"; |
39 | ||
40 | while ($pat =~ s/-e\s+'([^']*)'\s*//) | |
41 | { | |
42 | my $e = $1; | |
43 | $e =~ s/\\([\(\)])/$1/g; | |
44 | $e =~ s/\\(\d)/\$$1/g; | |
45 | $str .= "$e;\n"; | |
46 | } | |
47 | $str .= "}\n"; | |
48 | ||
49 | eval $str; | |
50 | ||
51 | die "$str:$@" if $@; | |
52 | ||
1ae6ead9 | 53 | open(H, ">", "$file.new") || die "Cannot open $file.new:$!"; |
884a09e7 | 54 | binmode(H); |
137443ea | 55 | while (<SH>) |
56 | { | |
57 | last if /^$term$/o; | |
58 | s/\$([\w_]+)/Config($1)/eg; | |
59 | s/`([^\`]*)`/BackTick($1)/eg; | |
60 | munge(); | |
61 | s/\\\$/\$/g; | |
62 | s#/[ *\*]*\*/#/**/#; | |
f3b9bb7d | 63 | s#(.)/\*\*/#$1/ **/# if(/^\/\*/); #avoid "/*" inside comments |
4ea817c6 | 64 | if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/) |
acbc2db6 | 65 | { |
1c68cbf7 DD |
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"; | |
acbc2db6 | 72 | } |
e5a95ffb | 73 | # incpush() handles archlibs, so disable them |
4ea817c6 | 74 | elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/) |
acbc2db6 | 75 | { |
f3b9bb7d | 76 | $_ = "/*#define ". $1 . "_EXP \"\"\t/ **/\n"; |
137443ea | 77 | } |
7bef440c SH |
78 | elsif (/^\s*#define\s+CPP(STDIN|RUN)\s+"gcc(.*)"\s*$/) |
79 | { | |
80 | $_ = "#define CPP" . $1 . " \"" . $opt{ARCHPREFIX} . "gcc" . $2 . "\"\n"; | |
81 | } | |
137443ea | 82 | print H; |
83 | } | |
137443ea | 84 | close(H); |
85 | close(SH); | |
86 | ||
bf543eaf DD |
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); | |
989c251f | 93 | } |
137443ea | 94 | |
acfe0abc | 95 | if (compare("$file.new",$file)) |
137443ea | 96 | { |
97 | warn "$file has changed\n"; | |
98 | chmod(0666,$file); | |
99 | unlink($file); | |
bf543eaf | 100 | rename("$file.new",$file) || die "Cannot rename:$!"; |
137443ea | 101 | } |
01f988be GS |
102 | else |
103 | { | |
104 | unlink ("$file.new"); | |
01f988be | 105 | } |
137443ea | 106 | |
107 | sub Config | |
108 | { | |
109 | my $var = shift; | |
110 | my $val = $Config{$var}; | |
111 | $val = 'undef' unless defined $val; | |
112 | $val =~ s/\\/\\\\/g; | |
113 | return $val; | |
114 | } | |
115 | ||
116 | sub BackTick | |
117 | { | |
118 | my $cmd = shift; | |
119 | if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/) | |
120 | { | |
2d7ad1b1 | 121 | my($data,$pat) = ($1,$2); |
137443ea | 122 | $data =~ s/\s+/ /g; |
123 | eval "\$data =~ $pat"; | |
124 | return $data; | |
125 | } | |
126 | else | |
127 | { | |
128 | die "Cannot handle \`$cmd\`"; | |
129 | } | |
130 | return $cmd; | |
131 | } |