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.

81 lines
1.8 KiB

  1. #!/bin/sh
  2. #
  3. # Generate perl module package dependencies
  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 3 ]; then
  9. echo >&2 "Usage: $(basename $0) STAGING-DIR PERL-BUILD-DIR [FILES...] [DIRECTORIES...]"
  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_SCRIPT'
  18. use strict;
  19. use warnings;
  20. use Module::ScanDeps;
  21. use File::Find;
  22. use Cwd;
  23. our $sitelib = "/usr/lib/perl5/5.10";
  24. sub scandeps {
  25. my $builddir = Cwd::abs_path(shift);
  26. my @scanpaths = @_;
  27. my ($curdir, @pkgdirs, $dir, @deps, %depends, $file);
  28. our ($pkg, %bundles, $path, @files);
  29. @pkgdirs = glob($builddir . "/*/ipkg");
  30. $curdir = getcwd();
  31. @INC = ();
  32. for $dir (@pkgdirs) {
  33. chdir($dir) or die "$dir: $!";
  34. for $pkg (glob("*")) {
  35. chdir($dir . "/" . $pkg . $sitelib) or next;
  36. push @INC, getcwd();
  37. sub wanted {
  38. return unless (-f $_);
  39. s/^\.\///;
  40. $bundles{$_} = $pkg;
  41. }
  42. find({ wanted => \&wanted, no_chdir => 1 }, ".");
  43. }
  44. }
  45. chdir($curdir) or die "$curdir: $!\n";
  46. for $path (@scanpaths) {
  47. sub scan_wanted {
  48. return unless (-f $_ and /\.(pl|pm)$/);
  49. push @files, $_;
  50. }
  51. if (-f $path) {
  52. push @files, $path;
  53. }
  54. elsif (-d $path) {
  55. find({ wanted => \&scan_wanted, no_chdir => 1 }, $path);
  56. }
  57. }
  58. @deps = keys %{scan_deps(files => \@files, recurse => 0)};
  59. for $file (grep { not exists $bundles{$_} } @deps) {
  60. warn "could not resolve dependency: $file\n";
  61. }
  62. %depends = map { $bundles{$_}, 1 } grep { exists $bundles{$_} } @deps;
  63. if (%depends) {
  64. print join(' ', 'perl', sort keys %depends), "\n";
  65. }
  66. }
  67. if (@ARGV > 1) {
  68. scandeps(@ARGV);
  69. }
  70. PERL_SCRIPT