Build.PL 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. ExtUtils::MakeMaker 6.80
  9. ExtUtils::ParseXS 3.22
  10. ExtUtils::XSpp 0
  11. ExtUtils::Typemaps 0
  12. ExtUtils::Typemaps::Basic 0
  13. File::Basename 0
  14. File::Spec 0
  15. Getopt::Long 0
  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. );
  26. my %recommends = qw(
  27. Class::XSAccessor 0
  28. Test::Harness 0
  29. );
  30. my $sudo = grep { $_ eq '--sudo' } @ARGV;
  31. my $gui = grep { $_ eq '--gui' } @ARGV;
  32. my $nolocal = grep { $_ eq '--nolocal' } @ARGV;
  33. if ($gui) {
  34. %prereqs = qw(
  35. Class::Accessor 0
  36. Wx 0.9918
  37. );
  38. %recommends = qw(
  39. Wx::GLCanvas 0
  40. );
  41. if ($^O eq 'MSWin32') {
  42. $recommends{"Win32::TieRegistry"} = 0;
  43. # we need an up-to-date Win32::API because older aren't thread-safe (GH #2517)
  44. $prereqs{'Win32::API'} = 0.79;
  45. }
  46. }
  47. my @missing_prereqs = ();
  48. if ($ENV{SLIC3R_NO_AUTO}) {
  49. foreach my $module (sort keys %prereqs) {
  50. my $version = $prereqs{$module};
  51. next if eval "use $module $version; 1";
  52. push @missing_prereqs, $module if exists $prereqs{$module};
  53. print "Missing prerequisite $module $version\n";
  54. }
  55. foreach my $module (sort keys %recommends) {
  56. my $version = $recommends{$module};
  57. next if eval "use $module $version; 1";
  58. print "Missing optional $module $version\n";
  59. }
  60. } else {
  61. my @try = (
  62. $ENV{CPANM} // (),
  63. File::Spec->catfile($Config{sitebin}, 'cpanm'),
  64. File::Spec->catfile($Config{installscript}, 'cpanm'),
  65. );
  66. my $cpanm;
  67. foreach my $path (@try) {
  68. if (-e $path) { # don't use -x because it fails on Windows
  69. $cpanm = $path;
  70. last;
  71. }
  72. }
  73. if (!$cpanm) {
  74. if ($^O =~ /^(?:darwin|linux)$/ && system(qw(which cpanm)) == 0) {
  75. $cpanm = 'cpanm';
  76. }
  77. }
  78. die <<'EOF'
  79. cpanm was not found. Please install it before running this script.
  80. There are several ways to install cpanm, try one of these:
  81. apt-get install cpanminus
  82. curl -L http://cpanmin.us | perl - --sudo App::cpanminus
  83. cpan App::cpanminus
  84. If it is installed in a non-standard location you can do:
  85. CPANM=/path/to/cpanm perl Build.PL
  86. EOF
  87. if !$cpanm;
  88. my @cpanm_args = ();
  89. push @cpanm_args, "--sudo" if $sudo;
  90. # install local::lib without --local-lib otherwise it's not usable afterwards
  91. if (!eval "use local::lib qw(local-lib); 1") {
  92. my $res = system $cpanm, @cpanm_args, 'local::lib';
  93. warn "Warning: local::lib is required. You might need to run the `cpanm --sudo local::lib` command in order to install it.\n"
  94. if $res != 0;
  95. }
  96. push @cpanm_args, ('--local-lib', 'local-lib') if ! $nolocal;
  97. # make sure our cpanm is updated (old ones don't support the ~ syntax)
  98. system $cpanm, @cpanm_args, 'App::cpanminus';
  99. my %modules = (%prereqs, %recommends);
  100. foreach my $module (sort keys %modules) {
  101. my $version = $modules{$module};
  102. my @cmd = ($cpanm, @cpanm_args);
  103. # temporary workaround for upstream bug in test
  104. push @cmd, '--notest'
  105. if $module =~ /^(?:OpenGL|Test::Harness)$/;
  106. push @cmd, "$module~$version";
  107. my $res = system @cmd;
  108. if ($res != 0) {
  109. if (exists $prereqs{$module}) {
  110. push @missing_prereqs, $module;
  111. } else {
  112. printf "Don't worry, this module is optional.\n";
  113. }
  114. }
  115. }
  116. }
  117. print "\n";
  118. if ($gui) {
  119. print "Perl dependencies for the Slic3r GUI were installed.\n";
  120. } else {
  121. print "Perl dependencies for Slic3r were installed.\n";
  122. print "If you also want to use the GUI you can now run `perl Build.PL --gui` to install the required modules.\n";
  123. }
  124. print "\n";
  125. print "In the next step, you need to build the Slic3r C++ library.\n";
  126. print "1) Create a build directory and change to it\n";
  127. print "2) run cmake .. -DCMAKE_BUILD_TYPE=Release\n";
  128. print "3) run make\n";
  129. print "4) to execute the automatic tests, run ctest --verbose\n";
  130. __END__