Build.PL 5.0 KB

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