add missing dependency
[openwrt.git] / scripts / gen_package_config.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
11 my $src;
12 my $makefile;
13 my $pkg;
14 my %package;
15 my %category;
16
17
18 sub find_dep($$) {
19 my $pkg = shift;
20 my $name = shift;
21 my $deps = ($pkg->{vdepends} or $pkg->{depends});
22
23 return 0 unless defined $deps;
24 foreach my $dep (@{$deps}) {
25 return 1 if $dep eq $name;
26 return 1 if ($package{$dep} and (find_dep($package{$dep},$name) == 1));
27 }
28 return 0;
29 }
30
31 sub depends($$) {
32 my $a = shift;
33 my $b = shift;
34 my $ret;
35
36 return 0 if ($a->{submenu} ne $b->{submenu});
37 if (find_dep($a, $b->{name}) == 1) {
38 $ret = 1;
39 } elsif (find_dep($b, $a->{name}) == 1) {
40 $ret = -1;
41 } else {
42 return 0;
43 }
44 # print STDERR "depends($a->{name}, $b->{name}) == $ret\n";
45 return $ret;
46 }
47
48
49 sub print_category($) {
50 my $cat = shift;
51 my %menus;
52 my %menu_dep;
53
54 return unless $category{$cat};
55
56 print "menu \"$cat\"\n\n";
57 my %spkg = %{$category{$cat}};
58
59 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
60 foreach my $pkg (@{$spkg{$spkg}}) {
61 my $menu = $pkg->{submenu};
62 if ($menu) {
63 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
64 } else {
65 $menu = 'undef';
66 }
67 $menus{$menu} or $menus{$menu} = [];
68 push @{$menus{$menu}}, $pkg;
69 }
70 }
71 my @menus = sort {
72 ($a eq 'undef' ? 1 : 0) or
73 ($b eq 'undef' ? -1 : 0) or
74 ($a cmp $b)
75 } keys %menus;
76
77 foreach my $menu (@menus) {
78 my @pkgs = sort {
79 depends($a, $b) or
80 ($a->{name} cmp $b->{name})
81 } @{$menus{$menu}};
82 if ($menu ne 'undef') {
83 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
84 print "menu \"$menu\"\n";
85 }
86 foreach my $pkg (@pkgs) {
87 my $title = $pkg->{name};
88 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
89 if ($c > 0) {
90 $title .= ("." x $c). " ". $pkg->{title};
91 }
92 print "\tconfig DEFAULT_".$pkg->{name}."\n";
93 print "\t\tbool\n\n";
94 print "\t";
95 $pkg->{menu} and print "menu";
96 print "config PACKAGE_".$pkg->{name}."\n";
97 print "\t\ttristate \"$title\"\n";
98 print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
99 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
100 print "\t\tdefault $default\n";
101 }
102 foreach my $depend (@{$pkg->{depends}}) {
103 my $m = "depends";
104 $depend =~ s/^([@\+]+)//;
105 my $flags = $1;
106 my $vdep;
107
108 if ($vdep = $package{$depend}->{vdepends}) {
109 $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
110 } else {
111 $flags =~ /@/ or $depend = "PACKAGE_$depend";
112 $flags =~ /\+/ and $m = "select";
113 }
114 print "\t\t$m $depend\n";
115 }
116 print "\t\thelp\n";
117 print $pkg->{description};
118 print "\n";
119
120 $pkg->{config} and print $pkg->{config}."\n";
121 }
122 if ($menu ne 'undef') {
123 print "endmenu\n";
124 $menu_dep{$menu} and print "endif\n";
125 }
126 }
127 print "endmenu\n\n";
128
129 undef $category{$cat};
130 }
131
132 my $line;
133 while ($line = <>) {
134 chomp $line;
135 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
136 $makefile = $1;
137 $src = $2;
138 undef $pkg;
139 };
140 $line =~ /^Package: \s*(.+)\s*$/ and do {
141 $pkg = {};
142 $pkg->{src} = $src;
143 $pkg->{makefile} = $makefile;
144 $pkg->{name} = $1;
145 $pkg->{default} = "m if ALL";
146 $package{$1} = $pkg;
147 };
148 $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
149 $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
150 $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
151 $line =~ /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
152 $line =~ /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
153 $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
154 $line =~ /^Provides: \s*(.+)\s*$/ and do {
155 my @vpkg = split /\s+/, $1;
156 foreach my $vpkg (@vpkg) {
157 $package{$vpkg} or $package{$vpkg} = { vdepends => [] };
158 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
159 }
160 };
161 $line =~ /^Depends: \s*(.+)\s*$/ and do {
162 my @dep = split /\s+/, $1;
163 $pkg->{depends} = \@dep;
164 };
165 $line =~ /^Category: \s*(.+)\s*$/ and do {
166 $pkg->{category} = $1;
167 defined $category{$1} or $category{$1} = {};
168 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
169 push @{$category{$1}->{$src}}, $pkg;
170 };
171 $line =~ /^Description: \s*(.*)\s*$/ and do {
172 my $desc = "\t\t$1\n\n";
173 my $line;
174 while ($line = <>) {
175 last if $line =~ /^@@/;
176 $desc .= "\t\t$line";
177 }
178 $pkg->{description} = $desc;
179 };
180 $line =~ /^Config: \s*(.*)\s*$/ and do {
181 my $conf = "$1\n";
182 my $line;
183 while ($line = <>) {
184 last if $line =~ /^@@/;
185 $conf .= "$line";
186 }
187 $pkg->{config} = $conf;
188 }
189 }
190
191 print_category 'Base system';
192 foreach my $cat (keys %category) {
193 print_category $cat;
194 }
This page took 0.068054 seconds and 5 git commands to generate.