busybox: add 2 upstream fixes
[openwrt.git] / package / utils / busybox / convert_menuconfig.pl
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
9 use strict;
10 my $PATH = $ARGV[0];
11 ($PATH and -d $PATH) or die 'invalid path';
12
13 my %config;
14
15 open FIND, "find \"$PATH\" -name Config.in |";
16 while (<FIND>) {
17         chomp;
18         my $input = $_;
19         s/^$PATH\///g;
20         s/sysdeps\/linux\///g;
21         my $output = $_;
22         print STDERR "$input => $output\n";
23         $output =~ /^(.+)\/[^\/]+$/ and system("mkdir -p $1");
24
25         open INPUT, $input;
26         open OUTPUT, ">$output";
27         my ($cur, $default_set, $line);
28         while ($line = <INPUT>) {
29                 next if $line =~ /^\s*mainmenu/;
30
31                 # FIXME: make this dynamic
32                 $line =~ s/default FEATURE_BUFFERS_USE_MALLOC/default FEATURE_BUFFERS_GO_ON_STACK/;
33                 $line =~ s/default FEATURE_SH_IS_NONE/default FEATURE_SH_IS_ASH/;
34
35                 if ($line =~ /^\s*config\s*([\w_]+)/) {
36                         $cur = $1;
37                         undef $default_set;
38                 }
39                 if ($line =~ /^\s*(menu|choice|end|source)/) {
40                         undef $cur;
41                         undef $default_set;
42                 }
43                 $line =~ s/^(\s*source\s+)/$1package\/utils\/busybox\/config\//;
44
45                 $line =~ s/^(\s*(prompt "[^"]+" if|config|depends|depends on|select|default|default \w if)\s+\!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
46                 $line =~ s/(( \|\| | \&\& | \( )!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
47                 $line =~ s/(\( ?!?)([A-Z_]+ (\|\||&&))/$1BUSYBOX_CONFIG_$2/g;
48
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
58                                 $line =~ s/^(\s*default\s*)(\w+|"[^"]*")(.*)/$1$c$3/;
59                         }
60                 }
61
62                 print OUTPUT $line;
63         }
64         close OUTPUT;
65         close INPUT;
66 }
67 close FIND;