5 our @EXPORT = qw(%package %srcpackage %category %preconfig %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($) {
197 my %ignore = map { $_ => 1 } @ignore;
199 open FILE, "<$file" or do {
200 warn "Cannot open '$file': $!\n";
205 /^Source-Makefile: \s*((?:package\/)?((?:.+\/)?([^\/]+))\/Makefile)\s*$/ and do {
210 ignore => $ignore{$3},
215 $srcpackage{$3} = $src;
219 /^Override: \s*(.+?)\s*$/ and do {
221 $overrides{$src->{name}} = 1;
224 /^Package:\s*(.+?)\s*$/ and do {
230 $pkg->{depends} = [];
231 $pkg->{mdepends} = [];
232 $pkg->{tristate} = 1;
233 $pkg->{override} = $override;
235 push @{$src->{packages}}, $pkg;
237 /^Feature:\s*(.+?)\s*$/ and do {
240 $feature->{name} = $1;
241 $feature->{priority} = 0;
244 /^Target-Name:\s*(.+?)\s*$/ and do {
245 $features{$1} or $features{$1} = [];
246 push @{$features{$1}}, $feature unless $src->{ignore};
248 /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
249 /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
250 /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
251 /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
254 /^Build-Depends: \s*(.+)\s*$/ and $src->{builddepends} = [ split /\s+/, $1 ];
255 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $src->{"builddepends/$1"} = [ split /\s+/, $2 ];
256 /^Build-Types:\s*(.+)\s*$/ and $src->{buildtypes} = [ split /\s+/, $1 ];
258 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
259 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
260 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
261 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
262 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
263 /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
264 /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
265 /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
266 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
267 /^Provides: \s*(.+)\s*$/ and do {
268 my @vpkg = split /\s+/, $1;
269 foreach my $vpkg (@vpkg) {
270 $package{$vpkg} or $package{$vpkg} = {
275 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
278 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
279 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
280 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
281 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
282 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
283 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
284 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
285 /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
286 /^Category: \s*(.+)\s*$/ and do {
287 $pkg->{category} = $1;
288 defined $category{$1} or $category{$1} = {};
289 defined $category{$1}{$src->{name}} or $category{$1}{$src->{name}} = [];
290 push @{$category{$1}{$src->{name}}}, $pkg;
292 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
293 /^Type: \s*(.+)\s*$/ and do {
294 $pkg->{type} = [ split /\s+/, $1 ];
295 undef $pkg->{tristate};
296 foreach my $type (@{$pkg->{type}}) {
297 $type =~ /ipkg/ and $pkg->{tristate} = 1;
300 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
301 /^Prereq-Check:/ and $pkg->{prereq} = 1;
302 /^Preconfig:\s*(.+)\s*$/ and do {
303 my $pkgname = $pkg->{name};
304 $preconfig{$pkgname} or $preconfig{$pkgname} = {};
305 if (exists $preconfig{$pkgname}->{$1}) {
306 $preconfig = $preconfig{$pkgname}->{$1};
311 $preconfig{$pkgname}{$1} = $preconfig unless $src->{ignore};
314 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
315 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
316 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
317 /^Require-User:\s*(.*?)\s*$/ and do {
318 my @ugspecs = split /\s+/, $1;
320 for my $ugspec (@ugspecs) {
321 my @ugspec = split /:/, $ugspec, 2;
322 parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
324 parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;