From: Andreas Henriksson <andreas@fatal.se>
Subject: Add configure option for pgsql support

Add configure option --enable-pgsql to manually be able to select 
instead of automagically choosing at build-time, to be able to build 
both the static- and postgresql-version of bandwidthd

diff -urNad bandwidthd-2.0.1+cvs20071208~/configure.in bandwidthd-2.0.1+cvs20071208/configure.in
--- bandwidthd-2.0.1+cvs20071208~/configure.in	2007-12-11 13:51:23.000000000 +0100
+++ bandwidthd-2.0.1+cvs20071208/configure.in	2007-12-11 13:51:50.000000000 +0100
@@ -55,10 +55,35 @@
 	[AC_CHECK_LIB(wpcap, pcap_open_live, ,[AC_MSG_ERROR([Bandwidthd requires but cannot find libpcap])])])
 
 # Optional Library
-AC_CHECK_FILE(/usr/local/pgsql/lib, LDFLAGS="$LDFLAGS -L/usr/local/pgsql/lib")
-AC_CHECK_FILE(/usr/local/pgsql/include, CPPFLAGS="$CPPFLAGS -I/usr/local/pgsql/include")
-AC_CHECK_LIB(pq, PQconnectdb,
-	[AC_CHECK_LIB(pq,PQexecParams, ,AC_MSG_WARN([libpq exists but is too old... bandwidthd requires support for PQexecParams]))])
+AC_PATH_PROG(PG_CONFIG, pg_config)
+
+use_pgsql=no
+
+if test x$enable_pgsql = xyes ; then
+  if test "x$PG_CONFIG" = "x" ; then
+    echo "*** Couldn't find pg_config. Disabling PostgreSQL support."
+  else
+    LDFLAGS="$LDFLAGS -L`$PG_CONFIG --libdir` -lpq"
+
+    pgsql_cflags=`$PG_CONFIG --includedir`
+    if test "x$pgsql_cflags" != "x/usr/include" ; then
+      CPPFLAGS="$CPPFLAGS -I$pgsql_cflags"
+    fi
+     
+    use_pgsql=yes
+    AC_DEFINE(HAVE_LIBPQ, 1, "Enable PostgreSQL compiletime option")
+  fi
+fi
+
+#AM_CONDITIONAL(HAVE_PGSQL, test x$use_pgsql != xno)
+
+#AC_SUBST(PG_LIBS)
+#AC_SUBST(PG_CFLAGS)
+
+#AC_CHECK_FILE(/usr/local/pgsql/lib, LDFLAGS="$LDFLAGS -L/usr/local/pgsql/lib")
+#AC_CHECK_FILE(/usr/local/pgsql/include, CPPFLAGS="$CPPFLAGS -I/usr/local/pgsql/include")
+#AC_CHECK_LIB(pq, PQconnectdb,
+#	[AC_CHECK_LIB(pq,PQexecParams, ,AC_MSG_WARN([libpq exists but is too old... bandwidthd requires support for PQexecParams]))])
 
 # Checks for header files.
 AC_HEADER_DIRENT
@@ -133,4 +158,7 @@
 AC_DEFINE_DIR(LOG_DIR, log_dir, [Name of log directory])
 AC_DEFINE_DIR(HTDOCS_DIR, htdocs_dir, [Name of htdocs directory])
 AC_DEFINE_DIR(EXTENSION_DIR, extension_dir, [Name of the extensions directory])
+AC_ARG_ENABLE([pgsql], AC_HELP_STRING([--enable-pgsql],
+	[Enable PostgreSQL support. Default is yes, if available.]),
+	enable_pgsql="$enableval", enable_pgsql=yes)
 AC_OUTPUT(Makefile)
