~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to Build.PL

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

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