]>
Dogcows Code - chaz/p5-Alien-ZMQ/blob - inc/My/Build.pm
4 use warnings FATAL
=> 'all';
10 use Digest
::SHA qw
/sha1_hex/;
11 use File
::Path qw
/remove_tree/;
12 use File
::Spec
::Functions qw
/catdir catfile/;
13 use LWP
::Simple qw
/getstore RC_OK/;
16 use base
'Module::Build';
21 $self->SUPER::ACTION_code
;
23 return if -e
'build-zeromq';
24 $self->add_to_cleanup('build-zeromq');
26 my %args = $self->args;
29 $self->have_c_compiler or die "C compiler not found";
31 unless (exists $args{'zmq-skip-probe'}) {
33 %vars = $self->probe_zeromq;
36 if ($vars{inc_version
} && $vars{lib_version
}) {
37 say "Found ØMQ $vars{lib_version}; skipping installation";
39 say "ØMQ not found; building from source...";
40 %vars = $self->install_zeromq;
43 # write vars to ZMQ.pm
44 my $module = catfile qw
/blib lib Alien ZMQ.pm/;
45 open my $LIB, "<$module" or die "Cannot read module";
46 my $lib = do { local $/; <$LIB> };
48 $lib =~ s/^sub inc_dir.*$/sub inc_dir { "$vars{inc_dir}" }/m;
49 $lib =~ s/^sub lib_dir.*$/sub lib_dir { "$vars{lib_dir}" }/m;
50 $lib =~ s/^sub inc_version.*$/sub inc_version { v$vars{inc_version} }/m;
51 $lib =~ s/^sub lib_version.*$/sub lib_version { v$vars{lib_version} }/m;
52 my @stats = stat $module;
54 open $LIB, ">$module" or die "Cannot write config to module";
57 chmod $stats[2], $module;
59 open my $TARGET, ">build-zeromq";
60 print $TARGET time, "\n";
66 my $cb = $self->cbuilder;
67 my %config = $cb->get_config;
69 my $src = "test-$$.c";
70 open my $SRC, ">$src";
74 int main(int argc, char* argv[]) {
75 int major, minor, patch;
76 zmq_version(&major, &minor, &patch);
77 printf("%d.%d.%d %d.%d.%d",
78 ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH,
88 my $cflags = $self->args('zmq-cflags');
89 my $libs = $self->args('zmq-libs');
93 my $pkg_config = $ENV{PKG_CONFIG_COMMAND
} || "pkg-config";
94 for my $pkg (qw
/libzmq zeromq3/) {
95 $pkg_version = `$pkg_config $pkg --modversion`;
97 next unless $pkg_version;
99 $cflags ||= `$pkg_config $pkg --cflags`;
100 $libs ||= `$pkg_config $pkg --libs`;
102 # use -I and -L flag arguments as extra search directories
103 my $inc = `$pkg_config $pkg --cflags-only-I`;
104 push @inc_search, map { s/^-I//; $_ } $cb->split_like_shell($inc);
105 my $lib = `$pkg_config $pkg --libs-only-L`;
106 push @lib_search, map { s/^-L//; $_ } $cb->split_like_shell($lib);
112 $cb->compile(source
=> $src, include_dirs
=> [@inc_search], extra_compiler_flags
=> $cflags);
118 $cb->link_executable(objects
=> $obj, extra_linker_flags
=> $libs);
125 my ($inc_version, $lib_version) = $out =~ /(\d\.\d\.\d) (\d\.\d\.\d)/;
127 # query the compiler for include and library search paths
128 push @lib_search, map {
132 -d $path ? realpath($path) : ();
133 } split /:/, `$config{cc
} -print-search-dirs
`;
134 push @inc_search, map {
136 $path =~ s/lib(32|64)?$/include/;
140 # search for the header and library files
141 my ($inc_dir) = grep { -f catfile($_, "zmq.h") } @inc_search;
142 my ($lib_dir) = grep { -f catfile($_, $cb->lib_file("libzmq")) } @lib_search;
145 inc_version => $inc_version,
146 lib_version => $lib_version,
147 pkg_version => $pkg_version,
155 my $cb = $self->cbuilder;
157 my $version = $self->notes('zmq-version');
158 my $sha1 = $self->notes('zmq-sha1');
159 my $archive = "zeromq-$version.tar.gz";
161 say "Downloading ØMQ $version source archive from download.zeromq.org...";
162 getstore("http://download.zeromq.org/$archive", $archive) == RC_OK
163 or die "Failed to download ØMQ source archive";
166 my $sha1sum = Digest::SHA->new;
167 open my $ARCHIVE, "<$archive";
169 $sha1sum->addfile($ARCHIVE);
171 $sha1sum->hexdigest eq $sha1 or die "Source archive checksum mismatch";
174 Archive::Tar->new($archive)->extract;
177 my $prefix = catdir($self->install_destination("lib"), qw/auto share dist Alien-ZMQ/);
178 my $basedir = $self->base_dir;
179 my $datadir = catdir($basedir, "share");
180 my $srcdir = catdir($basedir, "zeromq-$version");
182 say "Configuring...";
183 my @config = $cb->split_like_shell($self->args('zmq-config') || "");
185 $cb->do_system("./configure", "--prefix=$prefix", @config)
186 or die "Failed to configure ØMQ";
189 $cb->do_system("make") or die "Failed to make ØMQ";
192 $cb->do_system(qw|make install prefix=/|, "DESTDIR=$datadir")
193 or die "Failed to install ØMQ";
196 remove_tree($srcdir);
199 inc_version => $version,
200 lib_version => $version,
201 inc_dir => catdir($prefix, "include"),
202 lib_dir => catdir($prefix, "lib"),
This page took 0.045883 seconds and 4 git commands to generate.