5 our @EXPORT = qw(%package %vpackage %srcpackage %category %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
25 $str .= (($_ and $prefix) ? $prefix . $_ : $_);
28 return $str ? $str : "";
33 $conf =~ tr#/\.\-/#___#;
37 sub parse_package_metadata_usergroup($$$$$) {
46 # the regex for name is taken from is_valid_name() of package shadow
47 if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
50 } elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
54 warn "$makefile: invalid $typename spec $spec\n";
58 if ($id =~ /^[1-9]\d*$/) {
60 warn "$makefile: $typename $name id $id >= 65536";
63 if (not exists $ids->{$id}) {
66 makefile => $makefile,
68 } elsif ($ids->{$id}{name} ne $name) {
69 warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
73 warn "$makefile: $typename $name has invalid id $id\n";
77 if (not exists $names->{$name}) {
80 makefile => $makefile,
82 } elsif ($names->{$name}{id} != $id) {
83 warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
89 sub parse_target_metadata($) {
91 my ($target, @target, $profile);
95 open FILE, "<$file" or do {
96 warn "Can't open file '$file': $!\n";
101 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and $makefile = $1;
102 /^Target:\s*(.+)\s*$/ and do {
107 makefile => $makefile,
108 boardconf => confstr($name),
109 conf => confstr($name),
115 push @target, $target;
116 $target{$name} = $target;
117 if ($name =~ /([^\/]+)\/([^\/]+)/) {
118 push @{$target{$1}->{subtargets}}, $2;
119 $target->{board} = $1;
120 $target->{boardconf} = confstr($1);
121 $target->{subtarget} = 1;
122 $target->{parent} = $target{$1};
125 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
126 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
127 /^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1;
128 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
129 /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
130 /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
131 /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
132 /^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
133 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
134 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
135 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
136 /^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
137 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
138 /^Target-Profile:\s*(.+)\s*$/ and do {
142 has_image_metadata => 0,
143 supported_devices => [],
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-hasImageMetadata:\s*(\d+)\s*$/ and $profile->{has_image_metadata} = $1;
152 /^Target-Profile-SupportedDevices:\s*(.+)\s*$/ and $profile->{supported_devices} = [ split(/\s+/, $1) ];
153 /^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
154 $profile->{priority} = $1;
157 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
158 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
161 foreach my $target (@target) {
162 if (@{$target->{subtargets}} > 0) {
163 $target->{profiles} = [];
166 @{$target->{profiles}} > 0 or $target->{profiles} = [
174 $target->{sort} and @{$target->{profiles}} = sort {
175 $a->{priority} <=> $b->{priority} or
176 $a->{name} cmp $b->{name};
177 } @{$target->{profiles}};
182 sub clear_packages() {
192 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 {
229 $pkg->{depends} = [];
230 $pkg->{mdepends} = [];
231 $pkg->{provides} = [$1];
232 $pkg->{tristate} = 1;
233 $pkg->{override} = $override;
235 push @{$src->{packages}}, $pkg;
237 $vpackage{$1} or $vpackage{$1} = [];
238 unshift @{$vpackage{$1}}, $pkg;
240 /^Build-Depends: \s*(.+)\s*$/ and $src->{builddepends} = [ split /\s+/, $1 ];
241 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $src->{"builddepends/$1"} = [ split /\s+/, $2 ];
242 /^Build-Types:\s*(.+)\s*$/ and $src->{buildtypes} = [ split /\s+/, $1 ];
244 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
245 /^ABIVersion: \s*(.+)\s*$/ and $pkg->{abiversion} = $1;
246 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
247 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
248 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
249 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
250 /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
251 /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
252 /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
253 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
254 /^Provides: \s*(.+)\s*$/ and do {
255 my @vpkg = split /\s+/, $1;
256 @{$pkg->{provides}} = ($pkg->{name}, @vpkg);
257 foreach my $vpkg (@vpkg) {
258 next if ($vpkg eq $pkg->{name});
259 $vpackage{$vpkg} or $vpackage{$vpkg} = [];
260 push @{$vpackage{$vpkg}}, $pkg;
263 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
264 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
265 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
266 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
267 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
268 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
269 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
270 /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
271 /^Category: \s*(.+)\s*$/ and do {
272 $pkg->{category} = $1;
273 defined $category{$1} or $category{$1} = {};
274 defined $category{$1}{$src->{name}} or $category{$1}{$src->{name}} = [];
275 push @{$category{$1}{$src->{name}}}, $pkg;
277 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
278 /^Type: \s*(.+)\s*$/ and do {
279 $pkg->{type} = [ split /\s+/, $1 ];
280 undef $pkg->{tristate};
281 foreach my $type (@{$pkg->{type}}) {
282 $type =~ /ipkg/ and $pkg->{tristate} = 1;
285 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
286 /^Prereq-Check:/ and $pkg->{prereq} = 1;
287 /^Require-User:\s*(.*?)\s*$/ and do {
288 my @ugspecs = split /\s+/, $1;
290 for my $ugspec (@ugspecs) {
291 my @ugspec = split /:/, $ugspec, 2;
293 parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
296 parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;