convert_menuconfig.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 %config;
  12. open FIND, "find \"$PATH\" -name Config.in |";
  13. while (<FIND>) {
  14. chomp;
  15. my $input = $_;
  16. s/^$PATH\///g;
  17. s/sysdeps\/linux\///g;
  18. my $output = $_;
  19. print STDERR "$input => $output\n";
  20. $output =~ /^(.+)\/[^\/]+$/ and system("mkdir -p $1");
  21. open INPUT, $input;
  22. open OUTPUT, ">$output";
  23. my ($cur, $default_set, $line);
  24. while ($line = <INPUT>) {
  25. next if $line =~ /^\s*mainmenu/;
  26. # FIXME: make this dynamic
  27. $line =~ s/default FEATURE_BUFFERS_USE_MALLOC/default FEATURE_BUFFERS_GO_ON_STACK/;
  28. $line =~ s/default FEATURE_SH_IS_NONE/default FEATURE_SH_IS_ASH/;
  29. if ($line =~ /^\s*config\s*([\w_]+)/) {
  30. $cur = $1;
  31. undef $default_set;
  32. }
  33. if ($line =~ /^\s*(menu|choice|end|source)/) {
  34. undef $cur;
  35. undef $default_set;
  36. }
  37. $line =~ s/^(\s*source\s+)/$1package\/utils\/busybox\/config\//;
  38. if ($line =~ /^(\s*range\s*)(\w+)(\s+)(\w+)\s*$/) {
  39. my $prefix = $1;
  40. my $r1 = $2;
  41. my $r2 = $4;
  42. $r1 =~ s/^([a-zA-Z]+)/BUSYBOX_CONFIG_$1/;
  43. $r2 =~ s/^([a-zA-Z]+)/BUSYBOX_CONFIG_$1/;
  44. $line = "$prefix$r1 $r2\n";
  45. }
  46. $line =~ s/^(\s*(prompt "[^"]+" if|config|depends|depends on|select|default|default \w if)\s+\!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
  47. $line =~ s/(( \|\| | \&\& | \( )!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
  48. $line =~ s/(\( ?!?)([A-Z_]+ (\|\||&&))/$1BUSYBOX_CONFIG_$2/g;
  49. if ($cur) {
  50. ($cur eq 'LFS') and do {
  51. $line =~ s/^(\s*(bool|tristate|string))\s*".+"$/$1/;
  52. };
  53. if ($line =~ /^\s*default/) {
  54. my $c;
  55. $default_set = 1;
  56. $c = "BUSYBOX_DEFAULT_$cur";
  57. $line =~ s/^(\s*default\s*)(\w+|"[^"]*")(.*)/$1$c$3/;
  58. }
  59. }
  60. print OUTPUT $line;
  61. }
  62. close OUTPUT;
  63. close INPUT;
  64. }
  65. close FIND;