title: How to define AM_CONDITIONAL and AC_DEFINE based on PKG_CHECK_MODULES result?
body: <p>I am trying to write a <code>configure.ac</code> file to do these tasks:</p>
  
  <ol>
  <li><p>The <code>configure</code> script should accept a <code>--with-libuv</code> parameter.</p></li>
  <li><p>A variable <code>with_libuv</code> should be set to either <code>yes</code>, <code>no</code> or <code>check</code> (with <code>check</code> being the default value when nothing was passed on the command line).</p></li>
  <li><p>When <code>with_libuv == "yes"</code> a mandatory PKG_CHECK_MODULES check for <code>libuv &gt;= 1.9.0</code> should be done and <code>HAVE_LIBUV = 1</code> should be set on success (On error <code>configure</code> should abort).</p></li>
  <li><p>When <code>with_libuv == "no"</code> nothing should be checked,</p></li>
  <li><p>When <code>with_libuv == "false"</code> an optional PKG_CHECK_MODULES check (for the same library as in 3.) should be done and <code>HAVE_LIBUV</code> should be set to either <code>0</code> or <code>1</code> accordingly.</p></li>
  <li><p>If <code>with_libuv != "no" &amp;&amp; HAVE_LIBUV == 1</code> AC_DEFINE should set <code>-DUSE_LIBUV</code> and AM_CONDITIONAL should set <code>USE_LIBUV</code> as a conditional for automake.</p></li>
  <li><p>If not <code>with_libuv != "no" &amp;&amp; HAVE_LIBUV == 1</code> the preprocessor directive should not be set and the AM_CONDITIONAL should be set to <code>0</code>.</p></li>
  </ol>
  
  <p>I have figured out how to do steps 1-5, but I am struggeling with 6 and 7.</p>
  
  <p>Here is my current attempt:</p>
  
  <pre><code>AC_INIT(
    [mumble-pluginbot-plusplus],
    [0.5],
    [https://github.com/promi/mumble-pluginbot-plusplus/issues],
    [],
    [https://github.com/promi/mumble-pluginbot-plusplus])
  
  AC_CONFIG_MACRO_DIR([m4])
  AM_INIT_AUTOMAKE([foreign])
  AM_SILENT_RULES([yes])
  
  AC_PROG_CXX
  LT_INIT
  
  # Make sure that pkg-config is installed!
  # The PKG_CHECK_MODULES macro prints a horrible error message when
  # pkg-config is not installed at autogen time.                   
  #
  # It is also required when the first PKG_CHECK_MODULES is inside a conditional
  PKG_PROG_PKG_CONFIG
  
  PKG_CHECK_MODULES(OPUS, [opus &gt;= 1.1])
  PKG_CHECK_MODULES(OPENSSL, [openssl])
  PKG_CHECK_MODULES(PROTOBUF, [protobuf])
  PKG_CHECK_MODULES(MPDCLIENT, [libmpdclient])
  
  AC_ARG_WITH(
    [libuv],
    [AS_HELP_STRING([--with-libuv], [support efficient MPD status polling @&lt;:@default=check@:&gt;@])],
    [],
    [with_libuv=check])
  
  # if     --with-libuv    -&gt; it must be installed
  # elseif --without-libuv -&gt; do nothing
  # else                   -&gt; check whether it is installed
  AS_CASE(
    ["$with_libuv"],
    [yes], [PKG_CHECK_MODULES(UV, [libuv &gt;= 1.9.0], [HAVE_LIBUV=1])],
    [no],  [],
           [PKG_CHECK_MODULES(UV, [libuv &gt;= 1.9.0], [HAVE_LIBUV=1], [HAVE_LIBUV=0])])
  
  if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
     AM_CONDITIONAL([USE_LIBUV], [1])
     AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
  else
     AM_CONDITIONAL([USE_LIBUV], [0])
  fi
  
  #AC_CONFIG_HEADERS([src/config.h])
  AC_CONFIG_FILES([Makefile])
  
  AC_OUTPUT
  </code></pre>
  
  <p>The problematic part is this:</p>
  
  <pre><code>if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
     AM_CONDITIONAL([USE_LIBUV], [1])
     AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
  else
     AM_CONDITIONAL([USE_LIBUV], [0])
  fi
  </code></pre>
  
  <p>Here is an excerpt from the configure output:</p>
  
  <pre><code>checking pkg-config is at least version 0.9.0... yes
  checking for OPUS... yes
  checking for OPENSSL... yes
  checking for PROTOBUF... yes
  checking for MPDCLIENT... yes
  checking for UV... yes
  ./configure: line 16467: test: x1: integer expression expected
  ./configure: line 16480: 0: command not found
  checking that generated files are newer than configure... done
  </code></pre>
  
  <p>How can I implement steps 6 and 7 in a way that actually works?</p>