3 # Script used to sort kernel-*.config files.
5 # ./kernel-config-sort.pl ../BUILD/linux-2.6.*/ kernel-multiarch.config
7 # ./kernel-config-sort.pl ../BUILD/linux-2.6.*/ -a x86 kernel-x86_84.config
12 my $dir = ( shift @ARGV ) || ".";
14 if ( $ARGV[0] eq "-a" ) {
18 my $old_dir = $ENV{PWD};
27 my @files = glob $parent."*";
30 if ( $_ eq "Documentation" or $_ eq "build-done" ) {
37 if ( m#^.*/Kconfig# ) {
39 push @Kconfig_arch, $_;
41 push @Kconfig_list, $_;
48 push @Kconfig_list, "arch/$arch/Kconfig";
51 push @Kconfig_list, @Kconfig_arch;
65 warn "FILE $file does not exist\n";
69 open my $f_in, '<', $file;
71 if ( /^\s?(?:menu)?config\s+(.*?)`?\s*$/ ) {
72 if ( $byName{ $1 } ) {
73 warn "Warning: $file: $1 already defined in $byName{ $1 }\n";
76 push @config_list, [ 'o', $1 ];
79 if ( /^\s?comment\s+"(.*?)"\s*$/ ) {
80 push @config_list, [ 'c', $1 ];
83 if ( /^\s*source\s+"(\S+?)"\s*$/ or /^\s*source\s+(\S+?)\s*$/) {
84 push @maybe_add_source, $1;
85 push @config_list, [ 's', $1 ];
91 $byFile{ $file } = \@config_list;
95 @add{ @maybe_add_source } = ();
96 foreach ( @Kconfig_list ) {
97 delete $add{ $_ } if exists $add{ $_ };
100 #warn "Adding more source files: " . ( join ", ", sort keys %add ) ."\n";
101 push @Kconfig_list, sort keys %add;
108 for ( $i = 0; $i < scalar @Kconfig_list; $i++ ) {
109 my $file = $Kconfig_list[ $i ];
110 add_Kconfig( $file );
118 foreach my $f ( sort keys %byFile ) {
119 next unless $f =~ /^arch/;
120 foreach my $line ( @{ $byFile{ $f } } ) {
121 push @arch_specific, $line->[1]
122 if $line->[0] eq 'o';
124 delete $byFile{ $f };
127 my @as = map { [ 'o', $_ ] } sort @arch_specific;
128 $arch_specific = \@as;
133 my $out_file = $ARGV[ $#ARGV ];
137 my $allowed_name = qr/[A-Za-z0-9_]+/;
145 if ( /^# CONFIG_($allowed_name) is not set$/ ) {
148 if ( /^(?:CONFIG_)?($allowed_name)[=\s]/ ) {
152 if ( /\S/ and !/^#-/ ) {
153 warn "Ignored line: $_";
158 if ( exists $setOptions{ $opt } ) {
159 die "OPTION $opt REDEFINED";
162 $setOptions{ $opt } = $comment . $_;
171 push @out, "#-", "#- *** FILE: $file ***", "#-";
172 my $file_lines = $byFile{ $file };
174 foreach my $line ( @{$file_lines} ) {
175 my ($type, $data) = @$line;
176 if ( $type eq 'o' ) {
177 if ( exists $setOptions{ $data } ) {
178 push @out, $setOptions{ $data };
179 delete $setOptions{ $data };
182 } elsif ( $type eq 'c' ) {
183 push @out, "#- $data";
184 } elsif ( $type eq 's' ) {
185 push @out, "#- file $data goes here";
189 return "\n" . ( join "\n", @out ) . "\n";
194 *FILE_OUT = \*STDOUT;
196 open FILE_OUT, '>', $out_file;
200 foreach my $f ( sort keys %byFile ) {
201 push @out, file_out( $f );
204 my $as_name = "arch/* - ARCH SPECIFIC OPTIONS";
205 $byFile{ $as_name } = $arch_specific;
206 unshift @out, file_out( $as_name );
210 foreach my $f ( sort keys %byFile ) {
211 print FILE_OUT file_out( $f );
215 if ( keys %setOptions ) {
216 print FILE_OUT "\n#-\n#- *** PROBABLY REMOVED OPTIONS ***\n#-\n";
217 foreach my $k ( sort keys %setOptions ) {
218 print FILE_OUT $setOptions{ $k } . "\n";