<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package metadata;
use base 'Exporter';
use strict;
use warnings;
our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig clear_packages parse_package_metadata get_multiline);

our %package;
our %preconfig;
our %srcpackage;
our %category;
our %subdir;

sub get_multiline {
	my $fh = shift;
	my $prefix = shift;
	my $str;
	while (&lt;$fh&gt;) {
		last if /^@@/;
		$str .= (($_ and $prefix) ? $prefix . $_ : $_);
	}

	return $str ? $str : "";
}

sub clear_packages() {
	%subdir = ();
	%preconfig = ();
	%package = ();
	%srcpackage = ();
	%category = ();
}

sub parse_package_metadata($) {
	my $file = shift;
	my $pkg;
	my $makefile;
	my $preconfig;
	my $subdir;
	my $src;

	open FILE, "&lt;$file" or do {
		warn "Cannot open '$file': $!\n";
		return undef;
	};
	while (&lt;FILE&gt;) {
		chomp;
		/^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
			$makefile = $1;
			$subdir = $2;
			$src = $3;
			$subdir =~ s/^package\///;
			$subdir{$src} = $subdir;
			$srcpackage{$src} = [];
			undef $pkg;
		};
		next unless $src;
		/^Package:\s*(.+?)\s*$/ and do {
			$pkg = {};
			$pkg-&gt;{src} = $src;
			$pkg-&gt;{makefile} = $makefile;
			$pkg-&gt;{name} = $1;
			$pkg-&gt;{title} = "";
			$pkg-&gt;{default} = "m if ALL";
			$pkg-&gt;{depends} = [];
			$pkg-&gt;{builddepends} = [];
			$pkg-&gt;{buildtypes} = [];
			$pkg-&gt;{subdir} = $subdir;
			$pkg-&gt;{tristate} = 1;
			$package{$1} = $pkg;
			push @{$srcpackage{$src}}, $pkg;
		};
		/^Version: \s*(.+)\s*$/ and $pkg-&gt;{version} = $1;
		/^Title: \s*(.+)\s*$/ and $pkg-&gt;{title} = $1;
		/^Menu: \s*(.+)\s*$/ and $pkg-&gt;{menu} = $1;
		/^Submenu: \s*(.+)\s*$/ and $pkg-&gt;{submenu} = $1;
		/^Submenu-Depends: \s*(.+)\s*$/ and $pkg-&gt;{submenudep} = $1;
		/^Source: \s*(.+)\s*$/ and $pkg-&gt;{source} = $1;
		/^Default: \s*(.+)\s*$/ and $pkg-&gt;{default} = $1;
		/^Provides: \s*(.+)\s*$/ and do {
			my @vpkg = split /\s+/, $1;
			foreach my $vpkg (@vpkg) {
				$package{$vpkg} or $package{$vpkg} = {
					name =&gt; $vpkg,
					vdepends =&gt; [],
					src =&gt; $src,
					subdir =&gt; $subdir,
					makefile =&gt; $makefile
				};
				push @{$package{$vpkg}-&gt;{vdepends}}, $pkg-&gt;{name};
			}
		};
		/^Depends: \s*(.+)\s*$/ and $pkg-&gt;{depends} = [ split /\s+/, $1 ];
		/^Build-Only: \s*(.+)\s*$/ and $pkg-&gt;{buildonly} = 1;
		/^Build-Depends: \s*(.+)\s*$/ and $pkg-&gt;{builddepends} = [ split /\s+/, $1 ];
		/^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg-&gt;{"builddepends/$1"} = [ split /\s+/, $2 ];
		/^Build-Types:\s*(.+)\s*$/ and $pkg-&gt;{buildtypes} = [ split /\s+/, $1 ];
		/^Category: \s*(.+)\s*$/ and do {
			$pkg-&gt;{category} = $1;
			defined $category{$1} or $category{$1} = {};
			defined $category{$1}-&gt;{$src} or $category{$1}-&gt;{$src} = [];
			push @{$category{$1}-&gt;{$src}}, $pkg;
		};
		/^Description: \s*(.*)\s*$/ and $pkg-&gt;{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
		/^Type: \s*(.+)\s*$/ and do {
			$pkg-&gt;{type} = [ split /\s+/, $1 ];
			undef $pkg-&gt;{tristate};
			foreach my $type (@{$pkg-&gt;{type}}) {
				$type =~ /ipkg/ and $pkg-&gt;{tristate} = 1;
			}
		};
		/^Config:\s*(.*)\s*$/ and $pkg-&gt;{config} = "$1\n".get_multiline(*FILE, "\t");
		/^Prereq-Check:/ and $pkg-&gt;{prereq} = 1;
		/^Preconfig:\s*(.+)\s*$/ and do {
			my $pkgname = $pkg-&gt;{name};
			$preconfig{$pkgname} or $preconfig{$pkgname} = {};
			if (exists $preconfig{$pkgname}-&gt;{$1}) {
				$preconfig = $preconfig{$pkgname}-&gt;{$1};
			} else {
				$preconfig = {
					id =&gt; $1
				};
				$preconfig{$pkgname}-&gt;{$1} = $preconfig;
			}
		};
		/^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig-&gt;{type} = $1;
		/^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig-&gt;{label} = $1;
		/^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig-&gt;{default} = $1;
	}
	close FILE;
	return 1;
}

1;
</pre></body></html>