Build.PL 4.9 KB

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