summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/common/make/config.mk11
-rwxr-xr-xcesar/common/tools/config-merge115
2 files changed, 81 insertions, 45 deletions
diff --git a/cesar/common/make/config.mk b/cesar/common/make/config.mk
index c5dbc829ff..8dead57edf 100644
--- a/cesar/common/make/config.mk
+++ b/cesar/common/make/config.mk
@@ -3,6 +3,7 @@
USER_PROJECT_CONFIG ?= $(wildcard $(if $(VARIANT),$(VARIANT)-)Config)
DEFAULT_PROJECT_CONFIG := $(OBJ_DIR)/Config.empty
PROJECT_CONFIG := $(if $(USER_PROJECT_CONFIG),$(USER_PROJECT_CONFIG),$(DEFAULT_PROJECT_CONFIG))
+CONFIG_SETS ?= $(BASE)/common/config-sets
.PHONY: CONFIG_FORCE CONFIG_CHECK BUILD_INFO_FORCE
@@ -21,8 +22,9 @@ $2_MODULE_LIST_FILE := $$(OBJ_DIR)/Module.$1.list
# Configuration is automatically updated if the list of config file has
# changed since last update.
+$2_CONFIG_LIST_CUR = $$(PROJECT_CONFIG) $$($2_MODULES_CONFIG) $$(wildcard $$(CONFIG_SETS)/*)
-include $$($2_CONFIG_LIST_FILE)
-$2_CONFIG_FORCE := $$(if $$(call list-neq,$$($2_CONFIG_LIST),$$(PROJECT_CONFIG) $$($2_MODULES_CONFIG)),CONFIG_FORCE)
+$2_CONFIG_FORCE := $$(if $$(call list-neq,$$($2_CONFIG_LIST),$$($2_CONFIG_LIST_CUR)),CONFIG_FORCE)
$2_CONFIG_CHECK := $$(if $$($2_CONFIG_FORCE)$$($2_CONFIG_CHECKED),,CONFIG_CHECK)
$2_CONFIG_MERGE_OPTION := $$(if $$($2_CONFIG_CHECK),,--ignore-unknown-identifier)
@@ -40,11 +42,12 @@ MODULE_LIST_FILES := $(call gather_type,MODULE_LIST_FILE)
# Define config rules.
# Call with: type, typevar
define CONFIG_RULES_template
-$$($2_MERGED_CONFIG): $$(PROJECT_CONFIG) $$($2_MODULES_CONFIG) $$(OBJ_DIR_STAMP) $$($2_CONFIG_FORCE) $$($2_CONFIG_CHECK)
+$$($2_MERGED_CONFIG): $$($2_CONFIG_LIST_CUR) $$(OBJ_DIR_STAMP) $$($2_CONFIG_FORCE) $$($2_CONFIG_CHECK)
@echo "CONF [$1] merge"
$$Qsleep 1 # needed to make make see the file update.
- $$Q$$(TOOLS_DIR)/config-merge $$($2_CONFIG_MERGE_OPTION) $1 $2 $$(PROJECT_CONFIG) $$($2_MODULES_CONFIG) > $$@
- $$Qecho "$2_CONFIG_LIST = $$(PROJECT_CONFIG) $$($2_MODULES_CONFIG)" > $$($2_CONFIG_LIST_FILE)
+ $$Q$$(TOOLS_DIR)/config-merge -d $$(CONFIG_SETS) $$($2_CONFIG_MERGE_OPTION) $1 $2 \
+ $$(PROJECT_CONFIG) $$($2_MODULES_CONFIG) > $$@
+ $$Qecho "$2_CONFIG_LIST = $$($2_CONFIG_LIST_CUR)" > $$($2_CONFIG_LIST_FILE)
$$Qecho "$2_CONFIG_CHECKED = $$($2_CONFIG_CHECK)" >> $$($2_CONFIG_LIST_FILE)
$$($2_HEADERS_CONFIG_STAMP): $$($2_MERGED_CONFIG)
diff --git a/cesar/common/tools/config-merge b/cesar/common/tools/config-merge
index fff4702fd6..69a1f442e2 100755
--- a/cesar/common/tools/config-merge
+++ b/cesar/common/tools/config-merge
@@ -16,13 +16,20 @@ Syntax: $0 [options] build_type build_type_var project_config module_configs...
Options:
-u, --ignore-unknown-identifier do not stop on unknown identifier
+ -w, --warn-unknown-in-set warn if an unknown identifier is seen in
+ config set
+ -d, --set-dir=DIRECTORY directory containing the config sets
EOF
}
my $help;
my $ignore_unknown_identifier = 0;
+my $warn_unknown_in_set = 0;
+my $set_dir;
GetOptions (
'help|h' => \$help,
'ignore-unknown-identifier|u' => \$ignore_unknown_identifier,
+ 'warn-unknown-in-set|w' => \$warn_unknown_in_set,
+ 'set-dir|d=s' => \$set_dir,
) or help ();
help () if $help;
help () if @ARGV < 3;
@@ -44,61 +51,87 @@ my %conf_set;
my $build_type = shift;
my $build_type_var = shift;
-# Put project config at end of list.
-my $proj = shift;
-push @ARGV, $proj;
-
-# First read modules configs and populate %conf. Then read project config.
-while (<>)
+sub read_config
{
- chomp;
- next if /^\s*#/;
- next if /^$/;
- if (/^\s* ([A-Z0-9_]+) # Item identifier.
- \s* (?:\[([a-z0-9-]+)\])? # Optional build type selector.
- \s* =
- \s* ([yn]|[0-9]+|"[^"]*") # Value.
- \s*$/x)
+ my ($filename, $type) = @_;
+ open my $FILE, "<$filename" or die;
+ while (<$FILE>)
{
- my ($var, $selector, $val) = ($1, $2, $3);
- $var =~ /^CONFIG_[A-Z0-9_]*[A-Z0-9]$/
- or die "$ARGV:$.:unaccepted identifier \"$var\"\n";
- if (scalar @ARGV == 0)
+ chomp;
+ next if /^\s*#/;
+ next if /^$/;
+ if (/^\s* ([A-Z0-9_]+) # Item identifier.
+ \s* (?:\[([a-z0-9-]+)\])? # Optional build type selector.
+ \s* =
+ \s* ([yn]|[0-9]+|"[^"]*") # Value.
+ \s*$/x)
{
- # Project config.
- defined $selector && $selector ne $build_type
- and next;
- if (exists $conf{$var})
+ my ($var, $selector, $val) = ($1, $2, $3);
+ $var =~ /^CONFIG_[A-Z0-9_]*[A-Z0-9]$/
+ or die "$filename:$.:unaccepted identifier \"$var\"\n";
+ if ($type eq 'module')
+ {
+ # Module config.
+ defined $selector
+ and die "$filename:$.:selector in module config\n";
+ !exists $conf{$var}
+ or die "$filename:$.:duplicated identifier \"$var\"\n";
+ }
+ elsif ($type eq 'set')
{
- type ($val) eq type ($conf{$var})
- or die "$ARGV:$.:bad type for \"$var\"\n";
- my $overriden = defined $selector;
- !exists $conf_set{$var} || $conf_set{$var} < $overriden
- or die "$ARGV:$.:\"$var\" already set\n";
- $conf_set{$var} = $overriden;
+ # Default config set, ignore non existent config.
+ defined $selector
+ and die "$filename:$.:selector in config set\n";
+ if (!exists $conf{$var})
+ {
+ $warn_unknown_in_set
+ and warn "$filename:$.:ignored identifier \"$var\"\n";
+ next;
+ }
}
else
{
- $ignore_unknown_identifier
- or die "$ARGV:$.:unknown identifier \"$var\"\n";
+ # Project config.
+ defined $selector && $selector ne $build_type
+ and next;
+ if (exists $conf{$var})
+ {
+ type ($val) eq type ($conf{$var})
+ or die "$filename:$.:bad type for \"$var\"\n";
+ my $overriden = defined $selector;
+ !exists $conf_set{$var} || $conf_set{$var} < $overriden
+ or die "$filename:$.:\"$var\" already set\n";
+ $conf_set{$var} = $overriden;
+ }
+ else
+ {
+ $ignore_unknown_identifier
+ or die "$filename:$.:unknown identifier \"$var\"\n";
+ }
}
+ $conf{$var} = $val;
+ next;
}
- else
+ elsif (m'^\s* set \s* ([a-z][-a-z0-9_/]*) \s*$'x)
{
- # Module config.
- defined $selector
- and die "$ARGV:$.:selector in module config\n";
- !exists $conf{$var}
- or die "$ARGV:$.:duplicated identifier \"$var\"\n";
+ $type eq 'module'
+ and die "$filename:$.:config set called in module config\n";
+ my $set = $1;
+ defined $set_dir
+ or die "use --set-dir to point to config sets\n";
+ read_config ("$set_dir/$set", 'set');
+ next;
}
- $conf{$var} = $val;
- next;
+ die "$filename:$.:unrecognized line\n";
}
- die "$ARGV:$.:unrecognized line\n";
-} continue {
- close ARGV if eof;
+ close $FILE;
}
+# First read modules configs and populate %conf. Then read project config.
+my $proj = shift;
+read_config ($_, 'module') for (@ARGV);
+read_config ($proj, 'project');
+
# Output merged config.
print "${build_type_var}_$_ = $conf{$_}\n" for (sort keys %conf);