Overload subtraction in Vector
[Math-GSL.git] / Build.PL
blob8939ac8ca29c4b39bf49380ec03e036012e2f579
1 #!/usr/bin/perl -w
3 # This script has been heavily modified from the Device::Cdio Build.PL
4 # Jonathan Leto <jonathan@leto.net>
5 # Copyright (C) 2006 Rocky Bernstein <rocky@cpan.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use warnings;
22 use Config;
23 use Data::Dumper;
24 use Module::Build;
25 use lib 'inc';
26 use GSLBuilder;
28 BEGIN {
29 eval { require ExtUtils::PkgConfig };
30 if ($@) {
31 print "\nI see that you are a CPANTester, you really should install ExtUtils::PkgConfig !\n"
32 if $ENV{AUTOMATED_TESTING};
33 print <<EXIT;
34 ExtUtils::PkgConfig is currently needed to find GSL for the compilation of this module.
35 It may be bundled with Math::GSL in the future.
36 EXIT
37 exit 0;
43 sub try_compile {
44 my ($c, %args) = @_;
46 my $ok = 0;
47 my $tmp = "tmp$$";
48 local(*TMPC);
50 my $obj_ext = $Config{_o} || ".o";
51 unlink("$tmp.c", "$tmp$obj_ext");
53 if (open(TMPC, ">", "$tmp.c")) {
54 print TMPC $c;
55 close(TMPC);
57 my $cccmd = $args{cccmd};
58 my $errornull;
59 my $ccflags = $Config{'ccflags'};
60 $ccflags .= " $args{ccflags}" if $args{ccflags};
62 if ($args{silent} ) {
63 $errornull = "2>/dev/null" unless defined $errornull;
64 } else {
65 $errornull = '';
68 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c $errornull"
69 unless defined $cccmd;
71 printf "cccmd = $cccmd\n" if $args{verbose};
72 my $res = system($cccmd);
73 $ok = defined($res) && $res == 0;
75 if ( !$ok ) {
76 my $errno = $? >> 8;
77 local $! = $errno;
78 print "
80 *** The test compile of '$tmp.c' failed: status $?
81 *** (the status means: errno = $errno or '$!')
82 *** DO NOT PANIC: this just means that *some* you may get some innocuous
83 *** compiler warnings.
86 unlink("$tmp.c");
89 return $ok;
92 sub try_cflags ($) {
93 my ($ccflags) = @_;
94 my $c_prog = "int main () { return 0; }\n";
95 print "Checking if $Config{cc} supports \"$ccflags\"...";
96 my $result = try_compile($c_prog, ccflags=>$ccflags);
97 if ($result) {
98 print "yes\n";
99 return " $ccflags";
101 print "no\n";
102 return '';
106 print "Checking for GSL..";
107 my %gsl_pkgcfg = ExtUtils::PkgConfig->find ('gsl');
109 my $MIN_GSL_VERSION = "1.8";
110 my $gv = $gsl_pkgcfg{'modversion'};
111 my $current_minor_version;
113 if (defined $gv) {
114 if ($gv =~ m{\A(\d+(?:\.\d+)+)}) {
115 my @current= split /\./, $1;
116 my @min= split /\./, $MIN_GSL_VERSION;
117 $current_minor_version = $current[1];
118 unless ($current[0] >= $min[0] && $current[1] >= $min[1]) {
119 printf "
120 ***
121 *** You need to have GSL %s or greater installed. (You have $gv).
122 *** Get GSL at http://www.gnu.org/software/gsl\n", $MIN_GSL_VERSION;
123 exit 1;
124 } else {
125 print "Found GSL version $gv\n";
128 } else {
129 print "
130 ***
131 *** Can't parse GSL version $gv.
132 *** Will continue and keep my fingers crossed for luck.
135 } else {
136 print "
137 ***
138 *** Can't find GSL configuration info. Is GSL installed?
139 *** Get GSL at http://www.gnu.org/software/gsl
141 exit 1;
145 my $ccflags = $gsl_pkgcfg{cflags};
147 ## Swig produces a number of GCC warnings. Turn them off if we can.
148 $ccflags .= try_cflags("-Wno-strict-aliasing");
149 $ccflags .= try_cflags("-Wno-unused-function");
150 $ccflags .= try_cflags("-Wno-unused-value");
151 $ccflags .= try_cflags("-Wno-unused-function");
152 $ccflags .= try_cflags("-Wno-unused-variable");
154 my $ldflags = "$gsl_pkgcfg{libs} -gsl";
155 my $swig_flags = "$gsl_pkgcfg{cflags}"; # -Wall is a bit much
157 if ( $^O eq 'cygwin' && $Config{shrpenv} =~ m{\Aenv LD_RUN_PATH=(.*)\Z} ) {
158 $ldflags .= " -L$1 -lperl";
159 # Should we check the 32-ness?
160 $swig_flags = '-DNEED_LONG';
161 } elsif ( $^O eq 'darwin' ) {
162 $ldflags .= ' -bundle -flat_namespace ';
163 } elsif ($Config{archname} =~ /x86_64/ ) {
164 $ldflags .= ' -fPIC ';
165 $ccflags .= ' -fPIC ';
167 my @Subsystems = sort qw/
168 BLAS Diff Machine Statistics
169 Eigen Matrix Poly Wavelet2D
170 BSpline Errno PowInt Wavelet
171 CBLAS FFT Min
172 CDF Fit QRNG
173 Chebyshev Monte RNG
174 Heapsort Multifit Randist Sum
175 Combination Histogram Multimin Roots
176 Complex Histogram2D Multiroots SF
177 Const Siman IEEEUtils Sys
178 Integration NTuple Sort
179 DHT Interp ODEIV Vector
180 Deriv Linalg Permutation Spline
183 # BSplines appeared in 1.9
184 if ($current_minor_version < 9 ) {
185 @Subsystems = grep { ! /BSpline/ } @Subsystems;
187 my $cleanup = qq{core *.core Makefile Math-GSL-* tmp* pod2ht*.tmp _build blib *.so *.orig };
189 my $builder = GSLBuilder->new(
190 module_name => 'Math::GSL',
191 add_to_cleanup => [ $cleanup ],
192 create_makefile_pl => 'passthrough',
193 dist_abstract => 'Interface to the GNU Scientific Library using SWIG',
194 dist_author => 'Jonathan Leto <jonathan@leto.net>',
195 dist_version_from => 'lib/Math/GSL.pm',
196 include_dirs => q{},
197 extra_linker_flags => '-shared ' . $ldflags,
198 extra_compiler_flags=> $ccflags,
199 swig_flags => $swig_flags,
200 license => 'gpl',
201 requires => {
202 'ExtUtils::PkgConfig' => '1.03',
203 'Scalar::Util' => 0,
204 'Test::More' => 0,
205 'Test::Exception' => 0.21,
206 'Test::Class' => 0.12,
207 version => 0,
208 perl => '5.8.0',
210 sign => 0,
211 swig_source => [
212 map { [ "$_.i" ] } @Subsystems
215 $builder->add_build_element('swig');
216 $builder->create_build_script();
217 print "Have a great day!\n";