Parse-STDF
view release on metacpan or search on metacpan
#!/usr/bin/env perl
# Copyright (C) 2014 Erick Jordan <ejordan@cpan.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
use Module::Build;
use Config;
my $LIBSTDF_CONFIG = "libstdf-config";
my $MIN_SWIG_VERSION = version->parse("2.0.4");
my $MIN_LIBSTDF_VERSION = version->parse("0.4");
check_libstdf();
my $class = Module::Build->subclass( class => 'MyModuleBuild',
code => q!
use File::Basename;
use Data::Dumper;
sub process_swig_files {
my $self = shift;
my $verb = $self->runtime_params('verbose');
$verb = 0 if $self->runtime_params('quiet');
#my @p = @_;
print "process swig files\n" if $verb;
my $swigdeps = $self->config('swig_source');
my @swig_flags = $self->split_like_shell($self->config('swig_flags'));
my @swigsource = keys %$swigdeps;
my $lib = 'lib';
#my $blib_lib = File::Spec->catfile('blib', 'lib');
foreach my $file (@swigsource) {
#FIXME add dir $self->config('swig_files')
my $basename = basename($file, '.swg');
my $cfile = $basename."_wrap.c";
my $pmfile = File::Spec->catfile($lib,"$basename.pm");
if ($self->up_to_date($swigdeps->{$file}, $cfile) &&
$self->up_to_date($swigdeps->{$file}, $pmfile)) {
next if $self->up_to_date($file, $cfile) &&
$self->up_to_date($cfile, $pmfile);
}
print "swig: $file -> $cfile\n" if $verb;
$self->do_system('swig', '-o', $cfile, '-perl', '-outdir',
$lib, @swig_flags, $file);
$self->copy_if_modified(from => $pmfile, to_dir => 'blib');
}
return 1;
}
sub process_c_files {
my $self = shift;
my $verb = $self->runtime_params('verbose');
$verb = 0 if $self->runtime_params('quiet');
#my @p = @_;
print "process c files\n" if $verb;
my $cfiles = $self->rscan_dir('./',qr/\.c$/);
# if none return
#set $self->quiet() for CBuilder->new
$self->quiet($verb?0:1);
my $cb = $self->cbuilder(); # get a ExtUtils::CBuilder object
print " CBuilder: ",$cb->VERSION,"\n" if $verb;
#setenv TMPDIR for cc ??
foreach my $file (@$cfiles) {
my $basename = basename($file, '_wrap.c');
$basename = basename($file, '.c') if not defined $basename;
my $libname = $basename.".".$self->config('dlext');
$libname = File::Spec->catfile('blib', 'arch',$libname);
next if $self->up_to_date($file,$libname);
print "(CC) $file -> $basename.so\n" if $verb;
my $obj = $cb->compile(source => $file,
## include_dirs => $self->config('include_dirs'),
extra_compiler_flags => $self->config('extra_compiler_flags'));
print "CB compiled: $obj\n" if $verb;
my $lib = $cb->link(objects => $obj,
extra_linker_flags => $self->config('extra_linker_flags'));
print "CB generated: $lib\n" if $verb;
$self->copy_if_modified(from => $lib, to => $libname);
}
return 1;
}
!);
#
my $build = $class->new(
module_name => 'Parse::STDF',
configure_requires => { 'Module::Build' => 0.38 },
create_makefile_pl => 'small',
dist_abstract =>
'Parse files in Standard Test Data Format into Perl objects',
dist_author => 'Erick Jordan <ejordan@cpan.org>',
dist_version_from => 'lib/Parse/STDF.pm',
license => 'gpl',
needs_compiler => 1,
release_status => 'stable',
requires => {
'Test::More' => 0,
'version' => 0,
'ExtUtils::CBuilder' => '0.28'
},
get_options => {
extra_ldflags => { type => '=s' },
extra_ccflags => { type => '=s' },
}
);
$build->config(swig_files => './');
$build->config(swig_source => { # with dependencies as hash value
'swig/libstdf.swg' => ['swig/funcs.swg', 'swig/typemaps.swg']
} );
if($build->have_c_compiler()) {
$build->notes('c_compiler' => 1);
print "C compiler found - check swig\n" if $build->config('verbose');
if(!$build->config('obj_ext')) {
$build->config('obj_ext','.o');
}
if(!$build->config('dlext')) {
$build->config('dlext','so');
}
my $swig_installed = check_swig(
verbose => $build->config('verbose'));
$build->notes(swig_installed => $swig_installed);
my ($ccflags, $ldflags,$swig_flags) = check_c_compiler(
$build->config('cc'), $build->config('ccflags'));
# Add command line options here:
$ldflags .= ' '.$build->args('extra_ldflags') if ( defined( $build->args('extra_ldflags') ) );
$ccflags .= ' '.$build->args('extra_ccflags') if ( defined( $build->args('extra_ccflags') ) );
$build->config(extra_linker_flags => $ldflags);
$build->config(extra_compiler_flags => $ccflags);
if($swig_installed) {
$build->config(swig_flags => $swig_flags);
$build->add_build_element('swig');
( run in 2.235 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )