diff options
Diffstat (limited to 'scripts/kconfig/streamline_config.pl')
-rw-r--r-- | scripts/kconfig/streamline_config.pl | 109 |
1 files changed, 97 insertions, 12 deletions
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index 0d800820c3cd..fd81fc33d633 100644 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl @@ -42,6 +42,8 @@ # mv config_strip .config # make oldconfig # +use strict; + my $config = ".config"; my $uname = `uname -r`; @@ -113,14 +115,18 @@ find_config; # Get the build source and top level Kconfig file (passed in) my $ksource = $ARGV[0]; my $kconfig = $ARGV[1]; +my $lsmod_file = $ARGV[2]; + +my @makefiles = `find $ksource -name Makefile 2>/dev/null`; +chomp @makefiles; -my @makefiles = `find $ksource -name Makefile`; my %depends; my %selects; my %prompts; my %objects; my $var; -my $cont = 0; +my $iflevel = 0; +my @ifdeps; # prevent recursion my %read_kconfigs; @@ -132,19 +138,54 @@ sub read_kconfig { my $config; my @kconfigs; - open(KIN, "$ksource/$kconfig") || die "Can't open $kconfig"; + my $cont = 0; + my $line; + + my $source = "$ksource/$kconfig"; + my $last_source = ""; + + # Check for any environment variables used + while ($source =~ /\$(\w+)/ && $last_source ne $source) { + my $env = $1; + $last_source = $source; + $source =~ s/\$$env/$ENV{$env}/; + } + + open(KIN, "$source") || die "Can't open $kconfig"; while (<KIN>) { chomp; + # Make sure that lines ending with \ continue + if ($cont) { + $_ = $line . " " . $_; + } + + if (s/\\$//) { + $cont = 1; + $line = $_; + next; + } + + $cont = 0; + # collect any Kconfig sources if (/^source\s*"(.*)"/) { $kconfigs[$#kconfigs+1] = $1; } # configs found - if (/^\s*config\s+(\S+)\s*$/) { + if (/^\s*(menu)?config\s+(\S+)\s*$/) { $state = "NEW"; - $config = $1; + $config = $2; + + for (my $i = 0; $i < $iflevel; $i++) { + if ($i) { + $depends{$config} .= " " . $ifdeps[$i]; + } else { + $depends{$config} = $ifdeps[$i]; + } + $state = "DEP"; + } # collect the depends for the config } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) { @@ -164,7 +205,22 @@ sub read_kconfig { # configs without prompts must be selected } elsif ($state ne "NONE" && /^\s*tristate\s\S/) { # note if the config has a prompt - $prompt{$config} = 1; + $prompts{$config} = 1; + + # Check for if statements + } elsif (/^if\s+(.*\S)\s*$/) { + my $deps = $1; + # remove beginning and ending non text + $deps =~ s/^[^a-zA-Z0-9_]*//; + $deps =~ s/[^a-zA-Z0-9_]*$//; + + my @deps = split /[^a-zA-Z0-9_]+/, $deps; + + $ifdeps[$iflevel++] = join ':', @deps; + + } elsif (/^endif/) { + + $iflevel-- if ($iflevel); # stop on "help" } elsif (/^\s*help\s*$/) { @@ -188,7 +244,8 @@ if ($kconfig) { # Read all Makefiles to map the configs to the objects foreach my $makefile (@makefiles) { - chomp $makefile; + + my $cont = 0; open(MIN,$makefile) || die "Can't open $makefile"; while (<MIN>) { @@ -215,7 +272,7 @@ foreach my $makefile (@makefiles) { foreach my $obj (split /\s+/,$objs) { $obj =~ s/-/_/g; if ($obj =~ /(.*)\.o$/) { - # Objects may bes enabled by more than one config. + # Objects may be enabled by more than one config. # Store configs in an array. my @arr; @@ -237,8 +294,36 @@ foreach my $makefile (@makefiles) { my %modules; -# see what modules are loaded on this system -open(LIN,"/sbin/lsmod|") || die "Cant lsmod"; +if (defined($lsmod_file)) { + if ( ! -f $lsmod_file) { + die "$lsmod_file not found"; + } + if ( -x $lsmod_file) { + # the file is executable, run it + open(LIN, "$lsmod_file|"); + } else { + # Just read the contents + open(LIN, "$lsmod_file"); + } +} else { + + # see what modules are loaded on this system + my $lsmod; + + foreach my $dir ( ("/sbin", "/bin", "/usr/sbin", "/usr/bin") ) { + if ( -x "$dir/lsmod" ) { + $lsmod = "$dir/lsmod"; + last; + } +} + if (!defined($lsmod)) { + # try just the path + $lsmod = "lsmod"; + } + + open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod"; +} + while (<LIN>) { next if (/^Module/); # Skip the first line. if (/^(\S+)/) { @@ -252,7 +337,7 @@ close (LIN); my %configs; foreach my $module (keys(%modules)) { if (defined($objects{$module})) { - @arr = @{$objects{$module}}; + my @arr = @{$objects{$module}}; foreach my $conf (@arr) { $configs{$conf} = $module; } @@ -307,7 +392,7 @@ while ($repeat) { parse_config_dep_select $depends{$config}; } - if (defined($prompt{$config}) || !defined($selects{$config})) { + if (defined($prompts{$config}) || !defined($selects{$config})) { next; } |