-if test "x$with_libpq" = "xyes"
-then
- with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
- pg_config_status=$?
-
- if test $pg_config_status -eq 0
- then
- if test -n "$with_libpq_libdir"; then
- for dir in $with_libpq_libdir; do
- with_libpq_ldflags="$with_libpq_ldflags -L$dir"
- done
- fi
- else
- AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
- fi
-
- SAVE_LDFLAGS="$LDFLAGS"
- LDFLAGS="$LDFLAGS $with_libpq_ldflags"
-
- AC_CHECK_LIB(pq, PQconnectdb,
- [with_libpq="yes"],
- [with_libpq="no (symbol 'PQconnectdb' not found)"])
-
- AC_CHECK_LIB(pq, PQserverVersion,
- [with_libpq="yes"],
- [with_libpq="no (symbol 'PQserverVersion' not found)"])
-
- LDFLAGS="$SAVE_LDFLAGS"
-fi
-if test "x$with_libpq" = "xyes"
-then
- BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
- BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
- AC_SUBST(BUILD_WITH_LIBPQ_CPPFLAGS)
- AC_SUBST(BUILD_WITH_LIBPQ_LDFLAGS)
+
+if test "x$with_libpq" = "xyes"; then
+ with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
+ pg_config_status=$?
+
+ if test $pg_config_status -eq 0
+ then
+ if test -n "$with_libpq_libdir"; then
+ for dir in $with_libpq_libdir; do
+ with_libpq_ldflags="$with_libpq_ldflags -L$dir"
+ done
+ fi
+ else
+ AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+ fi
+
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $with_libpq_ldflags"
+
+ AC_CHECK_LIB([pq], [PQserverVersion],
+ [with_libpq="yes"],
+ [with_libpq="no (symbol 'PQserverVersion' not found)"])
+
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+if test "x$with_libpq" = "xyes"; then
+ BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
+ BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
+ BUILD_WITH_LIBPQ_LIBS="-lpq"
+fi
+
+AC_SUBST([BUILD_WITH_LIBPQ_CPPFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LDFLAGS])
+AC_SUBST([BUILD_WITH_LIBPQ_LIBS])
+# }}}
+
+# --with-libpqos {{{
+AC_ARG_WITH([libpqos],
+ [AS_HELP_STRING([--with-libpqos@<:@=PREFIX@:>@], [Path to libpqos.])],
+ [
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
+ with_libpqos_cppflags="-I$withval/include"
+ with_libpqos_ldflags="-L$withval/lib"
+ with_libpqos="yes"
+ else
+ with_libpqos="$withval"
+ fi
+ ],
+ [with_libpqos="yes"]
+)
+
+if test "x$with_libpqos" = "xyes"; then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libpqos_cppflags"
+
+ AC_CHECK_HEADERS([pqos.h],
+ [with_libpqos="yes"],
+ [with_libpqos="no (pqos.h not found)"]
+ )
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+
+if test "x$with_libpqos" = "xyes"; then
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $with_libpqos_ldflags"
+
+ AC_CHECK_LIB([pqos], [pqos_init],
+ [with_libpqos="yes"],
+ [with_libpqos="no (Can't find libpqos)"]
+ )
+
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+
+if test "x$with_libpqos" = "xyes"; then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libpqos_cppflags"
+ AC_PREPROC_IFELSE(
+ [
+ AC_LANG_SOURCE(
+ [[
+ #include <pqos.h>
+ #if PQOS_VERSION < 106
+ #error "required PQOS version >= 1.06"
+ #endif
+ ]]
+ )
+ ],
+ [with_libpqos="yes"],
+ [with_libpqos="no (pqos library version 1.06 or higher is required)"]
+ )
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+
+if test "x$with_libpqos" = "xyes"; then
+ BUILD_WITH_LIBPQOS_CPPFLAGS="$with_libpqos_cppflags"
+ BUILD_WITH_LIBPQOS_LDFLAGS="$with_libpqos_ldflags"
+ BUILD_WITH_LIBPQOS_LIBS="-lpqos"