diff --git a/scripts/reduce-config.pl b/scripts/reduce-config.pl new file mode 100755 index 000000000..ebccab42e --- /dev/null +++ b/scripts/reduce-config.pl @@ -0,0 +1,86 @@ +#! /usr/bin/perl +use strict; +use warnings; + +our $CONFIG_IN='./config.in'; +our $CONFIG_OUT='./config.reduced'; + +my @lines; +my @disa; + +sub read_config { + my ($fn)=@_; + open my $in,'<',$CONFIG_IN or die "$CONFIG_IN: $!\n"; + @lines=(<$in>); +} + +sub write_config { + my ($fn)=@_; + open my $out,'>',$fn or die "$fn: $!\n"; + for (my $i=0;$i<@lines;$i++) { + print $out $lines[$i] unless $disa[$i]; + } + close $out; +} + +sub build { + write_config('.config'); + system 'make olddefconfig>/dev/null'; + if ($?) { + warn "make failed: $?\n"; + return 0; + } + return 1; +} + +sub try { + write_config('./config'); + build() or return 0; + system 'cmp','-s','.config','.config.target.tmp'; + if ($?==0) { + return 1; + } else { + return 0; + } +} + +read_config($CONFIG_IN); +build() or die "failed to build with original config\n"; +system 'cp','.config','.config.target.tmp' and exit 1; + +my $p=0; +my $progress=0; + +while (1) { + if ($disa[$p]) { + ; + } else { + $disa[$p]=1; + if (try) { + $progress=1; + warn "disable $lines[$p]"; + } else { + $disa[$p]=0; + warn "keep $lines[$p]"; + } + } + $p++; + if ($p>=@lines) { + if ($progress) { + warn "starting over\n"; + $p=0; + $progress=0; + } + else { + warn "no progress. finished\n"; + last; + } + } +} + +# generate a valid .config +try() or die "final compare failed\n"; + +# and save the result +write_config($CONFIG_OUT); +