]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[util] config-local.h to avoid accidental commits
authorStefan Hajnoczi <stefanha@gmail.com>
Wed, 4 Jun 2008 19:56:20 +0000 (20:56 +0100)
committerMichael Brown <mcb30@etherboot.org>
Wed, 4 Jun 2008 23:45:33 +0000 (00:45 +0100)
During development it is often handy to change the config.h options from
their defaults, for example to enable debugging features.

To prevent accidental commits of debugging config.h changes, mdc
suggested having a config-local.h that is excluded from source control.
This file acts as a temporary config.h and can override any of the
defaults.

This commit is an attempt to implement the config-local.h feature.

The config.h file now has the following as its last line:
/* @TRYSOURCE config-local.h */

The @TRYSOURCE directive causes config-local.h to be included at that
point in the file.  If config-local.h does not exist, no error will be
printed and parsing will continue as normal.  Therefore, mkconfig.pl is
"trying" to "source" config-local.h.

src/.gitignore
src/Makefile.housekeeping
src/config.h
src/util/mkconfig.pl

index cc8e33e28ef57fc493a9f4b8002e87fed1e8b537..413f81410393a3067603a2b7d7dfc0ca71625b02 100644 (file)
@@ -2,3 +2,4 @@
 .echocheck
 TAGS*
 bin*
+config-local.h
index 216f29ec0c9a2643f5f4333be91b5ad3ff49b2b1..bbea2a56d5e4769ba0f3aa12273e6fc24c22d9b9 100644 (file)
@@ -121,8 +121,8 @@ CFLAGS      += $(SP_FLAGS)
 CFLAGS += -include compiler.h
 
 # config/%.h files are generated from config.h using mkconfig.pl
-config/%.h : config.h
-       $(MKCONFIG) $<
+config/%.h : config*.h
+       $(MKCONFIG) config.h
 CLEANUP        += config/*.h
 
 # SRCDIRS lists all directories containing source files.
index 2d8faa68a5d5bd6873be887c36939db1a7d10ecd..cec832c34d980b9463fbcfcf668c3cbe27c94a12 100644 (file)
 #undef NULL_TRAP               /* Attempt to catch NULL function calls */
 
 /* @END general.h */
+
+/* @TRYSOURCE config-local.h */
index 6a9c2f1442a82d7e196674e0360eb952cbbec23a..e55c2ca82350b899a296728ddebe384d400690e4 100755 (executable)
@@ -7,6 +7,7 @@ use warnings;
 
 my $cfgdir = "config";
 my $config_h = shift || "config.h";
+my @input_files;
 
 # Read in a whole file
 #
@@ -110,15 +111,15 @@ sub postamble {
   return "\n#endif /* $guard */\n";
 } 
 
-# Get the new configuration by splitting config.h file using the
-# @BEGIN/@END tags
+# Parse one config.h file into an existing configuration
 #
-sub new_config {
+sub parse_config {
   my $file = shift;
-
-  my $cfg = {};
+  my $cfg = shift;
   my $cursor = "";
 
+  push ( @input_files, $file );
+
   open my $fh, "<$file" or die "Could not open $file: $!\n";
   while ( <$fh> ) {
     if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
@@ -133,14 +134,28 @@ sub new_config {
          ." at $file line $.\n" unless $cursor eq $oldcursor;
       $cfg->{$cursor} .= $prefix."*/\n";
       $cursor = "";
+    } elsif ( ( my $newfile ) = /\@TRYSOURCE\s+([\w\-]+\.h)/ ) {
+      die "Missing \"\@END $cursor\" before \"\@TRYSOURCE $newfile\""
+         ." at $file line $.\n" if $cursor;
+      parse_config ( $newfile, $cfg ) if -e $newfile;
     } else {
       $cfg->{$cursor} .= $_ if $cursor;
     }
   }
   close $fh;
   die "Missing \"\@END $cursor\" in $file\n" if $cursor;
+}
 
-  foreach $cursor ( keys %$cfg ) {
+# Get the new configuration by splitting config.h file using the
+# @BEGIN/@END tags
+#
+sub new_config {
+  my $file = shift;
+  my $cfg = {};
+
+  parse_config ( $file, $cfg );
+
+  foreach my $cursor ( keys %$cfg ) {
     $cfg->{$cursor} .= postamble ( $cursor );
   }
 
@@ -180,9 +195,11 @@ foreach my $file ( keys %$new ) {
 }
 
 # If we now have 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.
+# timestamp on each input file to match the oldest fragment, to
+# prevent make from always attempting to rebuild the fragments.
 #
-if ( $oldest < file_mtime ( $config_h ) ) {
-  utime time(), $oldest, $config_h or die "Could not touch $config_h: $!\n";
+foreach my $file ( @input_files ) {
+  if ( $oldest < file_mtime ( $file ) ) {
+    utime time(), $oldest, $file or die "Could not touch $file: $!\n";
+  }
 }