brcm63xx: drop call to prepare_generic_squashfs
[openwrt.git] / scripts / metadata.pm
1 package metadata;
2 use base 'Exporter';
3 use strict;
4 use warnings;
5 our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features %overrides clear_packages parse_package_metadata get_multiline);
6
7 our %package;
8 our %preconfig;
9 our %srcpackage;
10 our %category;
11 our %subdir;
12 our %features;
13 our %overrides;
14
15 sub get_multiline {
16         my $fh = shift;
17         my $prefix = shift;
18         my $str;
19         while (<$fh>) {
20                 last if /^@@/;
21                 $str .= (($_ and $prefix) ? $prefix . $_ : $_);
22         }
23
24         return $str ? $str : "";
25 }
26
27 sub clear_packages() {
28         %subdir = ();
29         %preconfig = ();
30         %package = ();
31         %srcpackage = ();
32         %category = ();
33         %features = ();
34         %overrides = ();
35 }
36
37 sub parse_package_metadata($) {
38         my $file = shift;
39         my $pkg;
40         my $feature;
41         my $makefile;
42         my $preconfig;
43         my $subdir;
44         my $src;
45         my $override;
46
47         open FILE, "<$file" or do {
48                 warn "Cannot open '$file': $!\n";
49                 return undef;
50         };
51         while (<FILE>) {
52                 chomp;
53                 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
54                         $makefile = $1;
55                         $subdir = $2;
56                         $src = $3;
57                         $subdir =~ s/^package\///;
58                         $subdir{$src} = $subdir;
59                         $srcpackage{$src} = [];
60                         $override = "";
61                         undef $pkg;
62                 };
63                 /^Override: \s*(.+?)\s*$/ and do {
64                         $override = $1;
65                         $overrides{$src} = 1;
66                 };
67                 next unless $src;
68                 /^Package:\s*(.+?)\s*$/ and do {
69                         undef $feature;
70                         $pkg = {};
71                         $pkg->{src} = $src;
72                         $pkg->{makefile} = $makefile;
73                         $pkg->{name} = $1;
74                         $pkg->{title} = "";
75                         $pkg->{depends} = [];
76                         $pkg->{mdepends} = [];
77                         $pkg->{builddepends} = [];
78                         $pkg->{buildtypes} = [];
79                         $pkg->{subdir} = $subdir;
80                         $pkg->{tristate} = 1;
81                         $pkg->{override} = $override;
82                         $package{$1} = $pkg;
83                         push @{$srcpackage{$src}}, $pkg;
84                 };
85                 /^Feature:\s*(.+?)\s*$/ and do {
86                         undef $pkg;
87                         $feature = {};
88                         $feature->{name} = $1;
89                         $feature->{priority} = 0;
90                 };
91                 $feature and do {
92                         /^Target-Name:\s*(.+?)\s*$/ and do {
93                                 $features{$1} or $features{$1} = [];
94                                 push @{$features{$1}}, $feature;
95                         };
96                         /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
97                         /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
98                         /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
99                         /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
100                         next;
101                 };
102                 next unless $pkg;
103                 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
104                 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
105                 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
106                 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
107                 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
108                 /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
109                 /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
110                 /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
111                 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
112                 /^Provides: \s*(.+)\s*$/ and do {
113                         my @vpkg = split /\s+/, $1;
114                         foreach my $vpkg (@vpkg) {
115                                 $package{$vpkg} or $package{$vpkg} = {
116                                         name => $vpkg,
117                                         vdepends => [],
118                                         src => $src,
119                                         subdir => $subdir,
120                                         makefile => $makefile
121                                 };
122                                 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
123                         }
124                 };
125                 /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
126                 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
127                 /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
128                 /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
129                 /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
130                 /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
131                 /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
132                 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
133                 /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
134                 /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
135                 /^Feed:\s*(.+?)\s*$/ and $pkg->{feed} = $1;
136                 /^Category: \s*(.+)\s*$/ and do {
137                         $pkg->{category} = $1;
138                         defined $category{$1} or $category{$1} = {};
139                         defined $category{$1}->{$src} or $category{$1}->{$src} = [];
140                         push @{$category{$1}->{$src}}, $pkg;
141                 };
142                 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
143                 /^Type: \s*(.+)\s*$/ and do {
144                         $pkg->{type} = [ split /\s+/, $1 ];
145                         undef $pkg->{tristate};
146                         foreach my $type (@{$pkg->{type}}) {
147                                 $type =~ /ipkg/ and $pkg->{tristate} = 1;
148                         }
149                 };
150                 /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
151                 /^Prereq-Check:/ and $pkg->{prereq} = 1;
152                 /^Preconfig:\s*(.+)\s*$/ and do {
153                         my $pkgname = $pkg->{name};
154                         $preconfig{$pkgname} or $preconfig{$pkgname} = {};
155                         if (exists $preconfig{$pkgname}->{$1}) {
156                                 $preconfig = $preconfig{$pkgname}->{$1};
157                         } else {
158                                 $preconfig = {
159                                         id => $1
160                                 };
161                                 $preconfig{$pkgname}->{$1} = $preconfig;
162                         }
163                 };
164                 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
165                 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
166                 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
167         }
168         close FILE;
169         return 1;
170 }
171
172 1;