aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 16:17:41 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 16:17:41 -0400
commitf6bcfc9dd48d305211283b7f7d55e3779a2f661b (patch)
tree1d3f8c6e96ec519674edd510b03fb84342c0cb26 /scripts/kconfig
parent8f838e592d0349b6475830ec5fbe049d432ffbdd (diff)
parent4503379cb811809470ebefb58c943fe605bc3e29 (diff)
Merge tag 'localmodconfig-v3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-kconfig
Pull localmodconfig updates from Steven Rostedt: "Improve localmodconfig to remove even more unused module configs. These changes drastically improve the amount of module configs removed from a config file. It also adds some debug that I can have users easily enable if things do not work for them." * tag 'localmodconfig-v3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-kconfig: localmodconfig: Add debug environment variable LOCALMODCONFIG_DEBUG localmodconfig: Check if configs are already set for selects localmodconfig: Read in orig config file to avoid extra processing localmodconfig: Comments and cleanup for streamline_config.pl
Diffstat (limited to 'scripts/kconfig')
-rw-r--r--scripts/kconfig/streamline_config.pl175
1 files changed, 158 insertions, 17 deletions
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
index bccf07ddd0b6..2fbbbc1ddea0 100644
--- a/scripts/kconfig/streamline_config.pl
+++ b/scripts/kconfig/streamline_config.pl
@@ -45,6 +45,16 @@
45use strict; 45use strict;
46use Getopt::Long; 46use Getopt::Long;
47 47
48# set the environment variable LOCALMODCONFIG_DEBUG to get
49# debug output.
50my $debugprint = 0;
51$debugprint = 1 if (defined($ENV{LOCALMODCONFIG_DEBUG}));
52
53sub dprint {
54 return if (!$debugprint);
55 print STDERR @_;
56}
57
48my $config = ".config"; 58my $config = ".config";
49 59
50my $uname = `uname -r`; 60my $uname = `uname -r`;
@@ -113,6 +123,10 @@ sub find_config {
113 123
114find_config; 124find_config;
115 125
126# Read in the entire config file into config_file
127my @config_file = <CIN>;
128close CIN;
129
116# Parse options 130# Parse options
117my $localmodconfig = 0; 131my $localmodconfig = 0;
118my $localyesconfig = 0; 132my $localyesconfig = 0;
@@ -186,6 +200,7 @@ sub read_kconfig {
186 $state = "NEW"; 200 $state = "NEW";
187 $config = $2; 201 $config = $2;
188 202
203 # Add depends for 'if' nesting
189 for (my $i = 0; $i < $iflevel; $i++) { 204 for (my $i = 0; $i < $iflevel; $i++) {
190 if ($i) { 205 if ($i) {
191 $depends{$config} .= " " . $ifdeps[$i]; 206 $depends{$config} .= " " . $ifdeps[$i];
@@ -204,10 +219,11 @@ sub read_kconfig {
204 219
205 # Get the configs that select this config 220 # Get the configs that select this config
206 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) { 221 } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
207 if (defined($selects{$1})) { 222 my $conf = $1;
208 $selects{$1} .= " " . $config; 223 if (defined($selects{$conf})) {
224 $selects{$conf} .= " " . $config;
209 } else { 225 } else {
210 $selects{$1} = $config; 226 $selects{$conf} = $config;
211 } 227 }
212 228
213 # configs without prompts must be selected 229 # configs without prompts must be selected
@@ -250,6 +266,7 @@ if ($kconfig) {
250 read_kconfig($kconfig); 266 read_kconfig($kconfig);
251} 267}
252 268
269# Makefiles can use variables to define their dependencies
253sub convert_vars { 270sub convert_vars {
254 my ($line, %vars) = @_; 271 my ($line, %vars) = @_;
255 272
@@ -293,6 +310,7 @@ foreach my $makefile (@makefiles) {
293 310
294 my $objs; 311 my $objs;
295 312
313 # Convert variables in a line (could define configs)
296 $_ = convert_vars($_, %make_vars); 314 $_ = convert_vars($_, %make_vars);
297 315
298 # collect objects after obj-$(CONFIG_FOO_BAR) 316 # collect objects after obj-$(CONFIG_FOO_BAR)
@@ -373,13 +391,15 @@ while (<LIN>) {
373close (LIN); 391close (LIN);
374 392
375# add to the configs hash all configs that are needed to enable 393# add to the configs hash all configs that are needed to enable
376# a loaded module. 394# a loaded module. This is a direct obj-${CONFIG_FOO} += bar.o
395# where we know we need bar.o so we add FOO to the list.
377my %configs; 396my %configs;
378foreach my $module (keys(%modules)) { 397foreach my $module (keys(%modules)) {
379 if (defined($objects{$module})) { 398 if (defined($objects{$module})) {
380 my @arr = @{$objects{$module}}; 399 my @arr = @{$objects{$module}};
381 foreach my $conf (@arr) { 400 foreach my $conf (@arr) {
382 $configs{$conf} = $module; 401 $configs{$conf} = $module;
402 dprint "$conf added by direct ($module)\n";
383 } 403 }
384 } else { 404 } else {
385 # Most likely, someone has a custom (binary?) module loaded. 405 # Most likely, someone has a custom (binary?) module loaded.
@@ -387,9 +407,24 @@ foreach my $module (keys(%modules)) {
387 } 407 }
388} 408}
389 409
410# Read the current config, and see what is enabled. We want to
411# ignore configs that we would not enable anyway.
412
413my %orig_configs;
390my $valid = "A-Za-z_0-9"; 414my $valid = "A-Za-z_0-9";
415
416foreach my $line (@config_file) {
417 $_ = $line;
418
419 if (/(CONFIG_[$valid]*)=(m|y)/) {
420 $orig_configs{$1} = $2;
421 }
422}
423
391my $repeat = 1; 424my $repeat = 1;
392 425
426my $depconfig;
427
393# 428#
394# Note, we do not care about operands (like: &&, ||, !) we want to add any 429# Note, we do not care about operands (like: &&, ||, !) we want to add any
395# config that is in the depend list of another config. This script does 430# config that is in the depend list of another config. This script does
@@ -398,7 +433,7 @@ my $repeat = 1;
398# to keep on. If A was on in the original config, B would not have been 433# to keep on. If A was on in the original config, B would not have been
399# and B would not be turned on by this script. 434# and B would not be turned on by this script.
400# 435#
401sub parse_config_dep_select 436sub parse_config_depends
402{ 437{
403 my ($p) = @_; 438 my ($p) = @_;
404 439
@@ -409,10 +444,16 @@ sub parse_config_dep_select
409 444
410 $p =~ s/^[^$valid]*[$valid]+//; 445 $p =~ s/^[^$valid]*[$valid]+//;
411 446
447 # We only need to process if the depend config is a module
448 if (!defined($orig_configs{$conf}) || !$orig_configs{conf} eq "m") {
449 next;
450 }
451
412 if (!defined($configs{$conf})) { 452 if (!defined($configs{$conf})) {
413 # We must make sure that this config has its 453 # We must make sure that this config has its
414 # dependencies met. 454 # dependencies met.
415 $repeat = 1; # do again 455 $repeat = 1; # do again
456 dprint "$conf selected by depend $depconfig\n";
416 $configs{$conf} = 1; 457 $configs{$conf} = 1;
417 } 458 }
418 } else { 459 } else {
@@ -421,31 +462,132 @@ sub parse_config_dep_select
421 } 462 }
422} 463}
423 464
424while ($repeat) { 465# Select is treated a bit differently than depends. We call this
425 $repeat = 0; 466# when a config has no prompt and requires another config to be
467# selected. We use to just select all configs that selected this
468# config, but found that that can balloon into enabling hundreds
469# of configs that we do not care about.
470#
471# The idea is we look at all the configs that select it. If one
472# is already in our list of configs to enable, then there's nothing
473# else to do. If there isn't, we pick the first config that was
474# enabled in the orignal config and use that.
475sub parse_config_selects
476{
477 my ($config, $p) = @_;
426 478
427 foreach my $config (keys %configs) { 479 my $next_config;
428 $config =~ s/^CONFIG_//; 480
481 while ($p =~ /[$valid]/) {
429 482
430 if (defined($depends{$config})) { 483 if ($p =~ /^[^$valid]*([$valid]+)/) {
431 # This config has dependencies. Make sure they are also included 484 my $conf = "CONFIG_" . $1;
432 parse_config_dep_select $depends{$config}; 485
486 $p =~ s/^[^$valid]*[$valid]+//;
487
488 # Make sure that this config exists in the current .config file
489 if (!defined($orig_configs{$conf})) {
490 dprint "$conf not set for $config select\n";
491 next;
492 }
493
494 # Check if something other than a module selects this config
495 if (defined($orig_configs{$conf}) && $orig_configs{$conf} ne "m") {
496 dprint "$conf (non module) selects config, we are good\n";
497 # we are good with this
498 return;
499 }
500 if (defined($configs{$conf})) {
501 dprint "$conf selects $config so we are good\n";
502 # A set config selects this config, we are good
503 return;
504 }
505 # Set this config to be selected
506 if (!defined($next_config)) {
507 $next_config = $conf;
508 }
509 } else {
510 die "this should never happen";
433 } 511 }
512 }
434 513
435 if (defined($prompts{$config}) || !defined($selects{$config})) { 514 # If no possible config selected this, then something happened.
436 next; 515 if (!defined($next_config)) {
516 print STDERR "WARNING: $config is required, but nothing in the\n";
517 print STDERR " current config selects it.\n";
518 return;
519 }
520
521 # If we are here, then we found no config that is set and
522 # selects this config. Repeat.
523 $repeat = 1;
524 # Make this config need to be selected
525 $configs{$next_config} = 1;
526 dprint "$next_config selected by select $config\n";
527}
528
529my %process_selects;
530
531# loop through all configs, select their dependencies.
532sub loop_depend {
533 $repeat = 1;
534
535 while ($repeat) {
536 $repeat = 0;
537
538 forloop:
539 foreach my $config (keys %configs) {
540
541 # If this config is not a module, we do not need to process it
542 if (defined($orig_configs{$config}) && $orig_configs{$config} ne "m") {
543 next forloop;
544 }
545
546 $config =~ s/^CONFIG_//;
547 $depconfig = $config;
548
549 if (defined($depends{$config})) {
550 # This config has dependencies. Make sure they are also included
551 parse_config_depends $depends{$config};
552 }
553
554 # If the config has no prompt, then we need to check if a config
555 # that is enabled selected it. Or if we need to enable one.
556 if (!defined($prompts{$config}) && defined($selects{$config})) {
557 $process_selects{$config} = 1;
558 }
437 } 559 }
560 }
561}
562
563sub loop_select {
564
565 foreach my $config (keys %process_selects) {
566 $config =~ s/^CONFIG_//;
567
568 dprint "Process select $config\n";
438 569
439 # config has no prompt and must be selected. 570 # config has no prompt and must be selected.
440 parse_config_dep_select $selects{$config}; 571 parse_config_selects $config, $selects{$config};
441 } 572 }
442} 573}
443 574
575while ($repeat) {
576 # Get the first set of configs and their dependencies.
577 loop_depend;
578
579 $repeat = 0;
580
581 # Now we need to see if we have to check selects;
582 loop_select;
583}
584
444my %setconfigs; 585my %setconfigs;
445 586
446# Finally, read the .config file and turn off any module enabled that 587# Finally, read the .config file and turn off any module enabled that
447# we could not find a reason to keep enabled. 588# we could not find a reason to keep enabled.
448while(<CIN>) { 589foreach my $line (@config_file) {
590 $_ = $line;
449 591
450 if (/CONFIG_IKCONFIG/) { 592 if (/CONFIG_IKCONFIG/) {
451 if (/# CONFIG_IKCONFIG is not set/) { 593 if (/# CONFIG_IKCONFIG is not set/) {
@@ -473,7 +615,6 @@ while(<CIN>) {
473 } 615 }
474 print; 616 print;
475} 617}
476close(CIN);
477 618
478# Integrity check, make sure all modules that we want enabled do 619# Integrity check, make sure all modules that we want enabled do
479# indeed have their configs set. 620# indeed have their configs set.