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