Linux 3.2.88
[pandora-kernel.git] / scripts / kconfig / streamline_config.pl
index a4fe923..4a19a7f 100644 (file)
@@ -43,6 +43,7 @@
 #    make oldconfig
 #
 use strict;
+use Getopt::Long;
 
 my $config = ".config";
 
@@ -112,12 +113,19 @@ sub find_config {
 
 find_config;
 
+# Parse options
+my $localmodconfig = 0;
+my $localyesconfig = 0;
+
+GetOptions("localmodconfig" => \$localmodconfig,
+          "localyesconfig" => \$localyesconfig);
+
 # 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 $lsmod_file = $ENV{'LSMOD'};
 
-my @makefiles = `find $ksource -name Makefile 2>/dev/null`;
+my @makefiles = `find $ksource -name Makefile -or -name Kbuild 2>/dev/null`;
 chomp @makefiles;
 
 my %depends;
@@ -242,33 +250,61 @@ if ($kconfig) {
     read_kconfig($kconfig);
 }
 
+sub convert_vars {
+    my ($line, %vars) = @_;
+
+    my $process = "";
+
+    while ($line =~ s/^(.*?)(\$\((.*?)\))//) {
+       my $start = $1;
+       my $variable = $2;
+       my $var = $3;
+
+       if (defined($vars{$var})) {
+           $process .= $start . $vars{$var};
+       } else {
+           $process .= $start . $variable;
+       }
+    }
+
+    $process .= $line;
+
+    return $process;
+}
+
 # Read all Makefiles to map the configs to the objects
 foreach my $makefile (@makefiles) {
 
-    my $cont = 0;
+    my $line = "";
+    my %make_vars;
 
     open(MIN,$makefile) || die "Can't open $makefile";
     while (<MIN>) {
+       # if this line ends with a backslash, continue
+       chomp;
+       if (/^(.*)\\$/) {
+           $line .= $1;
+           next;
+       }
+
+       $line .= $_;
+       $_ = $line;
+       $line = "";
+
        my $objs;
 
-       # is this a line after a line with a backslash?
-       if ($cont && /(\S.*)$/) {
-           $objs = $1;
-       }
-       $cont = 0;
+       $_ = convert_vars($_, %make_vars);
 
        # collect objects after obj-$(CONFIG_FOO_BAR)
        if (/obj-\$\((CONFIG_[^\)]*)\)\s*[+:]?=\s*(.*)/) {
            $var = $1;
            $objs = $2;
+
+       # check if variables are set
+       } elsif (/^\s*(\S+)\s*[:]?=\s*(.*\S)/) {
+           $make_vars{$1} = $2;
        }
        if (defined($objs)) {
-           # test if the line ends with a backslash
-           if ($objs =~ m,(.*)\\$,) {
-               $objs = $1;
-               $cont = 1;
-           }
-
            foreach my $obj (split /\s+/,$objs) {
                $obj =~ s/-/_/g;
                if ($obj =~ /(.*)\.o$/) {
@@ -296,7 +332,11 @@ my %modules;
 
 if (defined($lsmod_file)) {
     if ( ! -f $lsmod_file) {
-       die "$lsmod_file not found";
+       if ( -f $ENV{'objtree'}."/".$lsmod_file) {
+           $lsmod_file = $ENV{'objtree'}."/".$lsmod_file;
+       } else {
+               die "$lsmod_file not found";
+       }
     }
     if ( -x $lsmod_file) {
        # the file is executable, run it
@@ -421,7 +461,13 @@ while(<CIN>) {
 
     if (/^(CONFIG.*)=(m|y)/) {
        if (defined($configs{$1})) {
-           $setconfigs{$1} = $2;
+           if ($localyesconfig) {
+               $setconfigs{$1} = 'y';
+               print "$1=y\n";
+               next;
+           } else {
+               $setconfigs{$1} = $2;
+           }
        } elsif ($2 eq "m") {
            print "# $1 is not set\n";
            next;