+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_h_path=""
+postgres_includes_found=no
+save_c_switch_site="$c_switch_site"
+
+dnl First, test standard location and site prefixes only:
+if test "$with_postgresql" != "no"; then
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+fi
+
+dnl Otherwise, test different known headers locations on linux:
+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
+ postgres_h_path="/usr/local/pgsql/include"
+ fi
+ c_switch_site="$save_c_switch_site"
+fi
+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
+ postgres_h_path="pgsql"
+ fi
+ c_switch_site="$save_c_switch_site"
+ fi
+if test "$postgres_includes_found" = "no" -a "$with_postgresql" != "no" -a \
+ -d "/usr/include/postgresql"; then
+ c_switch_site="$c_switch_site -I/usr/include/postgresql"
+ AC_CHECK_HEADER(libpq-fe.h,postgres_includes_found=yes)
+ if test "$postgres_includes_found" = "yes"; then
+ postgres_h_path="postgresql"
+fi
+ c_switch_site="$save_c_switch_site"
+fi
+
+dnl Finally, check if we can link with 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
+ if test -n "$postgres_h_path"; then
+ AC_DEFINE_UNQUOTED(POSTGRES_H_PATH, $postgres_h_path)
+ fi
+ AC_DEFINE(HAVE_POSTGRESQL)
+ if test "$with_postgresqlv7" = "yes"; then
+ AC_DEFINE(HAVE_POSTGRESQLV7)
+ fi
+ XE_PREPEND(-lpq, LIBS)
+ XE_ADD_OBJS(postgresql.o)
+fi
+