+# PostgreSQL includes and libraries
+with_postgres_include="-I/usr/include/pqxx"
+AC_MSG_NOTICE([using PostgreSQL headers at $with_postgres_include])
+with_postgres_lib="-lpqxx -lpq"
+AC_MSG_NOTICE([using PostgreSQL libraries at $with_postgres_lib])
+
+AC_SUBST(with_postgres_lib)
+AC_SUBST(with_postgres_include)
+POSTGRES_LIB="${with_postgres_lib}"
+AC_SUBST(POSTGRES_LIB)
+POSTGRES_INCLUDE="${with_postgres_include}"
+AC_SUBST(POSTGRES_INCLUDE)
+
+
+# Checks for libraries.
+AC_CHECK_LIB([pq], [PQexec], [], [AC_MSG_ERROR([Failed to find a suitable libpq.
+
+PostgreSQL's libpq needs to be installed.
+Perhaps you need to specify --with-postgres-lib?
+])], -L${with_postgres_lib})
+
+
+CXXFLAGS="$CXXFLAGS $POSTGRES_INCLUDE"
+LIBS="$LIBS $POSTGRES_LIB"