|
@@ -1,11 +1,12 @@
|
1
|
1
|
#!/usr/bin/perl -w
|
2
|
2
|
|
3
|
3
|
use File::Spec::Functions qw ( :ALL );
|
|
4
|
+use File::stat;
|
4
|
5
|
use strict;
|
5
|
6
|
use warnings;
|
6
|
7
|
|
7
|
8
|
my $cfgdir = "config";
|
8
|
|
-my $config_h = "config.h";
|
|
9
|
+my $config_h = shift || "config.h";
|
9
|
10
|
|
10
|
11
|
# Read in a whole file
|
11
|
12
|
#
|
|
@@ -38,6 +39,15 @@ sub delete_file {
|
38
|
39
|
unlink $file or die "Could not delete $file: $!\n";
|
39
|
40
|
}
|
40
|
41
|
|
|
42
|
+# Get a file modification time
|
|
43
|
+#
|
|
44
|
+sub file_mtime {
|
|
45
|
+ my $file = shift;
|
|
46
|
+
|
|
47
|
+ my $stat = stat ( $file ) or die "Could not stat $file: $!\n";
|
|
48
|
+ return $stat->mtime;
|
|
49
|
+}
|
|
50
|
+
|
41
|
51
|
# Read a directory listing (excluding the . and .. entries)
|
42
|
52
|
#
|
43
|
53
|
sub read_dir {
|
|
@@ -155,9 +165,24 @@ foreach my $file ( keys %$current ) {
|
155
|
165
|
unlink catfile ( $cfgdir, $file ) unless exists $new->{$file};
|
156
|
166
|
}
|
157
|
167
|
|
158
|
|
-# Write out any modified fragments
|
|
168
|
+# Write out any modified fragments, and find the oldest timestamp of
|
|
169
|
+# any unmodified fragments.
|
159
|
170
|
#
|
|
171
|
+my $oldest = time ();
|
160
|
172
|
foreach my $file ( keys %$new ) {
|
161
|
|
- write_file ( catfile ( $cfgdir, $file ), $new->{$file} )
|
162
|
|
- unless $current->{$file} && $new->{$file} eq $current->{$file};
|
|
173
|
+ if ( $current->{$file} && $new->{$file} eq $current->{$file} ) {
|
|
174
|
+ # Unmodified
|
|
175
|
+ my $time = file_mtime ( catfile ( $cfgdir, $file ) );
|
|
176
|
+ $oldest = $time if $time < $oldest;
|
|
177
|
+ } else {
|
|
178
|
+ write_file ( catfile ( $cfgdir, $file ), $new->{$file} );
|
|
179
|
+ }
|
|
180
|
+}
|
|
181
|
+
|
|
182
|
+# If we now have fragments that are older than config.h, set the
|
|
183
|
+# timestamp on config.h to match the oldest fragment, to prevent make
|
|
184
|
+# from always attempting to rebuild the fragments.
|
|
185
|
+#
|
|
186
|
+if ( $oldest < file_mtime ( $config_h ) ) {
|
|
187
|
+ utime time(), $oldest, $config_h or die "Could not touch $config_h: $!\n";
|
163
|
188
|
}
|