Build.PL 4.8 KB

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