Build.PL 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Config;
  5. use File::Spec;
  6. my %prereqs = qw(
  7. Encode::Locale 0
  8. ExtUtils::MakeMaker 6.80
  9. ExtUtils::ParseXS 3.22
  10. File::Basename 0
  11. File::Spec 0
  12. Getopt::Long 0
  13. Math::PlanePath 53
  14. Module::Build::WithXSpp 0.14
  15. Moo 1.003001
  16. POSIX 0
  17. Scalar::Util 0
  18. Test::Harness 0
  19. Test::More 0
  20. Thread::Semaphore 0
  21. IO::Scalar 0
  22. Time::HiRes 0
  23. );
  24. my %recommends = qw(
  25. Class::XSAccessor 0
  26. XML::SAX::ExpatXS 0
  27. );
  28. my $sudo = grep { $_ eq '--sudo' } @ARGV;
  29. my $gui = grep { $_ eq '--gui' } @ARGV;
  30. my $xs_only = grep { $_ eq '--xs' } @ARGV;
  31. if ($gui) {
  32. %prereqs = qw(
  33. Wx 0.9918
  34. );
  35. %recommends = qw(
  36. Growl::GNTP 0.15
  37. Wx::GLCanvas 0
  38. OpenGL 0
  39. );
  40. } elsif ($xs_only) {
  41. %prereqs = %recommends = ();
  42. }
  43. my @missing_prereqs = ();
  44. if ($ENV{SLIC3R_NO_AUTO}) {
  45. foreach my $module (sort keys %prereqs) {
  46. my $version = $prereqs{$module};
  47. next if eval "use $module $version; 1";
  48. push @missing_prereqs, $module if exists $prereqs{$module};
  49. print "Missing prerequisite $module $version\n";
  50. }
  51. foreach my $module (sort keys %recommends) {
  52. my $version = $recommends{$module};
  53. next if eval "use $module $version; 1";
  54. print "Missing optional $module $version\n";
  55. }
  56. } else {
  57. my @try = (
  58. $ENV{CPANM} // (),
  59. File::Spec->catfile($Config{sitebin}, 'cpanm'),
  60. File::Spec->catfile($Config{installscript}, 'cpanm'),
  61. );
  62. my $cpanm;
  63. foreach my $path (@try) {
  64. if (-e $path) { # don't use -x because it fails on Windows
  65. $cpanm = $path;
  66. last;
  67. }
  68. }
  69. if (!$cpanm) {
  70. if ($^O =~ /^(?:darwin|linux)$/ && system(qw(which cpanm)) == 0) {
  71. $cpanm = 'cpanm';
  72. }
  73. }
  74. die <<'EOF'
  75. cpanm was not found. Please install it before running this script.
  76. There are several ways to install cpanm, try one of these:
  77. apt-get install cpanminus
  78. curl -L http://cpanmin.us | perl - --sudo App::cpanminus
  79. cpan App::cpanminus
  80. If it is installed in a non-standard location you can do:
  81. CPANM=/path/to/cpanm perl Build.PL
  82. EOF
  83. if !$cpanm;
  84. my @cpanm_args = ();
  85. push @cpanm_args, "--sudo" if $sudo;
  86. # make sure our cpanm is updated (old ones don't support the ~ syntax)
  87. system $cpanm, @cpanm_args, 'App::cpanminus';
  88. # install the Windows-compatible Math::Libm
  89. if ($^O eq 'MSWin32' && !eval "use Math::Libm; 1") {
  90. system $cpanm, @cpanm_args, 'https://github.com/alexrj/Math-Libm/tarball/master';
  91. }
  92. my %modules = (%prereqs, %recommends);
  93. foreach my $module (sort keys %modules) {
  94. my $version = $modules{$module};
  95. my @cmd = ($cpanm, @cpanm_args, "$module~$version");
  96. if ($module eq 'XML::SAX::ExpatXS' && $^O eq 'MSWin32') {
  97. my $mingw = 'C:\dev\CitrusPerl\mingw64';
  98. $mingw = 'C:\dev\CitrusPerl\mingw32' if !-d $mingw;
  99. if (!-d $mingw) {
  100. print "Could not find the MinGW directory at $mingw; skipping XML::SAX::ExpatXS (only needed for faster parsing of AMF files)\n";
  101. } else {
  102. push @cmd, sprintf('--configure-args="EXPATLIBPATH=%s\lib EXPATINCPATH=%s\include"', $mingw, $mingw);
  103. }
  104. }
  105. my $res = system @cmd;
  106. if ($res != 0) {
  107. if (exists $prereqs{$module}) {
  108. push @missing_prereqs, $module;
  109. } else {
  110. printf "Don't worry, this module is optional.\n";
  111. }
  112. }
  113. }
  114. if (!$gui) {
  115. # clean xs directory before reinstalling, to make sure Build is called
  116. # with current perl binary
  117. if (-e './xs/Build') {
  118. if ($^O eq 'MSWin32') {
  119. system '.\xs\Build', 'distclean';
  120. } else {
  121. system './xs/Build', 'distclean';
  122. }
  123. }
  124. my $res = system $cpanm, @cpanm_args, '--reinstall', '--verbose', './xs';
  125. if ($res != 0) {
  126. die "The XS/C++ code failed to compile, aborting\n";
  127. }
  128. }
  129. }
  130. if (@missing_prereqs) {
  131. printf "The following prerequisites failed to install: %s\n", join(', ', @missing_prereqs);
  132. exit 1;
  133. } elsif (!$gui) {
  134. eval "use App::Prove; 1" or die "Failed to load App::Prove";
  135. my $res = App::Prove->new->run ? 0 : 1;
  136. if ($res == 0) {
  137. print "If you also want to use the GUI you can now run `perl Build.PL --gui` to install the required modules.\n";
  138. } else {
  139. print "Some tests failed. Please report the failure to the author!\n";
  140. }
  141. exit $res;
  142. }
  143. __END__