Bio-SamTools

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use Module::Build;
use Module::Load::Conditional qw(can_load);

my $HeaderFile = "bam.h";
my $LibFile    = "libbam.a";
my $ReadLine;

my ($sam_include,$sam_lib) = find_sam(); # may exit with error here

my $class = Module::Build->subclass(code=><<EOF);
    sub process_c_bin_files {
	my \$self = shift;
	chomp(my \$make  = `which make`);
	chomp(my \$nmake = `which nmake`);
	\$make ||= \$nmake;
	system "cd c_bin; \$make INCLUDES=-I$sam_include LIBPATH=-L$sam_lib";
	mkdir "blib/bin" unless -e "blib/bin";
        my \@exec = grep {-x \$_} <c_bin/*>;
	\$self->copy_if_modified(from   =>\$_,
				 to_dir => "./blib/bin/",
				 flatten=>1,
	    ) foreach \@exec;
    }

    sub ACTION_clean {
	my \$self = shift;
	\$self->SUPER::ACTION_clean();
        system "cd c_bin; make -s clean";
    }
EOF

my $build = $class->new(
    module_name        => 'Bio::SamTools',
    dist_version_from  => 'lib/Bio/DB/Sam.pm',
    dist_author        => 'Lincoln Stein <lincoln.stein@gmail.com>',
    dist_abstract      => 'Perl interface to SamTools library for DNA sequencing',
    license            => 'perl',
    include_dirs       => [$sam_include],
    extra_linker_flags => ["-L$sam_lib",'-lbam','-lpthread','-lz'],

    extra_compiler_flags=>[

        # must match DFLAGS in Samtools Makefile
	'-D_IOLIB=2','-D_FILE_OFFSET_BITS=64', 

	# turn off warnings originating in Perl's Newx* calls
	'-Wformat=0',
    ],

    c_source    => 'c_bin',
    c_bin_files => {'./bin/bam2bedgraph' => 'bin/bam2bedgraph'},

    build_requires => {
      'ExtUtils::CBuilder' => 0,
    },
    requires     => {
	'perl'                => '5.008',
	'Bio::Root::Version'  => '1.006009001',
    },
#    create_makefile_pl => 'passthrough',
    );

$build->add_build_element('c_bin');
$build->create_build_script;

exit 0;

sub find_sam {
    my ($sam_include,$sam_lib);

    if (my $samtools = _samtools()) {
	$sam_include = $samtools
	    if -e "$samtools/$HeaderFile";
	$sam_include = "$samtools/include"
	    if -e "$samtools/include/$HeaderFile";
	$sam_lib     = $samtools
	    if -e "$samtools/$LibFile";
	$sam_lib     = "$samtools/lib"
	    if -e "$samtools/lib/$LibFile";



( run in 2.405 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )