5 our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
27 $str .= (($_ and $prefix) ? $prefix . $_ : $_);
30 return $str ? $str : "";
35 $conf =~ tr#/\.\-/#___#;
39 sub parse_package_metadata_usergroup($$$$$) {
48 # the regex for name is taken from is_valid_name() of package shadow
49 if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
52 } elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
56 warn "$makefile: invalid $typename spec $spec\n";
60 if ($id =~ /^[1-9]\d*$/) {
62 warn "$makefile: $typename $name id $id >= 65536";
65 if (not exists $ids->{$id}) {
68 makefile => $makefile,
70 } elsif ($ids->{$id}{name} ne $name) {
71 warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
75 warn "$makefile: $typename $name has invalid id $id\n";
79 if (not exists $names->{$name}) {
82 makefile => $makefile,
84 } elsif ($names->{$name}{id} != $id) {
85 warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
91 sub parse_target_metadata($) {
93 my ($target, @target, $profile);
97 open FILE, "<$file" or do {
98 warn "Can't open file '$file': $!\n";
103 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and $makefile = $1;
104 /^Target:\s*(.+)\s*$/ and do {
109 makefile => $makefile,
110 boardconf => confstr($name),
111 conf => confstr($name),
117 push @target, $target;
118 $target{$name} = $target;
119 if ($name =~ /([^\/]+)\/([^\/]+)/) {
120 push @{$target{$1}->{subtargets}}, $2;
121 $target->{board} = $1;
122 $target->{boardconf} = confstr($1);
123 $target->{subtarget} = 1;
124 $target->{parent} = $target{$1};
127 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
128 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
129 /^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1;
130 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
131 /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
132 /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
133 /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
134 /^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
135 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
136 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
137 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
138 /^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
139 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
140 /^Target-Profile:\s*(.+)\s*$/ and do {
147 $1 =~ /^DEVICE_/ and $target->{has_devices} = 1;
148 push @{$target->{profiles}}, $profile;
150 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
151 /^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
152 $profile->{priority} = $1;
155 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
156 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
159 foreach my $target (@target) {
160 if (@{$target->{subtargets}} > 0) {
161 $target->{profiles} = [];
164 @{$target->{profiles}} > 0 or $target->{profiles} = [
172 $target->{sort} and @{$target->{profiles}} = sort {
173 $a->{priority} <=> $b->{priority} or
174 $a->{name} cmp $b->{name};
175 } @{$target->{profiles}};
180 sub clear_packages() {
192 sub parse_package_metadata($) {
201 my %ignore = map { $_ => 1 } @ignore;
203 open FILE, "<$file" or do {
204 warn "Cannot open '$file': $!\n";
209 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
213 $subdir =~ s/^package\///;
214 $subdir{$src} = $subdir;
215 $srcpackage{$src} = {
221 /^Override: \s*(.+?)\s*$/ and do {
223 $overrides{$src} = 1;
226 /^Package:\s*(.+?)\s*$/ and do {
229 $pkg->{ignore} = $ignore{$src};
231 $pkg->{makefile} = $makefile;
234 $pkg->{depends} = [];
235 $pkg->{mdepends} = [];
236 $pkg->{builddepends} = [];
237 $pkg->{buildtypes} = [];
238 $pkg->{subdir} = $subdir;
239 $pkg->{tristate} = 1;
240 $pkg->{override} = $override;
242 push @{$srcpackage{$src}{packages}}, $pkg;
244 /^Feature:\s*(.+?)\s*$/ and do {
247 $feature->{name} = $1;
248 $feature->{priority} = 0;
251 /^Target-Name:\s*(.+?)\s*$/ and do {
252 $features{$1} or $features{$1} = [];
253 push @{$features{$1}}, $feature unless $ignore{$src};
255 /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
256 /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
257 /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
258 /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
262 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
263 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
264 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
265 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
266 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
267 /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
268 /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
269 /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
270 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
271 /^Provides: \s*(.+)\s*$/ and do {
272 my @vpkg = split /\s+/, $1;
273 foreach my $vpkg (@vpkg) {
274 $package{$vpkg} or $package{$vpkg} = {
279 makefile => $makefile
281 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
284 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
285 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
286 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
287 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
288 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
289 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
290 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
291 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
292 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
293 /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
294 /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
295 /^Category: \s*(.+)\s*$/ and do {
296 $pkg->{category} = $1;
297 defined $category{$1} or $category{$1} = {};
298 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
299 push @{$category{$1}->{$src}}, $pkg;
301 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
302 /^Type: \s*(.+)\s*$/ and do {
303 $pkg->{type} = [ split /\s+/, $1 ];
304 undef $pkg->{tristate};
305 foreach my $type (@{$pkg->{type}}) {
306 $type =~ /ipkg/ and $pkg->{tristate} = 1;
309 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
310 /^Prereq-Check:/ and $pkg->{prereq} = 1;
311 /^Preconfig:\s*(.+)\s*$/ and do {
312 my $pkgname = $pkg->{name};
313 $preconfig{$pkgname} or $preconfig{$pkgname} = {};
314 if (exists $preconfig{$pkgname}->{$1}) {
315 $preconfig = $preconfig{$pkgname}->{$1};
320 $preconfig{$pkgname}->{$1} = $preconfig unless $ignore{$src};
323 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
324 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
325 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
326 /^Require-User:\s*(.*?)\s*$/ and do {
327 my @ugspecs = split /\s+/, $1;
329 for my $ugspec (@ugspecs) {
330 my @ugspec = split /:/, $ugspec, 2;
331 parse_package_metadata_usergroup($makefile, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
333 parse_package_metadata_usergroup($makefile, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;