From 321aaee205aee9035497b32c9087fabe325a7696 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 22 Jul 2011 16:00:49 +0200 Subject: MAke automake scripts PostgreSQL aware --- Makefile.am | 4 ++ configure.ac | 4 ++ m4/database.m4 | 5 ++ m4/libodb-pgsql.m4 | 84 ++++++++++++++++++++++ m4/pgsql.m4 | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100644 m4/libodb-pgsql.m4 create mode 100644 m4/pgsql.m4 diff --git a/Makefile.am b/Makefile.am index 2631719..09198da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,5 +21,9 @@ if DATABASE_SQLITE SUBDIRS += sqlite endif +if DATABASE_PGSQL +SUBDIRS += pgsql +endif + EXTRA_DIST = __file__(extra_dist) ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 43f8dc7..ff877d8 100644 --- a/configure.ac +++ b/configure.ac @@ -78,6 +78,10 @@ case $database in LIBODB_SQLITE([], [AC_MSG_ERROR([libodb-sqlite is not found; consider using --with-libodb-sqlite=DIR])]) SQLITE ;; + pgsql) + LIBODB_PGSQL([], [AC_MSG_ERROR([libodb-pgsql is not found; consider using --with-libodb-pgsql=DIR])]) + PGSQL + ;; esac # Check for the ODB compiler. diff --git a/m4/database.m4 b/m4/database.m4 index 9478016..476ec19 100644 --- a/m4/database.m4 +++ b/m4/database.m4 @@ -27,6 +27,10 @@ AC_ARG_WITH( database=sqlite AC_DEFINE([DATABASE_SQLITE], [1], [Using SQLite.]) ;; + pgsql) + database=pgsql + AC_DEFINE([DATABASE_PGSQL], [1], [Using PostgreSQL.]) + ;; *) AC_MSG_RESULT([]) AC_MSG_ERROR([unknown database $withval]) @@ -42,5 +46,6 @@ AC_SUBST([database]) AM_CONDITIONAL([DATABASE_MYSQL], [test x$database = xmysql]) AM_CONDITIONAL([DATABASE_SQLITE], [test x$database = xsqlite]) +AM_CONDITIONAL([DATABASE_PGSQL], [test x$database = xpgsql]) ])dnl diff --git a/m4/libodb-pgsql.m4 b/m4/libodb-pgsql.m4 new file mode 100644 index 0000000..0e92478 --- /dev/null +++ b/m4/libodb-pgsql.m4 @@ -0,0 +1,84 @@ +dnl file : m4/libodb-pgsql.m4 +dnl author : Boris Kolpackov +dnl copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +dnl license : GNU GPL v2; see accompanying LICENSE file +dnl +dnl LIBODB_PGSQL([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl +AC_DEFUN([LIBODB_PGSQL], [ +libodb_pgsql_found=no + +AC_ARG_WITH( + [libodb-pgsql], + [AC_HELP_STRING([--with-libodb-pgsql=DIR],[location of libodb-pgsql build directory])], + [libodb_pgsql_dir=${withval}], + [libodb_pgsql_dir=]) + +AC_MSG_CHECKING([for libodb-pgsql]) + +# If libodb_pgsql_dir was given, add the necessary preprocessor and +# linker flags. +# +if test x"$libodb_pgsql_dir" != x; then + save_CPPFLAGS="$CPPFLAGS" + save_LDFLAGS="$LDFLAGS" + + AS_SET_CATFILE([abs_libodb_pgsql_dir], [$ac_pwd], [$libodb_pgsql_dir]) + + CPPFLAGS="$CPPFLAGS -I$abs_libodb_pgsql_dir" + LDFLAGS="$LDFLAGS -L$abs_libodb_pgsql_dir/odb/pgsql" +fi + +save_LIBS="$LIBS" +LIBS="-lodb-pgsql $LIBS" + +CXX_LIBTOOL_LINK_IFELSE( +AC_LANG_SOURCE([[ +#include + +void +f () +{ +} + +const char* +g () +{ + try + { + f (); + } + catch (const odb::pgsql::database_exception& e) + { + return e.what (); + } + return 0; +} + +int +main () +{ + const char* m (g ()); + return m != 0; +} +]]), +[libodb_pgsql_found=yes]) + +if test x"$libodb_pgsql_found" = xno; then + LIBS="$save_LIBS" + + if test x"$libodb_pgsql_dir" != x; then + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + fi +fi + +if test x"$libodb_pgsql_found" = xyes; then + AC_MSG_RESULT([yes]) + $1 +else + AC_MSG_RESULT([no]) + $2 +fi +])dnl diff --git a/m4/pgsql.m4 b/m4/pgsql.m4 new file mode 100644 index 0000000..0646fec --- /dev/null +++ b/m4/pgsql.m4 @@ -0,0 +1,200 @@ +dnl file : m4/pgsql.m4 +dnl author : Constantin Michael +dnl copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +dnl license : GNU GPL v2; see accompanying LICENSE file +dnl +dnl PGSQL +dnl +AC_DEFUN([PGSQL], [ + +# Client. +# +AC_MSG_CHECKING([for pgsql client program]) +AC_ARG_WITH( + [pgsql-client], + [AC_HELP_STRING([--with-pgsql-client=path], [PostgreSQL client program path (psql by default)])], + [case $withval in + yes) + pgsql_client=psql + ;; + no) + AC_MSG_RESULT([]) + AC_MSG_ERROR([need pgsql client to run the tests]) + ;; + *) + pgsql_client=$withval + ;; + esac], + [pgsql_client=psql]) + +$pgsql_client --version 2>/dev/null 1>&2 + +if test x"$?" = x0; then + AC_MSG_RESULT([$psql_client]) +else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([pgsql client is not found; consider using --with-pgsql-client=PATH]) +fi + +# User. +# +AC_MSG_CHECKING([for pgsql database user]) +AC_ARG_WITH( + [pgsql-user], + [AC_HELP_STRING([--with-pgsql-user=login], [PostgreSQL database user (odb_test by default)])], + [case $withval in + yes) + pgsql_user=odb_test + pgsql_user_set=yes + ;; + no) + pgsql_user_set=no + ;; + *) + pgsql_user=$withval + pgsql_user_set=yes + ;; + esac], + [pgsql_user=odb_test + pgsql_user_set=yes]) + +if test x$pgsql_user_set = xyes; then + AC_MSG_RESULT(['$pgsql_user']) +else + AC_MSG_RESULT([none]) +fi + +# Database name. +# +AC_MSG_CHECKING([for pgsql database name]) +AC_ARG_WITH( + [pgsql-db], + [AC_HELP_STRING([--with-pgsql-db=name], [PostgreSQL database name (odb_test by default). Note that all data in this database WILL BE LOST!])], + [case $withval in + yes) + pgsql_db=odb_test + pgsql_db_set=yes + ;; + no) + pgsql_db_set=no + ;; + *) + pgsql_db=$withval + pgsql_db_set=yes + ;; + esac], + [pgsql_db=odb_test + pgsql_db_set=yes]) + +if test x$pgsql_db_set = xyes; then + AC_MSG_RESULT(['$pgsql_db']) +else + AC_MSG_RESULT([none]) +fi + +# Host. +# +AC_MSG_CHECKING([for pgsql database host]) +AC_ARG_WITH( + [pgsql-host], + [AC_HELP_STRING([--with-pgsql-host=host], [PostgreSQL database host (standard PostgreSQL host by default)])], + [case $withval in + yes) + pgsql_host= + pgsql_host_set=yes + ;; + no) + pgsql_host_set=no + ;; + *) + pgsql_host=$withval + pgsql_host_set=yes + ;; + esac], + [pgsql_host_set=no]) + +if test x$pgsql_host_set = xyes; then + AC_MSG_RESULT(['$pgsql_host']) +else + AC_MSG_RESULT([localhost]) +fi + +# Port. +# +AC_MSG_CHECKING([for pgsql database port]) +AC_ARG_WITH( + [pgsql-port], + [AC_HELP_STRING([--with-pgsql-port=port], [PostgreSQL database port (standard PostgreSQL port by default)])], + [case $withval in + yes) + pgsql_port=0 + pgsql_port_set=yes + ;; + no) + pgsql_port_set=no + ;; + *) + pgsql_port=$withval + pgsql_port_set=yes + ;; + esac], + [pgsql_port_set=no]) + +if test x$pgsql_port_set = xyes; then + AC_MSG_RESULT(['$pgsql_port']) +else + AC_MSG_RESULT([default]) +fi + +# Create options file. +# +AC_CONFIG_COMMANDS([pgsql.options], + [ + rm -f db.options + echo '#! /bin/sh' >db-driver + + if test x$pgsql_user_set = xyes; then + echo "--user '$pgsql_user'" >>db.options + echo 'opt="$opt --user='"$pgsql_user"'"' >>db-driver + fi + + if test x$pgsql_db_set = xyes; then + echo "--database '$pgsql_db'" >>db.options + echo 'opt="$opt --database='"$pgsql_db"'"' >>db-driver + fi + + if test x$pgsql_host_set = xyes; then + echo "--host '$pgsql_host'" >>db.options + echo 'opt="$opt --host='"$pgsql_host"'"' >>db-driver + fi + + if test x$pgsql_port_set = xyes; then + echo "--port '$pgsql_port'" >>db.options + echo 'opt="$opt --port='"$pgsql_port"'"' >>db-driver + fi + + echo 'if test x$[]1 != x; then' >>db-driver + echo " exec $pgsql_client "'$opt <$[]1' >>db-driver + echo "else" >>db-driver + echo " exec $pgsql_client "'$opt' >>db-driver + echo "fi" >>db-driver + + chmod +x db-driver + ], + [ + pgsql_client="$pgsql_client" + + pgsql_user="$pgsql_user" + pgsql_user_set="$pgsql_user_set" + + pgsql_db="$pgsql_db" + pgsql_db_set="$pgsql_db_set" + + pgsql_host="$pgsql_host" + pgsql_host_set="$pgsql_host_set" + + pgsql_port="$pgsql_port" + pgsql_port_set="$pgsql_port_set" + ]) + +])dnl -- cgit v1.1