1
0

convert_menuconfig.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. my $output = $input;
  17. my $replace = quotemeta($PATH);
  18. $output =~ s/^$replace\///g;
  19. $output =~ s/sysdeps\/linux\///g;
  20. print STDERR "$input => $output\n";
  21. $output =~ /^(.+)\/[^\/]+$/ and system("mkdir -p $1");
  22. open INPUT, $input;
  23. open OUTPUT, ">$output";
  24. my ($cur, $default_set, $line);
  25. while ($line = <INPUT>) {
  26. next if $line =~ /^\s*mainmenu/;
  27. # FIXME: make this dynamic
  28. $line =~ s/default FEATURE_BUFFERS_USE_MALLOC/default FEATURE_BUFFERS_GO_ON_STACK/;
  29. $line =~ s/default FEATURE_SH_IS_NONE/default FEATURE_SH_IS_ASH/;
  30. if ($line =~ /^\s*config\s*([\w_]+)/) {
  31. $cur = $1;
  32. undef $default_set;
  33. }
  34. if ($line =~ /^\s*(menu|choice|end|source)/) {
  35. undef $cur;
  36. undef $default_set;
  37. }
  38. $line =~ s/^(\s*source\s+)([^\/]+\/)*([^\/]+\/[^\/]+)$/$1$3/;
  39. if ($line =~ /^(\s*range\s*)(\w+)(\s+)(\w+)\s*$/) {
  40. my $prefix = $1;
  41. my $r1 = $2;
  42. my $r2 = $4;
  43. $r1 =~ s/^([a-zA-Z]+)/BUSYBOX_CONFIG_$1/;
  44. $r2 =~ s/^([a-zA-Z]+)/BUSYBOX_CONFIG_$1/;
  45. $line = "$prefix$r1 $r2\n";
  46. }
  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 = "BUSYBOX_DEFAULT_$cur";
  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;