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