convert_menuconfig.pl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) 2006 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. use strict;
  9. my $PATH = $ARGV[0];
  10. ($PATH and -d $PATH) or die 'invalid path';
  11. my $DEFCONFIG = $ARGV[1];
  12. ($DEFCONFIG and -f $DEFCONFIG) or die 'invalid config file';
  13. my %config;
  14. open CONFIG, $DEFCONFIG or die 'cannot open config file';
  15. while (<CONFIG>) {
  16. /^CONFIG_([\w_]+)=([ym])/ and $config{$1} = $2;
  17. /^CONFIG_([\w_]+)=(\d+)/ and $config{$1} = $2;
  18. /^CONFIG_([\w_]+)=(".+")/ and $config{$1} = $2;
  19. }
  20. close CONFIG;
  21. open FIND, "find \"$PATH\" -name Config.in |";
  22. while (<FIND>) {
  23. chomp;
  24. my $input = $_;
  25. s/^$PATH\///g;
  26. s/sysdeps\/linux\///g;
  27. my $output = $_;
  28. print STDERR "$input => $output\n";
  29. $output =~ /^(.+)\/[^\/]+$/ and system("mkdir -p $1");
  30. open INPUT, $input;
  31. open OUTPUT, ">$output";
  32. my ($cur, $default_set, $line);
  33. while ($line = <INPUT>) {
  34. next if $line =~ /^\s*mainmenu/;
  35. # FIXME: make this dynamic
  36. $line =~ s/default FEATURE_BUFFERS_USE_MALLOC/default FEATURE_BUFFERS_GO_ON_STACK/;
  37. $line =~ s/default FEATURE_SH_IS_NONE/default FEATURE_SH_IS_ASH/;
  38. if ($line =~ /^\s*config\s*([\w_]+)/) {
  39. $cur = $1;
  40. undef $default_set;
  41. }
  42. if ($line =~ /^\s*(menu|choice|end|source)/) {
  43. undef $cur;
  44. undef $default_set;
  45. }
  46. $line =~ s/^(\s*source\s+)/$1package\/busybox\/config\//;
  47. $line =~ s/^(\s*(prompt "[^"]+" if|config|depends|depends on|select|default|default \w if)\s+\!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
  48. $line =~ s/(( \|\| | \&\& | \( )!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
  49. $line =~ s/(\( ?!?)([A-Z_]+ (\|\||&&))/$1BUSYBOX_CONFIG_$2/g;
  50. if ($cur) {
  51. ($cur eq 'LFS') and do {
  52. $line =~ s/^(\s*(bool|tristate|string))\s*".+"$/$1/;
  53. };
  54. if ($line =~ /^\s*default/) {
  55. my $c;
  56. $default_set = 1;
  57. $c = $config{$cur} or $c = 'n';
  58. $line =~ s/^(\s*default\s*)(\w+|"[^"]*")(.*)/$1$c$3/;
  59. }
  60. }
  61. print OUTPUT $line;
  62. }
  63. close OUTPUT;
  64. close INPUT;
  65. }
  66. close FIND;