Fix dependency on zlib
[openwrt.git] / scripts / gen_busybox_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 my $DEFCONFIG = $ARGV[1];
13 ($DEFCONFIG and -f $DEFCONFIG) or die 'invalid config file';
14
15 my %config;
16
17 open CONFIG, $DEFCONFIG or die 'cannot open config file';
18 while (<CONFIG>) {
19 /^CONFIG_([\w_]+)=([ym])/ and $config{$1} = $2;
20 /^CONFIG_([\w_]+)=(\d+)/ and $config{$1} = $2;
21 /^CONFIG_([\w_]+)=(".+")/ and $config{$1} = $2;
22 }
23 close CONFIG;
24
25 open FIND, "find \"$PATH\" -name Config.in |";
26 while (<FIND>) {
27 chomp;
28 my $input = $_;
29 s/^$PATH\///g;
30 s/sysdeps\/linux\///g;
31 my $output = $_;
32 print STDERR "$input => $output\n";
33 $output =~ /^(.+)\/[^\/]+$/ and system("mkdir -p $1");
34
35 open INPUT, $input;
36 open OUTPUT, ">$output";
37 my ($cur, $default_set, $line);
38 while ($line = <INPUT>) {
39 next if $line =~ /^\s*mainmenu/;
40
41 # FIXME: make this dynamic
42 $line =~ s/default FEATURE_BUFFERS_USE_MALLOC/default FEATURE_BUFFERS_GO_ON_STACK/;
43 $line =~ s/default FEATURE_SH_IS_NONE/default FEATURE_SH_IS_ASH/;
44
45 if ($line =~ /^\s*config\s*([\w_]+)/) {
46 $cur = $1;
47 undef $default_set;
48 }
49 if ($line =~ /^\s*(menu|choice|end|source)/) {
50 undef $cur;
51 undef $default_set;
52 }
53 $line =~ s/^(\s*source\s+)/$1package\/busybox\/config\//;
54
55 $line =~ s/^(\s*(prompt "[^"]+" if|config|depends|depends on|select|default|default \w if)\s+\!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
56 $line =~ s/(( \|\| | \&\& | \( )!?)([A-Z_])/$1BUSYBOX_CONFIG_$3/g;
57 $line =~ s/(\( ?!?)([A-Z_]+ (\|\||&&))/$1BUSYBOX_CONFIG_$2/g;
58
59 if ($cur) {
60 ($cur eq 'LFS') and do {
61 $line =~ s/^(\s*(bool|tristate|string))\s*".+"$/$1/;
62 };
63 if ($line =~ /^\s*default/) {
64 my $c;
65 $default_set = 1;
66 $c = $config{$cur} or $c = 'n';
67
68 $line =~ s/^(\s*default\s*)(\w+|"[^"]*")(.*)/$1$c$3/;
69 }
70 }
71
72 print OUTPUT $line;
73 }
74 close OUTPUT;
75 close INPUT;
76
77 }
78 close FIND;
This page took 0.057431 seconds and 5 git commands to generate.