Add number of tests to various test files
[Math-GSL.git] / Build.PL
blob0680605d5790304e86f8903a000e94c009b57834
1 #!/usr/bin/perl -w
2 # This has been heavily modified from the Device::Cdio Build.PL
3 # 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 Math::GSL;
27 use GSLBuilder;
28 use File::Spec::Functions qw/:ALL/;
30 BEGIN {
31 eval { require ExtUtils::PkgConfig };
32 if ($@) {
33 print "\nI see that you are a CPANTester, you really should install ExtUtils::PkgConfig !\n"
34 if $ENV{AUTOMATED_TESTING};
35 print <<EXIT;
36 ExtUtils::PkgConfig is currently needed to find GSL for the compilation of this module.
37 It may be bundled with Math::GSL in the future.
38 EXIT
39 exit 0;
45 sub try_compile {
46 my ($c, %args) = @_;
48 my $ok = 0;
49 my $tmp = "tmp$$";
50 local(*TMPC);
52 my $obj_ext = $Config{_o} || ".o";
53 unlink("$tmp.c", "$tmp$obj_ext");
55 if (open(TMPC, ">", "$tmp.c")) {
56 print TMPC $c;
57 close(TMPC);
59 my $cccmd = $args{cccmd};
60 my $errornull;
61 my $ccflags = $Config{'ccflags'};
62 $ccflags .= " $args{ccflags}" if $args{ccflags};
64 if ($args{silent} ) {
65 $errornull = "2>/dev/null" unless defined $errornull;
66 } else {
67 $errornull = '';
70 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c $errornull"
71 unless defined $cccmd;
73 printf "cccmd = $cccmd\n" if $args{verbose};
74 my $res = system($cccmd);
75 $ok = defined($res) && $res == 0;
77 if ( !$ok ) {
78 my $errno = $? >> 8;
79 local $! = $errno;
80 print "
82 *** The test compile of '$tmp.c' failed: status $?
83 *** (the status means: errno = $errno or '$!')
84 *** DO NOT PANIC: this just means that *some* you may get some innocuous
85 *** compiler warnings.
88 unlink("$tmp.c");
91 return $ok;
94 sub try_cflags ($) {
95 my ($ccflags) = @_;
96 my $c_prog = "int main () { return 0; }\n";
97 print "Checking if $Config{cc} supports \"$ccflags\"...";
98 my $result = try_compile($c_prog, ccflags=>$ccflags);
99 if ($result) {
100 print "yes\n";
101 return " $ccflags";
103 print "no\n";
104 return '';
108 print "Checking for GSL..";
109 my %gsl_pkgcfg = ExtUtils::PkgConfig->find ('gsl');
111 my $MIN_GSL_VERSION = "1.8";
112 my $gv = $gsl_pkgcfg{'modversion'};
113 my $current_minor_version;
115 if (defined $gv) {
116 if ($gv =~ m{\A(\d+(?:\.\d+)+)}) {
117 my @current= split /\./, $1;
118 my @min= split /\./, $MIN_GSL_VERSION;
119 $current_minor_version = $current[1];
120 unless ($current[0] >= $min[0] && $current[1] >= $min[1]) {
121 printf "
122 ***
123 *** You need to have GSL %s or greater installed. (You have $gv).
124 *** Get GSL at http://www.gnu.org/software/gsl\n", $MIN_GSL_VERSION;
125 exit 1;
126 } else {
127 print "Found GSL version $gv\n";
130 } else {
131 print "
132 ***
133 *** Can't parse GSL version $gv.
134 *** Will continue and keep my fingers crossed for luck.
137 } else {
138 print "
139 ***
140 *** Can't find GSL configuration info. Is GSL installed?
141 *** Get GSL at http://www.gnu.org/software/gsl
143 exit 1;
147 my $ccflags = $gsl_pkgcfg{cflags};
149 ## Swig produces a number of GCC warnings. Turn them off if we can.
150 $ccflags .= try_cflags("-Wno-strict-aliasing");
151 $ccflags .= try_cflags("-Wno-unused-function");
152 $ccflags .= try_cflags("-Wno-unused-value");
153 $ccflags .= try_cflags("-Wno-unused-function");
154 $ccflags .= try_cflags("-Wno-unused-variable");
156 my $ldflags = "$gsl_pkgcfg{libs} -gsl";
157 my $swig_flags = "$gsl_pkgcfg{cflags}"; # -Wall is a bit much
159 if ( $^O eq 'cygwin' && $Config{shrpenv} =~ m{\Aenv LD_RUN_PATH=(.*)\Z} ) {
160 $ldflags .= " -L$1 -lperl";
161 # Should we check the 32-ness?
162 $swig_flags = '-DNEED_LONG';
163 } elsif ( $^O eq 'darwin' ) {
164 $ldflags .= ' -bundle -flat_namespace ';
166 if ($Config{archname} =~ /x86_64/ ) {
167 $ldflags .= ' -fPIC -fno-omit-frame-pointer ';
168 $ccflags .= ' -fPIC -fno-omit-frame-pointer ';
171 my @Subsystems = grep { ! /^Test$/ } Math::GSL::subsystems;
173 # BSplines appeared in 1.9
174 if ($current_minor_version < 9 ) {
175 @Subsystems = grep { ! /BSpline/ } @Subsystems;
177 my $cleanup = qq{
178 xs/*_wrap.c core *.core swig/*wrap.c
179 swig/*.o Makefile Math-GSL-* tmp* pod2ht*.tmp _build
180 lib/Math/GSL/[A-z]+/* blib *.so *.orig
181 } . join " ", map { catfile( (qw( lib Math GSL ), "$_.pm") ) } @Subsystems;
183 my $builder = GSLBuilder->new(
184 module_name => 'Math::GSL',
185 add_to_cleanup => [ $cleanup ],
186 create_makefile_pl => 'passthrough',
187 dist_abstract => 'Interface to the GNU Scientific Library using SWIG',
188 dist_author => 'Jonathan Leto <jonathan@leto.net>',
189 dist_version_from => 'lib/Math/GSL.pm',
190 include_dirs => q{},
191 extra_linker_flags => '-shared ' . $ldflags,
192 extra_compiler_flags=> $ccflags,
193 swig_flags => $swig_flags,
194 license => 'gpl',
195 requires => {
196 'ExtUtils::PkgConfig' => '1.03',
197 'Scalar::Util' => 0,
198 'Test::More' => 0,
199 'Test::Exception' => 0.21,
200 'Test::Class' => 0.12,
201 version => 0,
202 perl => '5.8.0',
204 sign => 0,
205 swig_source => [
206 map { [ "swig/$_.i", "pod/$_.pod" ] } @Subsystems ,
209 $builder->add_build_element('swig');
210 $builder->create_build_script();
211 print "Have a great day!\n";