build_perl_modules 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/perl
  2. # SYNTAX:
  3. # build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] tarball_dir
  4. #
  5. # DESCRIPTION:
  6. # Installs perl modules found in tarball_dir
  7. # Expects a file called install_order, containing one line per distribution name
  8. # Will take action against each distribution in turn
  9. # -d is a necessary destination directory for the perl mods
  10. # If -c is set, will remove the module build directories and exit
  11. # If -m is set, will run perl Makefile.PL and make
  12. # If -t is set, will run make test
  13. # If -i is set, will run make install
  14. # Options are discrete. This is because an overall ./configure, make, make test, make install
  15. # are run in different invocations. Obviously, you can't run a -t without a -m, but there's no
  16. # checking here for that
  17. # Can only use base modules
  18. use warnings;
  19. use strict;
  20. use Config;
  21. use Getopt::Std;
  22. use Cwd;
  23. use File::Path;
  24. my $opts = {};
  25. getopts('d:cmti', $opts) || die "Invalid options";
  26. my $moddir = shift @ARGV or die "Must specify a directory where tarballs exist";
  27. my $destdir = $opts->{d};
  28. die "Must set a destination directory" unless $destdir;
  29. chdir $moddir or die "Cannot change to $moddir";
  30. open F, "install_order" or die "Cannot open install_order file";
  31. my @files = grep { ! /^#/ && chop } <F>;
  32. close F;
  33. my @tarballs;
  34. foreach my $f (@files) {
  35. # Needs to be better. Also, what if there are two with same name?
  36. my $tarball;
  37. eval '$tarball = <'."$f".'*.tar.gz>';
  38. die unless ($tarball);
  39. print "Got $f, with file: $tarball",$/;
  40. push @tarballs, $tarball;
  41. (my $dir = $tarball) =~ s/\.tar.gz//;
  42. # Need to do cleaning before doing each module in turn
  43. if ($opts->{c}) {
  44. print "Cleaning $dir",$/;
  45. rmtree($dir);
  46. }
  47. }
  48. if ($opts->{c}) {
  49. print "Finished cleaning",$/;
  50. exit;
  51. }
  52. my $topdir = cwd();
  53. foreach my $tarball (@tarballs) {
  54. (my $dir = $tarball) =~ s/\.tar.gz//;
  55. if ($opts->{m}) {
  56. # Don't compile if already done - this is because of invocating this
  57. # script at different stages
  58. unless (-e $dir) {
  59. system("gunzip -c $tarball | tar -xf -") == 0 or die "Cannot extract $tarball";
  60. chdir $dir or die "Can't chdir into $dir";
  61. system("perl Makefile.PL PREFIX=$destdir INSTALLDIRS=site LIB=$destdir/lib") == 0 or die "Can't run perl Makefile.PL";
  62. system("make") == 0 or die "Can't run make";
  63. chdir $topdir or die "Can't chdir to top";;
  64. }
  65. }
  66. chdir $dir or die "Can't chdir into $dir";
  67. # Need to add this so this module is found for subsequent ones
  68. my @dirs = split(":", $ENV{PERL5LIB} || "");
  69. unshift @dirs, "$topdir/$dir/blib/lib";
  70. $ENV{PERL5LIB}=join(":", @dirs);
  71. if ($opts->{t}) {
  72. system("make test") == 0 or die "Can't run make test failed";
  73. }
  74. if ($opts->{i}) {
  75. system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install";
  76. }
  77. chdir $topdir or die "Can't go back to $topdir";
  78. }