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
27 use File
::Spec
::Functions qw
/:ALL/;
30 eval { require ExtUtils
::PkgConfig
};
32 print "\nI see that you are a CPANTester, you really should install ExtUtils::PkgConfig !\n"
33 if $ENV{AUTOMATED_TESTING
};
35 ExtUtils::PkgConfig is currently needed to find GSL for the compilation of this module.
36 It may be bundled with Math::GSL in the future.
51 my $obj_ext = $Config{_o
} || ".o";
52 unlink("$tmp.c", "$tmp$obj_ext");
54 if (open(TMPC
, ">", "$tmp.c")) {
58 my $cccmd = $args{cccmd
};
60 my $ccflags = $Config{'ccflags'};
61 $ccflags .= " $args{ccflags}" if $args{ccflags
};
64 $errornull = "2>/dev/null" unless defined $errornull;
69 $cccmd = "$Config{'cc'} -o $tmp $ccflags $tmp.c $errornull"
70 unless defined $cccmd;
72 printf "cccmd = $cccmd\n" if $args{verbose
};
73 my $res = system($cccmd);
74 $ok = defined($res) && $res == 0;
81 *** The test compile of '$tmp.c' failed: status $?
82 *** (the status means: errno = $errno or '$!')
83 *** DO NOT PANIC: this just means that *some* you may get some innocuous
84 *** compiler warnings.
95 my $c_prog = "int main () { return 0; }\n";
96 print "Checking if $Config{cc} supports \"$ccflags\"...";
97 my $result = try_compile
($c_prog, ccflags
=>$ccflags);
107 print "Checking for GSL..";
108 my %gsl_pkgcfg = ExtUtils
::PkgConfig
->find ('gsl');
110 my $MIN_GSL_VERSION = "1.8";
111 my $gv = $gsl_pkgcfg{'modversion'};
112 my $current_minor_version;
115 if ($gv =~ m{\A(\d+(?:\.\d+)+)}) {
116 my @current= split /\./, $1;
117 my @min= split /\./, $MIN_GSL_VERSION;
118 $current_minor_version = $current[1];
119 unless ($current[0] >= $min[0] && $current[1] >= $min[1]) {
122 *** You need to have GSL %s or greater installed. (You have $gv).
123 *** Get GSL at http://www.gnu.org/software/gsl\n", $MIN_GSL_VERSION;
126 print "Found GSL version $gv\n";
132 *** Can't parse GSL version $gv.
133 *** Will continue and keep my fingers crossed for luck.
139 *** Can't find GSL configuration info. Is GSL installed?
140 *** Get GSL at http://www.gnu.org/software/gsl
146 my $ccflags = $gsl_pkgcfg{cflags
};
148 ## Swig produces a number of GCC warnings. Turn them off if we can.
149 $ccflags .= try_cflags
("-Wno-strict-aliasing");
150 $ccflags .= try_cflags
("-Wno-unused-function");
151 $ccflags .= try_cflags
("-Wno-unused-value");
152 $ccflags .= try_cflags
("-Wno-unused-function");
153 $ccflags .= try_cflags
("-Wno-unused-variable");
155 my $ldflags = "$gsl_pkgcfg{libs} -gsl";
156 my $swig_flags = "$gsl_pkgcfg{cflags}"; # -Wall is a bit much
158 if ( $^O
eq 'cygwin' && $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 ( $^O
eq 'darwin' ) {
163 $ldflags .= ' -bundle -flat_namespace ';
165 if ($Config{archname
} =~ /x86_64/ ) {
166 $ldflags .= ' -fPIC -fno-omit-frame-pointer ';
167 $ccflags .= ' -fPIC -fno-omit-frame-pointer ';
170 my @Subsystems = grep { ! /^Test$/ } GSLBuilder
::subsystems
;
172 # BSplines appeared in 1.9
173 if ($current_minor_version < 9 ) {
174 @Subsystems = grep { ! /BSpline/ } @Subsystems;
177 xs
/*_wrap
.c core
*.core
178 swig
/*.o Makefile Math
-GSL
-* tmp
* pod2ht
*.tmp _build
179 lib
/Math/GSL
/[A-z]+/* blib
*.so
*.orig
180 } . join " ", map { catfile
( (qw( lib Math GSL ), "$_.pm") ) } @Subsystems;
182 my $builder = GSLBuilder
->new(
183 module_name
=> 'Math::GSL',
184 add_to_cleanup
=> [ $cleanup ],
185 create_makefile_pl
=> 'passthrough',
186 dist_abstract
=> 'Interface to the GNU Scientific Library using SWIG',
187 dist_author
=> 'Jonathan Leto <jonathan@leto.net>',
188 dist_version_from
=> 'lib/Math/GSL.pm',
190 extra_linker_flags
=> '-shared ' . $ldflags,
191 extra_compiler_flags
=> $ccflags,
192 swig_flags
=> $swig_flags,
195 'ExtUtils::PkgConfig' => '1.03',
198 'Test::Exception' => 0.21,
199 'Test::Class' => 0.12,
204 configure_requires
=> {
205 'ExtUtils::PkgConfig' => '1.03',
208 map { [ "swig/$_.i", "pod/$_.pod" ] } @Subsystems ,
211 $builder->add_build_element('swig');
212 $builder->create_build_script();
213 print "Have a great day!\n";