summaryrefslogtreecommitdiff
path: root/cesar/common/tools/config-merge
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/common/tools/config-merge')
-rwxr-xr-xcesar/common/tools/config-merge54
1 files changed, 54 insertions, 0 deletions
diff --git a/cesar/common/tools/config-merge b/cesar/common/tools/config-merge
new file mode 100755
index 0000000000..ae6b63a78e
--- /dev/null
+++ b/cesar/common/tools/config-merge
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+#
+# Read a project configuration and modules configurations and merge them to
+# stdout.
+#
+use strict;
+use warnings;
+
+if (scalar @ARGV < 1)
+{
+ die <<EOF;
+$0 - merge project and modules configuration to stdout.
+Syntax: $0 project_config module_configs...
+EOF
+}
+
+my %conf;
+
+my $proj = shift @ARGV;
+push @ARGV, $proj;
+
+while (<>)
+{
+ chomp;
+ next if /^\s*#/;
+ next if /^$/;
+ if (/^\s*([A-Z_]+)\s*=\s*([yn]|[0-9]+)\s*$/)
+ {
+ my ($var, $val) = ($1, $2);
+ $var =~ /^CONFIG_[A-Z_]*[A-Z]$/
+ or die "$ARGV:$.:unaccepted identifier \"$var\"\n";
+ if (scalar @ARGV == 0)
+ {
+ # Project config.
+ exists $conf{$var}
+ or die "$ARGV:$.:unknown identifier \"$var\"\n";
+ $val =~ /^[yn]$/ ^ $conf{$var} =~ /^[yn]$/
+ and die "$ARGV:$.:bad type for \"$var\"\n";
+ }
+ else
+ {
+ # Module config.
+ !exists $conf{$var}
+ or die "$ARGV:$.:duplicated identifier \"$var\"\n";
+ }
+ $conf{$var} = $val;
+ next;
+ }
+ die "$ARGV:$.:unrecognized line\n";
+} continue {
+ close ARGV if eof;
+}
+
+print "$_ = $conf{$_}\n" for (sort keys %conf);