add PROVIDES option, currently only used for menuconfig
[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 /^([\w_]+)=([ym])/ and $config{$1} = $2;
20 /^([\w_]+)=(\d+)/ and $config{$1} = $2;
21 /^([\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 CONFIG_FEATURE_BUFFERS_USE_MALLOC/default CONFIG_FEATURE_BUFFERS_GO_ON_STACK/;
43 $line =~ s/default BUSYBOX_CONFIG_FEATURE_SH_IS_NONE/default BUSYBOX_CONFIG_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+)((CONFIG|FDISK|USING|CROSS|EXTRA|PREFIX|FEATURE|HAVE|BUSYBOX)[\w_]*)/$1BUSYBOX_$2/g;
56
57 if ($cur) {
58 ($cur !~ /^CONFIG/ or $cur eq 'CONFIG_LFS') and do {
59 $line =~ s/^(\s*(bool|tristate|string))\s*".+"$/$1/;
60 };
61 if ($line =~ /^\s*default/) {
62 my $c;
63 $default_set = 1;
64 $c = $config{$cur} or $c = 'n';
65
66 $line =~ s/^(\s*default\s*)(\w+|"[^"]*")(.*)/$1$c$3/;
67 }
68 }
69
70 print OUTPUT $line;
71 }
72 close OUTPUT;
73 close INPUT;
74
75 }
76 close FIND;
This page took 0.04543 seconds and 5 git commands to generate.