POD for Math::GSL::Test
[Math-GSL.git] / Build.PL
blobb271b2839eb3e568b8a7b7965397fa8a57ad6caa
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= "-Wall $gsl_pkgcfg{cflags}";
157 if ('cygwin' eq $Config{osname} &&
158 $Config{shrpenv} =~ m{\Aenv LD_RUN_PATH=(.*)\Z} ) {
159 $ldflags .= " -L$1 -lperl";
160 # Should we check the 32-ness?
161 $swig_flags = '-DNEED_LONG';
162 } elsif ('darwin' eq $Config{osname}) {
163 $ldflags .= " -bundle -flat_namespace";
165 my @Subsystems = sort qw/
166 BLAS Diff Machine Statistics
167 Eigen Matrix Poly Wavelet2D
168 BSpline Errno PowInt Wavelet
169 CBLAS FFT Min
170 CDF Fit QRNG
171 Chebyshev Monte RNG
172 Heapsort Multifit Randist Sum
173 Combination Histogram Multimin Roots
174 Complex Histogram2D Multiroots SF
175 Const Siman IEEEUtils Sys
176 Integration NTuple Sort
177 DHT Interp ODEIV Vector
178 Deriv Linalg Permutation Spline
181 # BSplines appeared in 1.9
182 if ($current_minor_version < 9 ) {
183 @Subsystems = grep { ! /BSpline/ } @Subsystems;
185 my $cleanup = qq{core *.core Makefile Math-GSL-* tmp* pod2ht*.tmp _build blib *.so *.orig };
187 my $builder = GSLBuilder->new(
188 module_name => 'Math::GSL',
189 add_to_cleanup => [ $cleanup ],
190 create_makefile_pl => 'passthrough',
191 dist_abstract => 'Interface to the GNU Scientific Library using SWIG',
192 dist_author => 'Jonathan Leto <jonathan@leto.net>',
193 dist_version_from => 'lib/Math/GSL.pm',
194 include_dirs => q{},
195 extra_linker_flags => '-shared ' . $ldflags,
196 extra_compiler_flags=> $ccflags,
197 swig_flags => $swig_flags,
198 license => 'gpl',
199 requires => {
200 'ExtUtils::PkgConfig' => '1.03',
201 'Scalar::Util' => 0,
202 'Test::More' => 0,
203 'Test::Exception' => 0.21,
204 'Test::Class' => 0.12,
205 version => 0,
206 perl => '5.8.0',
208 sign => 0,
209 swig_source => [
210 map { [ "$_.i" ] } @Subsystems
213 $builder->add_build_element('swig');
214 $builder->create_build_script();
215 print "Have a great day!\n";