build_perl_modules 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if (-e "Makefile.PL") {
  62. system("perl Makefile.PL PREFIX=$destdir INSTALLDIRS=site LIB=$destdir/lib") == 0
  63. or die "Can't run perl Makefile.PL";
  64. system("make") == 0 or die "Can't run make";
  65. } else {
  66. system("perl Build.PL --prefix $destdir --installdirs site --install_path lib=$destdir/lib") == 0
  67. or die "Can't run perl Build.PL";
  68. system("./Build") == 0 or die "Can't run ./Build";
  69. }
  70. chdir $topdir or die "Can't chdir to top";;
  71. }
  72. }
  73. chdir $dir or die "Can't chdir into $dir";
  74. # Need to add this so this module is found for subsequent ones
  75. my @dirs = split(":", $ENV{PERL5LIB} || "");
  76. unshift @dirs, "$topdir/$dir/blib/lib";
  77. $ENV{PERL5LIB}=join(":", @dirs);
  78. if ($opts->{t}) {
  79. if (-e "Makefile") {
  80. system("make test") == 0 or die "Can't run make test failed";
  81. } else {
  82. system("./Build test") == 0 or die "./Build test failed";
  83. }
  84. }
  85. if ($opts->{i}) {
  86. if (-e "Makefile") {
  87. system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install";
  88. } else {
  89. system("./Build install") == 0 or die "Can't run ./Build install";
  90. }
  91. }
  92. chdir $topdir or die "Can't go back to $topdir";
  93. }