Alien-GMP

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN


my $check_gmp = <<'EOF';
#include <gmp.h>
int main(int argc, char *argv[]) { return __GNU_MP__ == 5 ? 0 : 1; }
EOF
my $cc = ExtUtils::CChecker->new;

my %paths = do {
	if ( !$ENV{COMPILE_ALIEN_GMP}
		 && $cc->try_compile_run( source => $check_gmp ) ) {
		say "GMP version >= 5.0.0 already installed; skipping compilation";

		# Find system include and lib directories:
		my @inc_paths = map {
			s/\n.*$//;
			s/^.+ =?//;
			-d $_ ? realpath($_) : () } split /:/, qx(cc -print-search-dirs);
		my ($inc_dir) = grep { -f catfile($_, "gmp.h") } map {
			my $path = $_;
			$path =~ s/lib/include/;
			$path } @inc_paths;
		my ($lib_dir) = grep { -f catfile($_, "libgmp.so") } @inc_paths;
		( inc_dir => $inc_dir, lib_dir => $lib_dir, extra_files => [] ) }
	else {
		can_run("libtool") or die "libtool not found";

		say "Downloading GMP source archive from ftp.gnu.org...";
		my $archive = "gmp-5.0.4.tar.bz2";
		my $ftp = Net::FTP->new("ftp.gnu.org")
			or die "Unable to connect to ftp.gnu.org";
		$ftp->login or die "Unable to anonymously login to ftp.gnu.org";
		$ftp->binary;
		$ftp->get("/gnu/gmp/$archive") or die "Failed to download $archive";
		$ftp->quit;

		say "Extracting...";
		Archive::Tar->new($archive)->extract;
		unlink $archive;

		# Compile/Install:
		say "Configuring...";
		my $base_dir = $builder->base_dir;
		my $share_dir = catdir( $base_dir, "share" );
		my $gmp_dir = catdir( $base_dir, glob "gmp-*" );
		chdir $gmp_dir;
		run( command => [
			"./configure", "--prefix=$share_dir", "--enable-shared"] )
			or die "Failed to configure GMP";

		say "Compiling...";
		run( command => [qw(make -j9)]) or die "Failed to make GMP";

		say "Installing...";
		run( command => [qw(make install)] ) or die "Failed to install GMP";

		# Gather include and lib directories:
		chdir $base_dir;
		remove_tree($gmp_dir);
		my @extra_files = ( glob( catfile qw(share include *) ),
							glob( catfile qw(share lib *) ),
							glob( catfile qw(share share info *) ) );
		my $dest_sharedir = catdir( $builder->install_destination("lib"),
									"auto", "share", "dist", "Alien-GMP" );



( run in 0.472 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )