]> Dogcows Code - chaz/p5-Alien-ZMQ/commitdiff
cflags and libs can now return a list of flags
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 29 Jan 2013 08:37:37 +0000 (01:37 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 29 Jan 2013 08:37:37 +0000 (01:37 -0700)
examples/01-compile.t
lib/Alien/ZMQ.pm
t/00-basic.t

index ffde85d5f5614f1910f6ecb302bb463d0998a563..83940efbb4ddb099ddd0024160c647b3c29c25c9 100644 (file)
@@ -37,25 +37,25 @@ END
 close $SRC;
 
 my $obj = eval {
 close $SRC;
 
 my $obj = eval {
-    $cb->compile(source => $src, extra_compiler_flags => Alien::ZMQ::cflags);
+    $cb->compile(source => $src, extra_compiler_flags => [Alien::ZMQ->cflags]);
 };
 unlink $src;
 ok($obj, "compile C code");
 BAIL_OUT("compile failed") unless $obj;
 
 my $exe = eval {
 };
 unlink $src;
 ok($obj, "compile C code");
 BAIL_OUT("compile failed") unless $obj;
 
 my $exe = eval {
-    $cb->link_executable(objects => $obj, extra_linker_flags => Alien::ZMQ::libs);
+    $cb->link_executable(objects => $obj, extra_linker_flags => [Alien::ZMQ->libs]);
 };
 unlink $obj;
 ok($exe, "link object");
 BAIL_OUT("link failed") unless $exe;
 
 };
 unlink $obj;
 ok($exe, "link object");
 BAIL_OUT("link failed") unless $exe;
 
-$ENV{LD_LIBRARY_PATH} = Alien::ZMQ::lib_dir;
+$ENV{LD_LIBRARY_PATH} = Alien::ZMQ->lib_dir;
 my $out = `./$exe`;
 ok($out, "run executable");
 unlink $exe;
 my ($inc_version, $lib_version) = $out =~ /(\d\.\d\.\d) (\d\.\d\.\d)/;
 
 my $out = `./$exe`;
 ok($out, "run executable");
 unlink $exe;
 my ($inc_version, $lib_version) = $out =~ /(\d\.\d\.\d) (\d\.\d\.\d)/;
 
-ok(version->parse($inc_version) == Alien::ZMQ::inc_version, "include versions are equal");
-ok(version->parse($lib_version) == Alien::ZMQ::lib_version, "library versions are equal");
+cmp_ok(version->parse($inc_version), '==', Alien::ZMQ->inc_version, "include versions are equal");
+cmp_ok(version->parse($lib_version), '==', Alien::ZMQ->lib_version, "library versions are equal");
 
 
index 7351fb6d56cb8b86d9445405705080902ee856d7..3990b8644565cade07f660c6ed81c1378c8af737 100644 (file)
@@ -44,19 +44,19 @@ be on the system.  Use this to skip those checks and always install libzmq.
 
 Pass extra flags to the compiler when probing for an existing installation of
 libzmq.  You can use this, along with L</--zmq-libs>, to help the probing
 
 Pass extra flags to the compiler when probing for an existing installation of
 libzmq.  You can use this, along with L</--zmq-libs>, to help the probing
-function locate your libzmq installation if it is installed in an unexpected
-place.  For example, if your libzmq is installed at F</opt/zeromq>, you can do
-something like this:
+function locate libzmq if it is installed in an unexpected place.  For
+example, if your libzmq is installed at F</opt/zeromq>, you can do something
+like this:
 
 
-    perl ./Build.PL --zmq-cflags="-I/opt/zeromq/include" \
-                    --zmq-libs="-L/opt/zeromq/lib -lzmq"
+    perl Build.PL --zmq-cflags="-I/opt/zeromq/include" \
+                  --zmq-libs="-L/opt/zeromq/lib -lzmq"
 
 These flags are only used by the probing function to locate libzmq; they will
 not be used when compiling libzmq from source (if it needs to be).  To affect
 the compiling of libzmq, using the L</--zmq-config> flag instead.
 
 A better alternative to using L</--zmq-cflags> and L</--zmq-libs> is to help
 
 These flags are only used by the probing function to locate libzmq; they will
 not be used when compiling libzmq from source (if it needs to be).  To affect
 the compiling of libzmq, using the L</--zmq-config> flag instead.
 
 A better alternative to using L</--zmq-cflags> and L</--zmq-libs> is to help
-the L<pkg-config(1)> command find your libzmq using the C<PKG_CONFIG_PATH>
+the L<pkg-config(1)> program find your libzmq by using the C<PKG_CONFIG_PATH>
 environment variable.  Of course, this method requires that you have the
 L<pkg-config(1)> program installed.  Here's an example:
 
 environment variable.  Of course, this method requires that you have the
 L<pkg-config(1)> program installed.  Here's an example:
 
@@ -67,9 +67,9 @@ L<pkg-config(1)> program installed.  Here's an example:
 
 Pass extra flags to the linker when probing for an existing installation of
 libzmq.  You can use this, along with L</--zmq-cflags>, to help the probing
 
 Pass extra flags to the linker when probing for an existing installation of
 libzmq.  You can use this, along with L</--zmq-cflags>, to help the probing
-function locate your libzmq installation if it is installed in an unexpected
-place.  Like L</--zmq-cflags>, these flags are only used by the probing
-function to locate libzmq.
+function locate libzmq if it is installed in an unexpected place.  Like
+L</--zmq-cflags>, these flags are only used by the probing function to locate
+libzmq.
 
 =item --zmq-config
 
 
 =item --zmq-config
 
@@ -144,31 +144,44 @@ sub lib_dir { }
 =method cflags
 
 Get the C compiler flags required to compile a program that uses libzmq.  This
 =method cflags
 
 Get the C compiler flags required to compile a program that uses libzmq.  This
-is a shortcut for constructing a C<-I> flag using L</inc_dir>.
+is a shortcut for constructing a C<-I> flag using L</inc_dir>.  In scalar
+context, the flags are quoted using L<String::ShellQuote> and returned as
+a single string.
 
 =cut
 
 sub cflags {
 
 =cut
 
 sub cflags {
-    "-I" . shell_quote(inc_dir);
+    if (wantarray) {
+        "-I" . inc_dir;
+    } else {
+        "-I" . shell_quote(inc_dir);
+    }
 }
 
 =method libs
 
 Get the linker flags required to link a program against libzmq.  This is
 }
 
 =method libs
 
 Get the linker flags required to link a program against libzmq.  This is
-a shortcut for constructing a C<-L> flag using L</lib_dir>, plus C<-lzmq>.  On
-some platforms, you may also want to add the library path to your executable
-or library as a runtime path; this can be done by passing C<-rpath> to the
-linker.  Something like this could work:
+a shortcut for constructing a C<-L> flag using L</lib_dir>, plus C<-lzmq>.  In
+scalar context, the flags are quoted using L<String::ShellQuote> and returned
+as a single string.
 
 
-    my $mylibs = Alien::ZMQ::libs . " -Wl,-rpath=" . Alien::ZMQ::lib_dir;
+On some platforms, you may also want to add the library path to your
+executable or library as a runtime path; this is usually done by passing
+C<-rpath> to the linker.  Something like this could work:
+
+    my @flags = (Alien::ZMQ::libs, "-Wl,-rpath=" . Alien::ZMQ::lib_dir);
 
 This will allow your program to find libzmq, even if it is installed in
 
 This will allow your program to find libzmq, even if it is installed in
-a non-standard location, but this isn't necessary on some platforms.
+a non-standard location, but some systems don't have this C<RPATH> mechanism.
 
 =cut
 
 sub libs {
 
 =cut
 
 sub libs {
-    "-L" . shell_quote(lib_dir) . " -lzmq";
+    if (wantarray) {
+        "-L" . lib_dir, "-lzmq";
+    } else {
+        "-L" . shell_quote(lib_dir) . " -lzmq";
+    }
 }
 
 1;
 }
 
 1;
index f819d60a2c2862151927bcc76a5e62688773da73..bb257eae65a6addbd32a3d601cd866e6dbe0f202 100644 (file)
@@ -1,9 +1,9 @@
 #!perl
 
 #!perl
 
-use warnings;
+use warnings FATAL => 'all';
 use strict;
 
 use strict;
 
-use Test::More tests => 8;
+use Test::More tests => 11;
 
 BEGIN {
     use_ok 'Alien::ZMQ';
 
 BEGIN {
     use_ok 'Alien::ZMQ';
@@ -14,7 +14,10 @@ ok Alien::ZMQ::lib_version, "library version number";
 ok Alien::ZMQ::inc_dir,     "include directory path";
 ok Alien::ZMQ::inc_dir,     "library directory path";
 
 ok Alien::ZMQ::inc_dir,     "include directory path";
 ok Alien::ZMQ::inc_dir,     "library directory path";
 
-like Alien::ZMQ::cflags, qr/-I\S+/, "cflags has -I";
-like Alien::ZMQ::libs,   qr/-L\S+/, "libs has -L";
-like Alien::ZMQ::libs,   qr/-lzmq/, "libs has -lzmq";
+ok grep(/-I\S+/, Alien::ZMQ::cflags), "cflags array has -I";
+ok grep(/-L\S+/, Alien::ZMQ::libs),   "libs array has -L";
+ok grep(/-lzmq/, Alien::ZMQ::libs),   "libs array has -lzmq";
 
 
+like Alien::ZMQ::cflags, qr/-I\S+/, "cflags string has -I";
+like Alien::ZMQ::libs,   qr/-L\S+/, "libs string has -L";
+like Alien::ZMQ::libs,   qr/-lzmq/, "libs string has -lzmq";
This page took 0.027096 seconds and 4 git commands to generate.