5 our @EXPORT = qw(%package %vpackage %srcpackage %category %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
26 $str .= (($_ and $prefix) ? $prefix . $_ : $_);
29 return $str ? $str : "";
34 $conf =~ tr#/\.\-/#___#;
38 sub parse_package_metadata_usergroup($$$$$) {
47 # the regex for name is taken from is_valid_name() of package shadow
48 if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
51 } elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
55 warn "$makefile: invalid $typename spec $spec\n";
59 if ($id =~ /^[1-9]\d*$/) {
61 warn "$makefile: $typename $name id $id >= 65536";
64 if (not exists $ids->{$id}) {
67 makefile => $makefile,
69 } elsif ($ids->{$id}{name} ne $name) {
70 warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
74 warn "$makefile: $typename $name has invalid id $id\n";
78 if (not exists $names->{$name}) {
81 makefile => $makefile,
83 } elsif ($names->{$name}{id} != $id) {
84 warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
90 sub parse_target_metadata($) {
92 my ($target, @target, $profile);
96 open FILE, "<$file" or do {
97 warn "Can't open file '$file': $!\n";
102 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and $makefile = $1;
103 /^Target:\s*(.+)\s*$/ and do {
108 makefile => $makefile,
109 boardconf => confstr($name),
110 conf => confstr($name),
116 push @target, $target;
117 $target{$name} = $target;
118 if ($name =~ /([^\/]+)\/([^\/]+)/) {
119 push @{$target{$1}->{subtargets}}, $2;
120 $target->{board} = $1;
121 $target->{boardconf} = confstr($1);
122 $target->{subtarget} = 1;
123 $target->{parent} = $target{$1};
126 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
127 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
128 /^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1;
129 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
130 /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
131 /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
132 /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
133 /^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
134 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
135 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
136 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
137 /^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
138 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
139 /^Target-Profile:\s*(.+)\s*$/ and do {
146 $1 =~ /^DEVICE_/ and $target->{has_devices} = 1;
147 push @{$target->{profiles}}, $profile;
149 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
150 /^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
151 $profile->{priority} = $1;
154 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
155 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
158 foreach my $target (@target) {
159 if (@{$target->{subtargets}} > 0) {
160 $target->{profiles} = [];
163 @{$target->{profiles}} > 0 or $target->{profiles} = [
171 $target->{sort} and @{$target->{profiles}} = sort {
172 $a->{priority} <=> $b->{priority} or
173 $a->{name} cmp $b->{name};
174 } @{$target->{profiles}};
179 sub clear_packages() {
190 sub parse_package_metadata($) {
196 my %ignore = map { $_ => 1 } @ignore;
198 open FILE, "<$file" or do {
199 warn "Cannot open '$file': $!\n";
204 /^Source-Makefile: \s*((?:package\/)?((?:.+\/)?([^\/]+))\/Makefile)\s*$/ and do {
209 ignore => $ignore{$3},
214 $srcpackage{$3} = $src;
218 /^Override: \s*(.+?)\s*$/ and do {
220 $overrides{$src->{name}} = 1;
223 /^Package:\s*(.+?)\s*$/ and do {
229 $pkg->{depends} = [];
230 $pkg->{mdepends} = [];
231 $pkg->{tristate} = 1;
232 $pkg->{override} = $override;
234 push @{$src->{packages}}, $pkg;
236 $vpackage{$1} or $vpackage{$1} = [];
237 unshift @{$vpackage{$1}}, $pkg;
239 /^Feature:\s*(.+?)\s*$/ and do {
242 $feature->{name} = $1;
243 $feature->{priority} = 0;
246 /^Target-Name:\s*(.+?)\s*$/ and do {
247 $features{$1} or $features{$1} = [];
248 push @{$features{$1}}, $feature unless $src->{ignore};
250 /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
251 /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
252 /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
253 /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
256 /^Build-Depends: \s*(.+)\s*$/ and $src->{builddepends} = [ split /\s+/, $1 ];
257 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $src->{"builddepends/$1"} = [ split /\s+/, $2 ];
258 /^Build-Types:\s*(.+)\s*$/ and $src->{buildtypes} = [ split /\s+/, $1 ];
260 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
261 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
262 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
263 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
264 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
265 /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
266 /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
267 /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
268 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
269 /^Provides: \s*(.+)\s*$/ and do {
270 my @vpkg = split /\s+/, $1;
271 foreach my $vpkg (@vpkg) {
272 $vpackage{$vpkg} or $vpackage{$vpkg} = [];
273 push @{$vpackage{$vpkg}}, $pkg;
276 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
277 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
278 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
279 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
280 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
281 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
282 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
283 /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
284 /^Category: \s*(.+)\s*$/ and do {
285 $pkg->{category} = $1;
286 defined $category{$1} or $category{$1} = {};
287 defined $category{$1}{$src->{name}} or $category{$1}{$src->{name}} = [];
288 push @{$category{$1}{$src->{name}}}, $pkg;
290 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
291 /^Type: \s*(.+)\s*$/ and do {
292 $pkg->{type} = [ split /\s+/, $1 ];
293 undef $pkg->{tristate};
294 foreach my $type (@{$pkg->{type}}) {
295 $type =~ /ipkg/ and $pkg->{tristate} = 1;
298 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
299 /^Prereq-Check:/ and $pkg->{prereq} = 1;
300 /^Require-User:\s*(.*?)\s*$/ and do {
301 my @ugspecs = split /\s+/, $1;
303 for my $ugspec (@ugspecs) {
304 my @ugspec = split /:/, $ugspec, 2;
305 parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
307 parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;