2
0

metadata.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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->{default} = "m if ALL";
  58. $pkg->{depends} = [];
  59. $pkg->{builddepends} = [];
  60. $pkg->{subdir} = $subdir;
  61. $pkg->{tristate} = 1;
  62. $package{$1} = $pkg;
  63. push @{$srcpackage{$src}}, $pkg;
  64. };
  65. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  66. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  67. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  68. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  69. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  70. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  71. /^Provides: \s*(.+)\s*$/ and do {
  72. my @vpkg = split /\s+/, $1;
  73. foreach my $vpkg (@vpkg) {
  74. $package{$vpkg} or $package{$vpkg} = {
  75. name => $vpkg,
  76. vdepends => [],
  77. src => $src,
  78. subdir => $subdir,
  79. makefile => $makefile
  80. };
  81. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  82. }
  83. };
  84. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  85. /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
  86. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  87. /^Category: \s*(.+)\s*$/ and do {
  88. $pkg->{category} = $1;
  89. defined $category{$1} or $category{$1} = {};
  90. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  91. push @{$category{$1}->{$src}}, $pkg;
  92. };
  93. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  94. /^Type: \s*(.+)\s*$/ and do {
  95. $pkg->{type} = [ split /\s+/, $1 ];
  96. undef $pkg->{tristate};
  97. foreach my $type (@{$pkg->{type}}) {
  98. $type =~ /ipkg/ and $pkg->{tristate} = 1;
  99. }
  100. };
  101. /^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
  102. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  103. /^Preconfig:\s*(.+)\s*$/ and do {
  104. my $pkgname = $pkg->{name};
  105. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  106. if (exists $preconfig{$pkgname}->{$1}) {
  107. $preconfig = $preconfig{$pkgname}->{$1};
  108. } else {
  109. $preconfig = {
  110. id => $1
  111. };
  112. $preconfig{$pkgname}->{$1} = $preconfig;
  113. }
  114. };
  115. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  116. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  117. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  118. }
  119. close FILE;
  120. return 1;
  121. }
  122. 1;