From f32d1e4eb10fd398aeabfac23d6f3d4e675b55d3 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 14 Dec 2017 12:33:29 +0100 Subject: [PATCH] Add scripts/reduce-config.pl The script can be used to generate a minimalistic kernel config file. All implied lines (default, coomment, computed) which don't make a difference to the configuration are removed. To use: - cd into a kernel build directory - copy the input configuration to config.in - run this script The minimalistic config file can the be found in config.reduced. The script works by removing lines from the config file one by one, runnig "make olddefconfig" and comparing the results. If the removal of an inout line doesn't make a difference, it is dropped permanently in the output. --- scripts/reduce-config.pl | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 scripts/reduce-config.pl diff --git a/scripts/reduce-config.pl b/scripts/reduce-config.pl new file mode 100755 index 000000000..4e65f8c81 --- /dev/null +++ b/scripts/reduce-config.pl @@ -0,0 +1,85 @@ +#! /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);