metadata.pm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package metadata;
  2. use base 'Exporter';
  3. use strict;
  4. use warnings;
  5. our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig clear_packages parse_package_metadata get_multiline);
  6. our %package;
  7. our %preconfig;
  8. our %srcpackage;
  9. our %category;
  10. our %subdir;
  11. sub get_multiline {
  12. my $fh = shift;
  13. my $prefix = shift;
  14. my $str;
  15. while (<$fh>) {
  16. last if /^@@/;
  17. s/^\s*//g;
  18. $str .= (($_ and $prefix) ? $prefix . $_ : $_);
  19. }
  20. return $str ? $str : "";
  21. }
  22. sub clear_packages() {
  23. %subdir = ();
  24. %preconfig = ();
  25. %package = ();
  26. %srcpackage = ();
  27. %category = ();
  28. }
  29. sub parse_package_metadata($) {
  30. my $file = shift;
  31. my $pkg;
  32. my $makefile;
  33. my $preconfig;
  34. my $subdir;
  35. my $src;
  36. open FILE, "<$file" or do {
  37. warn "Cannot open '$file': $!\n";
  38. return undef;
  39. };
  40. while (<FILE>) {
  41. chomp;
  42. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
  43. $makefile = $1;
  44. $subdir = $2;
  45. $src = $3;
  46. $subdir =~ s/^package\///;
  47. $subdir{$src} = $subdir;
  48. $srcpackage{$src} = [];
  49. undef $pkg;
  50. };
  51. next unless $src;
  52. /^Package:\s*(.+?)\s*$/ and do {
  53. $pkg = {};
  54. $pkg->{src} = $src;
  55. $pkg->{makefile} = $makefile;
  56. $pkg->{name} = $1;
  57. $pkg->{title} = "";
  58. $pkg->{default} = "m if ALL";
  59. $pkg->{depends} = [];
  60. $pkg->{builddepends} = [];
  61. $pkg->{buildtypes} = [];
  62. $pkg->{subdir} = $subdir;
  63. $pkg->{tristate} = 1;
  64. $package{$1} = $pkg;
  65. push @{$srcpackage{$src}}, $pkg;
  66. };
  67. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  68. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  69. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  70. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  71. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  72. /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
  73. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  74. /^Provides: \s*(.+)\s*$/ and do {
  75. my @vpkg = split /\s+/, $1;
  76. foreach my $vpkg (@vpkg) {
  77. $package{$vpkg} or $package{$vpkg} = {
  78. name => $vpkg,
  79. vdepends => [],
  80. src => $src,
  81. subdir => $subdir,
  82. makefile => $makefile
  83. };
  84. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  85. }
  86. };
  87. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  88. /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
  89. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  90. /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
  91. /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
  92. /^Category: \s*(.+)\s*$/ and do {
  93. $pkg->{category} = $1;
  94. defined $category{$1} or $category{$1} = {};
  95. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  96. push @{$category{$1}->{$src}}, $pkg;
  97. };
  98. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  99. /^Type: \s*(.+)\s*$/ and do {
  100. $pkg->{type} = [ split /\s+/, $1 ];
  101. undef $pkg->{tristate};
  102. foreach my $type (@{$pkg->{type}}) {
  103. $type =~ /ipkg/ and $pkg->{tristate} = 1;
  104. }
  105. };
  106. /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
  107. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  108. /^Preconfig:\s*(.+)\s*$/ and do {
  109. my $pkgname = $pkg->{name};
  110. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  111. if (exists $preconfig{$pkgname}->{$1}) {
  112. $preconfig = $preconfig{$pkgname}->{$1};
  113. } else {
  114. $preconfig = {
  115. id => $1
  116. };
  117. $preconfig{$pkgname}->{$1} = $preconfig;
  118. }
  119. };
  120. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  121. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  122. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  123. }
  124. close FILE;
  125. return 1;
  126. }
  127. 1;