You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
3.9 KiB

  1. #!/bin/sh
  2. #
  3. # Generate perl base modules package definitions
  4. #
  5. # Copyright (C) 2007 Peter Colberg <peter@petercolberg.org>
  6. # Licensed under the terms of the GNU General Public License.
  7. #
  8. if [ $# -lt 1 ]; then
  9. echo >&2 "Usage: $(basename $0) STAGING-DIR [OUTFILE]"
  10. exit 1
  11. fi
  12. STAGING_DIR="$1"
  13. PERL_BIN="$STAGING_DIR/usr/bin/perl"
  14. PERL_LIB="$STAGING_DIR/usr/lib/perl5/5.10"
  15. INC_DIR="$(dirname $0)"
  16. shift
  17. "$PERL_BIN" -I"$INC_DIR" -I"$PERL_LIB" - "$PERL_LIB" "$@" <<'PERL_SCRIPT'
  18. use strict;
  19. use warnings;
  20. use Module::ScanDeps;
  21. use File::Find;
  22. use File::Basename;
  23. our $skipfiles = 'CORE vmsish.pm auto/sdbm';
  24. our %defmodules = (
  25. 'essential' => 'lib.pm vars.pm strict.pm warnings.pm warnings Carp Carp.pm Exporter Exporter.pm locale.pm subs.pm overload.pm constant.pm',
  26. 'getoptpl' => 'getopt.pl getopts.pl',
  27. 'utf8' => 'utf8_heavy.pl',
  28. 'Getopt' => 'newgetopt.pl',
  29. 'open' => 'open2.pl open3.pl',
  30. 'Config' => 'Config_heavy.pl',
  31. 'bytes' => 'bytes_heavy.pl',
  32. );
  33. our %defdepends = (
  34. 'DB_File' => 'libdb1-compat',
  35. 'GDBM_File' => 'libgdbm',
  36. );
  37. our $prefix = 'perlbase-';
  38. sub template ($) {
  39. $_ = $_[0];
  40. return <<TEMPLATE;
  41. define Package/$$_{package}
  42. SECTION:=lang
  43. CATEGORY:=Languages
  44. URL:=http://www.cpan.org/
  45. TITLE:=$$_{module} perl module
  46. DEPENDS:=$$_{depends}
  47. endef
  48. define Package/$$_{package}/install
  49. \$(call perlmod/Install,\$(1),$$_{files},$$_{exclude})
  50. endef
  51. \$(eval \$(call BuildPackage,$$_{package}))
  52. TEMPLATE
  53. }
  54. sub scandeps ($) {
  55. my $sitedir = shift;
  56. my @result;
  57. my ($mod, $file, @deps, $dep, %depends, $parent, $pkg);
  58. our (%files, %modules);
  59. my (%packages, %excludes);
  60. for $mod (keys %defmodules) {
  61. ($pkg = $prefix . $mod) =~ tr/A-Z_/a-z-/;
  62. $modules{$pkg} = $mod;
  63. for $file (split / /, $defmodules{$mod}) {
  64. $files{$file} = $pkg;
  65. }
  66. }
  67. for $file ('pod', 'Pod', split(/ /, $skipfiles)) {
  68. $files{$file} = undef;
  69. }
  70. sub wanted {
  71. s/^\.\///;
  72. return if (/^(\.|auto)$/ or exists $files{$_});
  73. if (/\.pod$/) {
  74. $files{$_} = undef;
  75. }
  76. elsif (exists $files{dirname($_)}) {
  77. $files{$_} = $files{dirname($_)};
  78. }
  79. elsif (m!^(?:auto/)?([^./]+)(?:\.(?:pl|pm)|/|$)!) {
  80. (my $pkg = $prefix . $1) =~ tr/A-Z_/a-z-/;
  81. $modules{$pkg} = $1;
  82. $files{$_} = $pkg;
  83. }
  84. else {
  85. $files{$_} = undef;
  86. }
  87. }
  88. chdir($sitedir);
  89. find({ wanted => \&wanted, no_chdir => 1}, '.');
  90. for $pkg (keys %modules) {
  91. $packages{$pkg} = [];
  92. $excludes{$pkg} = [];
  93. $depends{$pkg} = {};
  94. }
  95. for $file (keys %files) {
  96. $mod = $files{$file};
  97. $parent = $files{dirname($file)};
  98. if (defined ($mod)) {
  99. if (defined ($parent) and not ($parent eq $mod)) {
  100. push @{$packages{$mod}}, $file;
  101. push @{$excludes{$parent}}, $file;
  102. }
  103. elsif (not defined ($parent)) {
  104. push @{$packages{$mod}}, $file;
  105. }
  106. }
  107. elsif (defined ($parent)) {
  108. push @{$excludes{$parent}}, $file;
  109. }
  110. }
  111. for $mod (keys %defdepends) {
  112. ($pkg = $prefix . $mod) =~ tr/A-Z_/a-z-/;
  113. for $dep (split / /, $defdepends{$mod}) {
  114. ${$depends{$pkg}}{$dep} = 1;
  115. }
  116. }
  117. @INC = ('.');
  118. for $file (grep { -f $_ and defined $files{$_} } keys %files) {
  119. @deps = keys %{scan_deps(files => [ $file ], recurse => 0)};
  120. $pkg = $files{$file};
  121. for $dep (grep { not defined $files{$_} } @deps) {
  122. warn "$file: could not resolve dependency: $dep\n";
  123. }
  124. for $dep (grep { defined $files{$_} } @deps) {
  125. next if ($files{$dep} eq $pkg);
  126. ${$depends{$pkg}}{$files{$dep}} = 1;
  127. }
  128. }
  129. for $pkg (sort keys %packages) {
  130. push @result, template({
  131. package => $pkg,
  132. module => $modules{$pkg},
  133. depends => join(' ', 'perl', sort keys %{$depends{$pkg}}),
  134. files => join(' ', sort @{$packages{$pkg}}),
  135. exclude => join(' ', sort @{$excludes{$pkg}}),
  136. });
  137. }
  138. return join('', @result);
  139. }
  140. if (@ARGV > 1) {
  141. open FILE, ">$ARGV[1]" or die "$ARGV[1]: $!\n";
  142. print FILE scandeps($ARGV[0]);
  143. close FILE;
  144. }
  145. else {
  146. print scandeps($ARGV[0] or '.');
  147. }
  148. PERL_SCRIPT