mirror of https://github.com/ipxe/ipxe.git
[util] config-local.h to avoid accidental commits
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.pull/1/head
parent
842165ef76
commit
f866b17998
|
@ -2,3 +2,4 @@
|
||||||
.echocheck
|
.echocheck
|
||||||
TAGS*
|
TAGS*
|
||||||
bin*
|
bin*
|
||||||
|
config-local.h
|
||||||
|
|
|
@ -121,8 +121,8 @@ CFLAGS += $(SP_FLAGS)
|
||||||
CFLAGS += -include compiler.h
|
CFLAGS += -include compiler.h
|
||||||
|
|
||||||
# config/%.h files are generated from config.h using mkconfig.pl
|
# config/%.h files are generated from config.h using mkconfig.pl
|
||||||
config/%.h : config.h
|
config/%.h : config*.h
|
||||||
$(MKCONFIG) $<
|
$(MKCONFIG) config.h
|
||||||
CLEANUP += config/*.h
|
CLEANUP += config/*.h
|
||||||
|
|
||||||
# SRCDIRS lists all directories containing source files.
|
# SRCDIRS lists all directories containing source files.
|
||||||
|
|
|
@ -166,3 +166,5 @@
|
||||||
#undef NULL_TRAP /* Attempt to catch NULL function calls */
|
#undef NULL_TRAP /* Attempt to catch NULL function calls */
|
||||||
|
|
||||||
/* @END general.h */
|
/* @END general.h */
|
||||||
|
|
||||||
|
/* @TRYSOURCE config-local.h */
|
||||||
|
|
|
@ -7,6 +7,7 @@ use warnings;
|
||||||
|
|
||||||
my $cfgdir = "config";
|
my $cfgdir = "config";
|
||||||
my $config_h = shift || "config.h";
|
my $config_h = shift || "config.h";
|
||||||
|
my @input_files;
|
||||||
|
|
||||||
# Read in a whole file
|
# Read in a whole file
|
||||||
#
|
#
|
||||||
|
@ -110,15 +111,15 @@ sub postamble {
|
||||||
return "\n#endif /* $guard */\n";
|
return "\n#endif /* $guard */\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the new configuration by splitting config.h file using the
|
# Parse one config.h file into an existing configuration
|
||||||
# @BEGIN/@END tags
|
|
||||||
#
|
#
|
||||||
sub new_config {
|
sub parse_config {
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
|
my $cfg = shift;
|
||||||
my $cfg = {};
|
|
||||||
my $cursor = "";
|
my $cursor = "";
|
||||||
|
|
||||||
|
push ( @input_files, $file );
|
||||||
|
|
||||||
open my $fh, "<$file" or die "Could not open $file: $!\n";
|
open my $fh, "<$file" or die "Could not open $file: $!\n";
|
||||||
while ( <$fh> ) {
|
while ( <$fh> ) {
|
||||||
if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
|
if ( ( my $newcursor, my $suffix ) = /\@BEGIN\s+(\w+\.h)(.*)$/ ) {
|
||||||
|
@ -133,14 +134,28 @@ sub new_config {
|
||||||
." at $file line $.\n" unless $cursor eq $oldcursor;
|
." at $file line $.\n" unless $cursor eq $oldcursor;
|
||||||
$cfg->{$cursor} .= $prefix."*/\n";
|
$cfg->{$cursor} .= $prefix."*/\n";
|
||||||
$cursor = "";
|
$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 {
|
} else {
|
||||||
$cfg->{$cursor} .= $_ if $cursor;
|
$cfg->{$cursor} .= $_ if $cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close $fh;
|
close $fh;
|
||||||
die "Missing \"\@END $cursor\" in $file\n" if $cursor;
|
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 );
|
$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
|
# 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
|
# timestamp on each input file to match the oldest fragment, to
|
||||||
# from always attempting to rebuild the fragments.
|
# prevent make from always attempting to rebuild the fragments.
|
||||||
#
|
#
|
||||||
if ( $oldest < file_mtime ( $config_h ) ) {
|
foreach my $file ( @input_files ) {
|
||||||
utime time(), $oldest, $config_h or die "Could not touch $config_h: $!\n";
|
if ( $oldest < file_mtime ( $file ) ) {
|
||||||
|
utime time(), $oldest, $file or die "Could not touch $file: $!\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue