5 # For the `mv' function which is smart enough to cross device boundries.
7 # For the `basename' function.
17 my ($same, $file_name, $temp_name) = @_;
22 or warn "Failed to unlink ", $temp_name, ": $!";
23 print "no change: ", $file_name, "\n";
27 mv $temp_name, $file_name
28 or die "Failed to rename ", $temp_name, " to ", $file_name, ": $!";
30 print "save edit: ", $file_name, "\n";
36 my ($value, $default) = @_;
50 my ($file, $new_no, $old_no, $line) = @_;
52 print $file, " line ", $new_no, " duplicates line ", $old_no, ": ", $line;
59 my ($case, $that, $this, $this_key, %this_macros) = @_;
60 my $type = $this_macros{$this_key}[1];
64 # roots file has extra macro statement
66 return if $type eq "d";
70 # build file has extra macro statement
71 # tell only of #define
72 return if $type eq "u";
76 die "Internal script error";
89 die "Internal script error";
92 print $this, " line ", $this_macros{$this_key}[0], " has ", $type, " ",
93 $this_key, " not found in ", $that, "\n";
107 my ($ph_name, $out_name, $inp_name, $end_name) = @_;
109 $ph_name = get_default $ph_name, "../config.h.in";
110 $out_name = get_default $out_name, "config.h.in";
111 $inp_name = get_default $inp_name, $out_name . ".in";
112 $end_name = get_default $end_name, $out_name . ".footer";
114 print STDERR "($inp_name + $ph_name) . $end_name --> $out_name\n"
117 #==========================================================================
118 # scan build level configuration to collect define/undef values
119 #==========================================================================
121 open FINP, "< $inp_name"
122 or die "error opening ", $inp_name, " for read: $!";
126 if (/^#\s*define\s*(\w+)(\s+(.+))?$/)
128 if (exists $build_macros{$1})
130 show_repeat $inp_name, $., $build_macros{$1}[0], $_;
134 $build_macros{$1} = [$., "d", $3];
137 elsif (/^\s*#\s*undef\s+(\w+)/)
139 if (exists $build_macros{$1})
141 show_repeat $inp_name, $., $build_macros{$1}[0], $_;
145 $build_macros{$1} = [$., "u"];
150 #==========================================================================
152 #==========================================================================
153 # temporary output file
154 #==========================================================================
155 my $temp_name = basename($out_name) . ".tmp";
157 open FOUT, "> $temp_name"
158 or die "error opening ", $temp_name, " for write: $!";
160 #==========================================================================
161 # copy build level configuration append file to output file
162 #==========================================================================
163 my $base_out = basename $out_name;
164 my $base_prog = basename $0;
165 my $base_inp = basename $inp_name;
166 my $base_ph = basename $ph_name;
167 my $base_end = basename $end_name;
171 *** $base_out, generated by $base_prog:
178 *** ***** DO NOT ALTER THIS FILE!!! *****
180 *** Changes to this file will be overwritten by automatic script runs.
181 *** Changes should be made to the $base_inp & $base_end
187 #==========================================================================
188 # copy root level configuration to output file
189 # while keeping track of conditional compile nesting level
190 #==========================================================================
191 open FINP, "< $ph_name"
192 or die "error opening ", $ph_name, " for read: $!";
199 if (/^\s*#\s*undef\s+(\w+)/)
201 if (exists $ph_macros{$1})
203 show_repeat $ph_name, $., $ph_macros{$1}[0], $_;
207 $ph_macros{$1} = [$., "u"];
210 if (exists $build_macros{$1}
211 and $build_macros{$1}[1] eq "d")
213 $out_line = "#define $1";
215 $out_line .= " " . $build_macros{$1}[2]
216 if defined $build_macros{$1}[2];
221 print FOUT $out_line;
224 #==========================================================================
226 #==========================================================================
227 # copy build level configuration append file to output file
228 #==========================================================================
229 if (open FINP, "< $end_name")
237 #==========================================================================
239 #==========================================================================
241 #==========================================================================
242 # determine whether output (if any) has changed from last run
243 #==========================================================================
246 if (open FINP, "< $out_name")
248 open FOUT, "< $temp_name"
249 or die "error opening ", $temp_name, " for read: $!";
254 last if eof FINP and eof FOUT;
255 if (eof FINP or eof FOUT or <FINP> ne <FOUT>)
265 #==========================================================================
267 #==========================================================================
268 my @keys_build = sort keys %build_macros;
269 my @keys_roots = sort keys %ph_macros;
270 my ($idx_build, $idx_roots) = (0, 0);
271 while ($idx_build < @keys_build or $idx_roots < @keys_roots) {
272 if ($idx_build >= @keys_build)
274 show_orphan 0, $inp_name, $ph_name, $keys_roots[$idx_roots],
278 elsif ($idx_roots >= @keys_roots)
280 show_orphan 1, $ph_name, $inp_name, $keys_build[$idx_build],
284 elsif ($keys_build[$idx_build] gt $keys_roots[$idx_roots])
286 show_orphan 0, $inp_name, $ph_name, $keys_roots[$idx_roots],
290 elsif ($keys_roots[$idx_roots] gt $keys_build[$idx_build])
292 show_orphan 1, $ph_name, $inp_name, $keys_build[$idx_build],
303 #==========================================================================
304 # save output only if changed
305 #==========================================================================
306 save_edit $same, $out_name, $temp_name;