Fiddle with Eigen+FFT tests and add nonsymmetric eigenvalue example
[Math-GSL.git] / Build.PL
blob5fa1cdf8c5934694513c53570b86ac150dfc8efe
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 ';
164 if ($Config{archname} =~ /x86_64/ ) {
165 $ldflags .= ' -fPIC -fno-omit-frame-pointer ';
166 $ccflags .= ' -fPIC -fno-omit-frame-pointer ';
168 my @Subsystems = sort qw/
169 BLAS Diff Machine Statistics
170 Eigen Matrix Poly Wavelet2D
171 BSpline Errno PowInt Wavelet
172 CBLAS FFT Min
173 CDF Fit QRNG
174 Chebyshev Monte RNG
175 Heapsort Multifit Randist Sum
176 Combination Histogram Multimin Roots
177 Complex Histogram2D Multiroots SF
178 Const Siman IEEEUtils Sys
179 Integration NTuple Sort
180 DHT Interp ODEIV Vector
181 Deriv Linalg Permutation Spline
184 # BSplines appeared in 1.9
185 if ($current_minor_version < 9 ) {
186 @Subsystems = grep { ! /BSpline/ } @Subsystems;
188 my $cleanup = qq{core *.core swig/*wrap.c swig/*.o Makefile Math-GSL-* tmp* pod2ht*.tmp _build lib/Math/GSL/[A-z]+/* blib *.so *.orig };
190 my $builder = GSLBuilder->new(
191 module_name => 'Math::GSL',
192 add_to_cleanup => [ $cleanup ],
193 create_makefile_pl => 'passthrough',
194 dist_abstract => 'Interface to the GNU Scientific Library using SWIG',
195 dist_author => 'Jonathan Leto <jonathan@leto.net>',
196 dist_version_from => 'lib/Math/GSL.pm',
197 include_dirs => q{},
198 extra_linker_flags => '-shared ' . $ldflags,
199 extra_compiler_flags=> $ccflags,
200 swig_flags => $swig_flags,
201 license => 'gpl',
202 requires => {
203 'ExtUtils::PkgConfig' => '1.03',
204 'Scalar::Util' => 0,
205 'Test::More' => 0,
206 'Test::Exception' => 0.21,
207 'Test::Class' => 0.12,
208 version => 0,
209 perl => '5.8.0',
211 sign => 0,
212 swig_source => [
213 map { [ "swig/$_.i" ] } @Subsystems ,
216 $builder->add_build_element('swig');
217 $builder->create_build_script();
218 print "Have a great day!\n";