Browse Source

If we end up with fragments that are older than config.h, set the

timestamp on config.h to match the oldest fragment, to prevent make
from always attempting to rebuild the fragments.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
a107996c9a
1 changed files with 29 additions and 4 deletions
  1. 29
    4
      src/util/mkconfig.pl

+ 29
- 4
src/util/mkconfig.pl View File

1
 #!/usr/bin/perl -w
1
 #!/usr/bin/perl -w
2
 
2
 
3
 use File::Spec::Functions qw ( :ALL );
3
 use File::Spec::Functions qw ( :ALL );
4
+use File::stat;
4
 use strict;
5
 use strict;
5
 use warnings;
6
 use warnings;
6
 
7
 
7
 my $cfgdir = "config";
8
 my $cfgdir = "config";
8
-my $config_h = "config.h";
9
+my $config_h = shift || "config.h";
9
 
10
 
10
 # Read in a whole file
11
 # Read in a whole file
11
 #
12
 #
38
   unlink $file or die "Could not delete $file: $!\n";
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
 # Read a directory listing (excluding the . and .. entries)
51
 # Read a directory listing (excluding the . and .. entries)
42
 #
52
 #
43
 sub read_dir {
53
 sub read_dir {
155
   unlink catfile ( $cfgdir, $file ) unless exists $new->{$file};
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
 foreach my $file ( keys %$new ) {
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
 }

Loading…
Cancel
Save