]>
Commit | Line | Data |
---|---|---|
0d34a427 LO |
1 | #!/usr/bin/perl -w |
2 | ||
3 | %allconfigs = (); | |
4 | %common = (); | |
5 | ||
6 | print "Reading config's ...\n"; | |
7 | ||
8 | for $config (@ARGV) { | |
9 | # Only config.* | |
10 | next if $config !~ /^config\..*/; | |
11 | # Nothing that is disabled, or remnant | |
12 | next if $config =~ /.*\.(default|disabled|stub)$/; | |
13 | ||
14 | %{$allconfigs{$config}} = (); | |
15 | ||
16 | print " processing $config ... "; | |
17 | ||
18 | open(CONFIG, "< $config"); | |
19 | ||
20 | while (<CONFIG>) { | |
21 | # Skip comments | |
22 | /^#*\s*CONFIG_(\w+)[\s=](.*)$/ or next; | |
23 | ||
24 | ${$allconfigs{$config}}{$1} = $2; | |
25 | ||
26 | $common{$1} = $2; | |
27 | } | |
28 | ||
29 | close(CONFIG); | |
30 | ||
31 | print "done.\n"; | |
32 | } | |
33 | ||
34 | print "\n"; | |
35 | ||
36 | print "Merging lists ... \n"; | |
37 | ||
38 | # %options - pointer to flavour config inside the allconfigs array | |
39 | for $config (keys(%allconfigs)) { | |
40 | my %options = %{$allconfigs{$config}}; | |
41 | ||
42 | print " processing $config ... "; | |
43 | ||
44 | for $key (keys(%common)) { | |
45 | next if not defined $common{$key}; | |
46 | ||
47 | # If we don't have the common option, then it isn't | |
48 | # common. If we do have that option, it must have the same | |
49 | # value. EXCEPT where this file does not have a value at all | |
50 | # which may safely be merged with any other value; the value | |
51 | # will be elided during recombination of the parts. | |
52 | if (!defined($options{$key})) { | |
53 | # Its ok really ... let it merge | |
54 | } elsif (not defined($options{$key})) { | |
55 | undef $common{$key}; | |
56 | } elsif ($common{$key} ne $options{$key}) { | |
57 | undef $common{$key}; | |
58 | } | |
59 | } | |
60 | ||
61 | print "done.\n"; | |
62 | } | |
63 | ||
64 | print "\n"; | |
65 | ||
66 | print "Creating common config ... "; | |
67 | ||
68 | open(COMMON, "> config.common"); | |
69 | print COMMON "#\n# Common config options automatically generated by splitconfig.pl\n#\n"; | |
70 | ||
71 | for $key (sort(keys(%common))) { | |
72 | if (not defined $common{$key}) { | |
73 | print COMMON "# CONFIG_$key is UNMERGABLE\n"; | |
74 | } elsif ($common{$key} eq "is not set") { | |
75 | print COMMON "# CONFIG_$key is not set\n"; | |
76 | } else { | |
77 | print COMMON "CONFIG_$key=$common{$key}\n"; | |
78 | } | |
79 | } | |
80 | close(COMMON); | |
81 | ||
82 | print "done.\n\n"; | |
83 | ||
84 | print "Creating stub configs ...\n"; | |
85 | ||
86 | for $config (keys(%allconfigs)) { | |
87 | my %options = %{$allconfigs{$config}}; | |
88 | ||
89 | print " processing $config ... "; | |
90 | ||
91 | open(STUB, "> $config"); | |
92 | print STUB "#\n# Config options for $config automatically generated by splitconfig.pl\n#\n"; | |
93 | ||
94 | for $key (sort(keys(%options))) { | |
95 | next if defined $common{$key}; | |
96 | ||
97 | if ($options{$key} =~ /^is /) { | |
98 | print STUB "# CONFIG_$key $options{$key}\n"; | |
99 | } else { | |
100 | print STUB "CONFIG_$key=$options{$key}\n"; | |
101 | } | |
102 | } | |
103 | ||
104 | close(STUB); | |
105 | ||
106 | print "done.\n"; | |
107 | } |