+dnl Autodetect PostgreSQL
+dnl The default installation location (non-Linux) is /usr/local/pgsql;
+dnl a different prefix can be selected at build/install time. If PostgreSQL
+dnl is installed into a different prefix, that prefix must be specified in
+dnl in the --site-prefixes flag.
+dnl The default RPM-based Linux installation location is /usr.
+AC_CHECKING(for PostgreSQL)
+postgres_includes_found=no
+save_c_switch_site="$c_switch_site"
+dnl First check site prefixes
+if test "$with_postgresql" != "no"; then
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+fi
+dnl test for Linux-style installation in /usr
+if test "$postgres_includes_found" = "no" -a "$with_postgresql" != "no" -a \
+ -d "/usr/include/pgsql"; then
+ c_switch_site="$c_switch_site -I/usr/include/pgsql"
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+ if test "$postgres_includes_found" != "yes"; then
+ c_switch_site="$save_c_switch_site"
+ fi
+fi
+if test "$postgres_includes_found" = "no" -a "$with_postgresql" != "no" -a \
+ -d "/usr/local/pgsql/include"; then
+ c_switch_site="$c_switch_site -I/usr/local/pgsql/include"
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+ if test "$postgres_includes_found" != "yes"; then
+ c_switch_site="$save_c_switch_site"
+ fi
+fi
+
+dnl last check -- can we link against libpq?
+if test "$postgres_includes_found" = "yes"; then
+ AC_CHECK_LIB(pq,PQconnectdb,with_postgresql=yes,with_postgresql=no)
+fi
+if test "$with_postgresql" = "yes"; then
+ AC_CHECK_LIB(pq,PQconnectStart,with_postgresqlv7=yes,with_postgresqlv7=no)
+fi
+if test "$with_postgresql" = "yes"; then
+ AC_DEFINE(HAVE_POSTGRESQL)
+ if test "$with_postgresqlv7" = "yes"; then
+ AC_DEFINE(HAVE_POSTGRESQLV7)
+ fi
+ XE_PREPEND(-lpq, LIBS)
+ XE_ADD_OBJS(postgresql.o)
+else
+ c_switch_site=$save_c_switch_site
+fi
+