X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=inc%2FMy%2FBuild.pm;h=d9ca6c7fa5e6cb91e0fabecd467e1f5277269edf;hb=cbcb27109b8b3ddd478fe7f6f072b175a3546e9b;hp=b582c9123730d8d9815a450fde23de0bf53d96e0;hpb=2c02694aaa9e02740bfd1f127d7dc676f816d54f;p=chaz%2Fp5-Alien-ZMQ diff --git a/inc/My/Build.pm b/inc/My/Build.pm index b582c91..d9ca6c7 100644 --- a/inc/My/Build.pm +++ b/inc/My/Build.pm @@ -1,16 +1,14 @@ package My::Build; -use v5.10; use warnings FATAL => 'all'; use strict; -use utf8; use Archive::Tar; use Cwd qw/realpath/; use Digest::SHA qw/sha1_hex/; use File::Path qw/remove_tree/; use File::Spec::Functions qw/catdir catfile/; -use IPC::Cmd qw/can_run run/; +use IPC::Run qw/run/; use LWP::Simple qw/getstore RC_OK/; use Module::Build; @@ -30,20 +28,20 @@ sub ACTION_code { $self->have_c_compiler or die "C compiler not found"; unless (exists $args{'zmq-skip-probe'}) { - say "Probing..."; + print "Probing...\n"; %vars = $self->probe_zeromq; } - if ($vars{inc_version} && $vars{lib_version}) { - say "Found ØMQ $vars{lib_version}; skipping installation"; + if ($vars{inc_version} && $vars{lib_version} && $vars{inc_dir} && $vars{lib_dir}) { + print "Found libzmq $vars{lib_version}; skipping installation\n"; } else { - say "ØMQ not found; building from source..."; + print "libzmq not found; building from source...\n"; %vars = $self->install_zeromq; } # write vars to ZMQ.pm my $module = catfile qw/blib lib Alien ZMQ.pm/; - open my $LIB, "<$module" or die "Cannot read module"; + open my $LIB, '<', $module or die "Cannot read module"; my $lib = do { local $/; <$LIB> }; close $LIB; $lib =~ s/^sub inc_dir.*$/sub inc_dir { "$vars{inc_dir}" }/m; @@ -52,12 +50,12 @@ sub ACTION_code { $lib =~ s/^sub lib_version.*$/sub lib_version { v$vars{lib_version} }/m; my @stats = stat $module; chmod 0644, $module; - open $LIB, ">$module" or die "Cannot write config to module"; + open $LIB, '>', $module or die "Cannot write config to module"; print $LIB $lib; close $LIB; chmod $stats[2], $module; - open my $TARGET, ">build-zeromq"; + open my $TARGET, '>', "build-zeromq"; print $TARGET time, "\n"; close $TARGET; } @@ -68,7 +66,7 @@ sub probe_zeromq { my %config = $cb->get_config; my $src = "test-$$.c"; - open my $SRC, ">$src"; + open my $SRC, '>', $src; print $SRC < #include @@ -155,25 +153,23 @@ sub install_zeromq { my $self = shift; my $cb = $self->cbuilder; - can_run("libtool") or die "The libtool command cannot be found"; - my $version = $self->notes('zmq-version'); my $sha1 = $self->notes('zmq-sha1'); my $archive = "zeromq-$version.tar.gz"; - say "Downloading ØMQ $version source archive from download.zeromq.org..."; + print "Downloading libzmq $version source archive from download.zeromq.org...\n"; getstore("http://download.zeromq.org/$archive", $archive) == RC_OK - or die "Failed to download ØMQ source archive"; + or die "Failed to download libzmq source archive"; - say "Verifying..."; + print "Verifying...\n"; my $sha1sum = Digest::SHA->new; - open my $ARCHIVE, "<$archive"; + open my $ARCHIVE, '<', $archive or die "Can't open source archive"; binmode $ARCHIVE; $sha1sum->addfile($ARCHIVE); close $ARCHIVE; $sha1sum->hexdigest eq $sha1 or die "Source archive checksum mismatch"; - say "Extracting..."; + print "Extracting...\n"; Archive::Tar->new($archive)->extract; unlink $archive; @@ -181,19 +177,24 @@ sub install_zeromq { my $basedir = $self->base_dir; my $datadir = catdir($basedir, "share"); my $srcdir = catdir($basedir, "zeromq-$version"); + chdir $srcdir; - say "Configuring..."; + print "Patching...\n"; + for my $patch (glob("$basedir/files/zeromq-$version-*.patch")) { + run [qw/patch -p1/], '<', $patch or die "Failed to patch libzmq"; + } + + print "Configuring...\n"; my @config = $cb->split_like_shell($self->args('zmq-config') || ""); - chdir $srcdir; - run(command => ["./configure", "--prefix=$prefix", @config]) - or die "Failed to configure ØMQ"; + $cb->do_system(qw/sh configure CPPFLAGS=-Wno-error/, "--prefix=$prefix", @config) + or die "Failed to configure libzmq"; - say "Compiling..."; - run(command => ['make']) or die "Failed to make ØMQ"; + print "Compiling...\n"; + $cb->do_system("make") or die "Failed to make libzmq"; - say "Installing..."; - run(command => [qw|make install prefix=/|, "DESTDIR=$datadir"]) - or die "Failed to install ØMQ"; + print "Installing...\n"; + $cb->do_system(qw|make install prefix=/|, "DESTDIR=$datadir") + or die "Failed to install libzmq"; chdir $basedir; remove_tree($srcdir);