Skip to content

Commit

Permalink
Add scripts/reduce-config.pl
Browse files Browse the repository at this point in the history
The script can be used to generate a minimalistic kernel config file.
All lines, which don't make a difference to the resulting
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 a input line didn't make a difference, it is dropped permanently
from the output.
  • Loading branch information
donald committed Dec 15, 2017
1 parent b5dadc0 commit e71dd64
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions scripts/reduce-config.pl
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit e71dd64

Please sign in to comment.