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} = [];
219 /^Override: \s*(.+?)\s*$/ and do {
221 $overrides{$src} = 1;
224 /^Package:\s*(.+?)\s*$/ and do {
227 $pkg->{ignore} = $ignore{$src};
229 $pkg->{makefile} = $makefile;
232 $pkg->{depends} = [];
233 $pkg->{mdepends} = [];
234 $pkg->{builddepends} = [];
235 $pkg->{buildtypes} = [];
236 $pkg->{subdir} = $subdir;
237 $pkg->{tristate} = 1;
238 $pkg->{override} = $override;
240 push @{$srcpackage{$src}}, $pkg;
242 /^Feature:\s*(.+?)\s*$/ and do {
245 $feature->{name} = $1;
246 $feature->{priority} = 0;
249 /^Target-Name:\s*(.+?)\s*$/ and do {
250 $features{$1} or $features{$1} = [];
251 push @{$features{$1}}, $feature unless $ignore{$src};
253 /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
254 /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
255 /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
256 /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
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 $package{$vpkg} or $package{$vpkg} = {
277 makefile => $makefile
279 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
282 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
283 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
284 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
285 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
286 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
287 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
288 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
289 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
290 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
291 /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
292 /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
293 /^Category: \s*(.+)\s*$/ and do {
294 $pkg->{category} = $1;
295 defined $category{$1} or $category{$1} = {};
296 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
297 push @{$category{$1}->{$src}}, $pkg;
299 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
300 /^Type: \s*(.+)\s*$/ and do {
301 $pkg->{type} = [ split /\s+/, $1 ];
302 undef $pkg->{tristate};
303 foreach my $type (@{$pkg->{type}}) {
304 $type =~ /ipkg/ and $pkg->{tristate} = 1;
307 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
308 /^Prereq-Check:/ and $pkg->{prereq} = 1;
309 /^Preconfig:\s*(.+)\s*$/ and do {
310 my $pkgname = $pkg->{name};
311 $preconfig{$pkgname} or $preconfig{$pkgname} = {};
312 if (exists $preconfig{$pkgname}->{$1}) {
313 $preconfig = $preconfig{$pkgname}->{$1};
318 $preconfig{$pkgname}->{$1} = $preconfig unless $ignore{$src};
321 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
322 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
323 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
324 /^Require-User:\s*(.*?)\s*$/ and do {
325 my @ugspecs = split /\s+/, $1;
327 for my $ugspec (@ugspecs) {
328 my @ugspec = split /:/, $ugspec, 2;
329 parse_package_metadata_usergroup($makefile, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
331 parse_package_metadata_usergroup($makefile, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;