Build.PL 5.7 KB

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