From 0171bf4686a984ed1acea17273ef534a9abbe1ba Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Mon, 7 Nov 2011 19:38:03 +0100 Subject: [PATCH] Move batch insert detection into db.m4 Moved the batch insert detection logic into the db.m4 macros so they only run when an enable command is set. This makes configure.in much cleaner. We also keep a list of backends which have batch insert enabled now that we allow multiple configured backends the simple yes or no doesn't cut it anymore so we output all backends that have batch insert enabled. Also fixed some problems in detecting the batch file enablers by splitting the LDFLAGS and LIBS for configure. So now a postgresql or mysql in a non standard place should work better. --- bacula/autoconf/bacula-macros/db.m4 | 138 +++++++++++++++++++-- bacula/autoconf/configure.in | 182 +++++++++------------------- 2 files changed, 182 insertions(+), 138 deletions(-) diff --git a/bacula/autoconf/bacula-macros/db.m4 b/bacula/autoconf/bacula-macros/db.m4 index 8e2610111e..2678af593b 100644 --- a/bacula/autoconf/bacula-macros/db.m4 +++ b/bacula/autoconf/bacula-macros/db.m4 @@ -121,6 +121,25 @@ AC_HELP_STRING([--with-dbi@<:@=DIR@:>@], [Include DBI support. DIR is the DBD ba fi uncomment_dbi=" " + dnl ------------------------------------------- + dnl Push the DB_PROG onto the stack of supported database backends for DBI + dnl ------------------------------------------- + DB_BACKENDS="${DB_BACKENDS} ${DB_PROG}" + + dnl ------------------------------------------- + dnl Check if dbi supports batch mode + dnl ------------------------------------------- + if test "x$support_batch_insert" = "xyes"; then + if test $DB_PROG = postgresql; then + AC_CHECK_LIB(pq, PQisthreadsafe, AC_DEFINE(HAVE_PQISTHREADSAFE)) + AC_CHECK_LIB(pq, PQputCopyData, AC_DEFINE(HAVE_PQ_COPY)) + test "x$ac_cv_lib_pq_PQputCopyData" = "xyes" + pkg=$? + if test $pkg = 0; then + AC_DEFINE(HAVE_DBI_BATCH_FILE_INSERT, 1, [Set if DBI DB batch insert code enabled]) + fi + fi + fi else AC_MSG_RESULT(no) fi @@ -132,7 +151,6 @@ AC_SUBST(DBI_LIBS) AC_SUBST(DBI_INCLUDE) AC_SUBST(DBI_BINDIR) AC_SUBST(DBI_DBD_DRIVERDIR) -AC_SUBST(uncomment_dbi) ]) @@ -203,7 +221,7 @@ AC_HELP_STRING([--with-dbi-driver@<:@=DRIVER@:>@], [Suport for DBI driver. DRIVE ;; "postgresql") db_prog="postgresql" - PG_CONFIG=`which pg_config` + PG_CONFIG=`which pg_config 2>/dev/null` if test -n "$PG_CONFIG"; then POSTGRESQL_BINDIR=`"$PG_CONFIG" --bindir` POSTGRESQL_LIBDIR=`"$PG_CONFIG" --libdir` @@ -400,7 +418,6 @@ AC_HELP_STRING([--with-mysql@<:@=DIR@:>@], [Include MySQL support. DIR is the My else MYSQL_LIBS="-L$MYSQL_LIBDIR -lmysqlclient_r -lz" fi - MYSQL_LFLAGS="-L$MYSQL_LIBDIR -lmysqlclient_r -lz" AC_DEFINE(HAVE_THREAD_SAFE_MYSQL, 1, [Set if Thread Safe MySQL can be checked using mysql_thread_safe]) DB_LIBS="${DB_LIBS} ${MYSQL_LIBS}" fi @@ -419,6 +436,30 @@ AC_HELP_STRING([--with-mysql@<:@=DIR@:>@], [Include MySQL support. DIR is the My else DB_BACKENDS="${DB_BACKENDS} mysql" fi + + dnl ------------------------------------------- + dnl Check if mysql supports batch mode + dnl ------------------------------------------- + if test "x$support_batch_insert" = "xyes"; then + dnl For mysql checking + saved_LDFLAGS="${LDFLAGS}" + LDFLAGS="${saved_LDFLAGS} -L$MYSQL_LIBDIR" + saved_LIBS="${LIBS}" + LIBS="${saved_LIBS} -lz" + + AC_CHECK_LIB(mysqlclient_r, mysql_thread_safe, AC_DEFINE(HAVE_MYSQL_THREAD_SAFE, 1, [Set if have mysql_thread_safe])) + if test "x$ac_cv_lib_mysqlclient_r_mysql_thread_safe" = "xyes"; then + if test -z "${batch_insert_db_backends}"; then + batch_insert_db_backends="MySQL" + else + batch_insert_db_backends="${batch_insert_db_backends} MySQL" + fi + fi + + dnl Revert after mysql checks + LDFLAGS="${saved_LDFLAGS}" + LIBS="${saved_LIBS}" + fi else AC_MSG_RESULT(no) fi @@ -504,7 +545,6 @@ AC_HELP_STRING([--with-embedded-mysql@<:@=DIR@:>@], [Include MySQL support. DIR else MYSQL_LIBS="-L$MYSQL_LIBDIR -lmysqld -lz -lm -lcrypt" fi - MYSQL_LFLAGS="-L$MYSQL_LIBDIR -lmysqld -lz -lm -lcrypt" MYSQL_LIB=$MYSQL_LIBDIR/libmysqld.a DB_LIBS="${DB_LIBS} ${MYSQL_LIBS}" @@ -522,6 +562,30 @@ AC_HELP_STRING([--with-embedded-mysql@<:@=DIR@:>@], [Include MySQL support. DIR else DB_BACKENDS="${DB_BACKENDS} mysql" fi + + dnl ------------------------------------------- + dnl Check if mysql supports batch mode + dnl ------------------------------------------- + if test "x$support_batch_insert" = "xyes"; then + dnl For mysql checking + saved_LDFLAGS="${LDFLAGS}" + LDFLAGS="${saved_LDFLAGS} -L$MYSQL_LIBDIR" + saved_LIBS="${LIBS}" + LIBS="${saved_LIBS} -lz -lm -lcrypt" + + AC_CHECK_LIB(mysqlclient_r, mysql_thread_safe, AC_DEFINE(HAVE_MYSQL_THREAD_SAFE, 1, [Set if have mysql_thread_safe])) + if test "x$ac_cv_lib_mysqlclient_r_mysql_thread_safe" = "xyes"; then + if test -z "${batch_insert_db_backends}"; then + batch_insert_db_backends="MySQL" + else + batch_insert_db_backends="${batch_insert_db_backends} MySQL" + fi + fi + + dnl Revert after mysql checks + LDFLAGS="${saved_LDFLAGS}" + LIBS="${saved_LIBS}" + fi else AC_MSG_RESULT(no) fi @@ -657,7 +721,6 @@ AC_HELP_STRING([--with-sqlite3@<:@=DIR@:>@], [Include SQLite3 support. DIR is th else SQLITE_LIBS="-L$SQLITE_LIBDIR -lsqlite3" fi - SQLITE_LFLAGS="-L$SQLITE_LIBDIR -lsqlite3" SQLITE_LIB=$SQLITE_LIBDIR/libsqlite3.a DB_LIBS="${DB_LIBS} ${SQLITE_LIBS}" @@ -674,6 +737,27 @@ AC_HELP_STRING([--with-sqlite3@<:@=DIR@:>@], [Include SQLite3 support. DIR is th else DB_BACKENDS="${DB_BACKENDS} sqlite3" fi + + dnl ------------------------------------------- + dnl Check if sqlite supports batch mode + dnl ------------------------------------------- + if test "x$support_batch_insert" = "xyes"; then + dnl For sqlite checking + saved_LDFLAGS="${LDFLAGS}" + LDFLAGS="${saved_LDFLAGS} -L$SQLITE_LIBDIR" + + AC_CHECK_LIB(sqlite3, sqlite3_threadsafe, AC_DEFINE(HAVE_SQLITE3_THREADSAFE, 1, [Set if have sqlite3_threadsafe])) + if test "x$ac_cv_lib_sqlite3_sqlite3_threadsafe" = "xyes"; then + if test -z "${batch_insert_db_backends}"; then + batch_insert_db_backends="SQLite3" + else + batch_insert_db_backends="${batch_insert_db_backends} SQLite3" + fi + fi + + dnl Revert after sqlite checks + LDFLAGS="${saved_LDFLAGS}" + fi else AC_MSG_RESULT(no) fi @@ -695,7 +779,7 @@ AC_HELP_STRING([--with-postgresql@<:@=DIR@:>@], [Include PostgreSQL support. DIR [ if test "$withval" != "no"; then if test "$withval" = "yes"; then - PG_CONFIG=`which pg_config` + PG_CONFIG=`which pg_config 2>/dev/null` if test -n "$PG_CONFIG"; then POSTGRESQL_INCDIR=`"$PG_CONFIG" --includedir` POSTGRESQL_LIBDIR=`"$PG_CONFIG" --libdir` @@ -762,11 +846,6 @@ AC_HELP_STRING([--with-postgresql@<:@=DIR@:>@], [Include PostgreSQL support. DIR POSTGRESQL_LIBS="-L$POSTGRESQL_LIBDIR -lpq" fi AC_CHECK_FUNC(crypt, , AC_CHECK_LIB(crypt, crypt, [POSTGRESQL_LIBS="$POSTGRESQL_LIBS -lcrypt"])) - if test x$use_libtool != xno; then - POSTGRESQL_LFLAGS=`echo ${POSTGRESQL_LIBS} | sed -e "s#-R $POSTGRESQL_LIBDIR##"` - else - POSTGRESQL_LFLAGS="${POSTGRESQL_LIBS}" - fi POSTGRESQL_LIB=$POSTGRESQL_LIBDIR/libpq.a DB_LIBS="${DB_LIBS} ${POSTGRESQL_LIBS}" @@ -780,6 +859,43 @@ AC_HELP_STRING([--with-postgresql@<:@=DIR@:>@], [Include PostgreSQL support. DIR else DB_BACKENDS="${DB_BACKENDS} postgresql" fi + + dnl ------------------------------------------- + dnl Check if postgresql supports batch mode + dnl ------------------------------------------- + if test "x$support_batch_insert" = "xyes"; then + dnl For postgresql checking + saved_LDFLAGS="${LDFLAGS}" + LDFLAGS="${saved_LDFLAGS} -L$POSTGRESQL_LIBDIR" + saved_LIBS="${LIBS}" + if test "x$ac_cv_lib_crypt_crypt" = "xyes" ; then + LIBS="${saved_LIBS} -lcrypt" + fi + + AC_CHECK_LIB(pq, PQisthreadsafe, AC_DEFINE(HAVE_PQISTHREADSAFE, 1, [Set if have PQisthreadsafe])) + AC_CHECK_LIB(pq, PQputCopyData, AC_DEFINE(HAVE_PQ_COPY, 1, [Set if have PQputCopyData])) + if test "x$ac_cv_lib_pq_PQputCopyData" = "xyes"; then + if test $support_batch_insert = yes ; then + AC_DEFINE(HAVE_POSTGRESQL_BATCH_FILE_INSERT, 1, [Set if PostgreSQL DB batch insert code enabled]) + if test -z "${batch_insert_db_backends}"; then + batch_insert_db_backends="PostgreSQL" + else + batch_insert_db_backends="${batch_insert_db_backends} PostgreSQL" + fi + fi + fi + + if test x$ac_cv_lib_pq_PQisthreadsafe != xyes -a x$support_batch_insert = xyes + then + echo "WARNING: Your PostgreSQL client library is too old to detect " + echo "if it was compiled with --enable-thread-safety, consider to " + echo "upgrade it in order to avoid problems with Batch insert mode" + fi + + dnl Revert after postgresql checks + LDFLAGS="${saved_LDFLAGS}" + LIBS="${saved_LIBS}" + fi else AC_MSG_RESULT(no) fi diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 7c67158c7c..7980e73d24 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -380,6 +380,7 @@ build_client_only=no build_dird=yes build_stored=yes db_backends="" +batch_insert_db_backends="" support_lockmgr=no dnl -------------------------------------------------------------------------- @@ -1701,9 +1702,32 @@ AC_ARG_WITH(sbin-perm, AC_SUBST(SBINPERM) +dnl ------------------------------------------- +dnl enable batch attribute DB insert (default on) +dnl ------------------------------------------- +support_batch_insert=yes +AC_ARG_ENABLE(batch-insert, + AC_HELP_STRING([--enable-batch-insert], [enable the DB batch insert code @<:@default=yes@:>@]), + [ + if test x$enableval = xno; then + support_batch_insert=no + fi + ] +) + +if test x$support_batch_insert = xyes; then + AC_DEFINE(USE_BATCH_FILE_INSERT, 1, [Set if DB batch insert code enabled]) +fi + dnl ------------------------------------------------ dnl Bacula check for various SQL database engines dnl ------------------------------------------------ + +dnl +dnl Set uncomment_dbi by default to '#' if DBI is enabled this will get reset +dnl +uncomment_dbi="#" + BA_CHECK_POSTGRESQL_DB BA_CHECK_MYSQL_DB @@ -1716,6 +1740,14 @@ BA_CHECK_SQLITE3_DB #BA_CHECK_DBI_DRIVER +dnl ------------------------------------------- +dnl If no batch insert backend are enable set +dnl variable to None +dnl ------------------------------------------- +if test -z "${batch_insert_db_backends}"; then + batch_insert_db_backends="None" +fi + dnl ------------------------------------------- dnl Make sure at least one database backend is found dnl ------------------------------------------- @@ -1788,116 +1820,12 @@ if test x$use_libtool = xyes; then DB_LIBS="" fi +AC_SUBST(uncomment_dbi) AC_SUBST(DB_BACKENDS) AC_SUBST(DB_LIBS) AC_SUBST(DEFAULT_DB_TYPE) AC_SUBST(SHARED_CATALOG_TARGETS) -dnl ------------------------------------------- -dnl enable batch attribute DB insert (default on) -dnl ------------------------------------------- -support_batch_insert=yes -AC_ARG_ENABLE(batch-insert, - AC_HELP_STRING([--enable-batch-insert], [enable the DB batch insert code @<:@default=yes@:>@]), - [ - if test x$enableval = xno; then - support_batch_insert=no - fi - ] -) - -if test x$support_batch_insert = xyes; then - AC_DEFINE(USE_BATCH_FILE_INSERT, 1, [Set if DB batch insert code enabled]) -fi - -dnl ------------------------------------------- -dnl Check if mysql supports batch mode -dnl ------------------------------------------- -if test ! -z "$MYSQL_LIB"; then - dnl For mysql checking - saved_LIBS="${LIBS}" - LIBS="${saved_LIBS} ${MYSQL_LFLAGS}" - - AC_CHECK_LIB(mysqlclient_r, mysql_thread_safe, AC_DEFINE(HAVE_MYSQL_THREAD_SAFE, 1, [Set if have mysql_thread_safe])) - - dnl Revert after mysql checks - LIBS="${saved_LIBS}" -fi - -dnl ------------------------------------------- -dnl Check if sqlite supports batch mode -dnl ------------------------------------------- -if test ! -z "SQLITE_LIB"; then - dnl For sqlite checking - saved_LIBS="${LIBS}" - LIBS="${saved_LIBS} ${SQLITE_LFLAGS}" - - AC_CHECK_LIB(sqlite3, sqlite3_threadsafe, AC_DEFINE(HAVE_SQLITE3_THREADSAFE, 1, [Set if have sqlite3_threadsafe])) - - dnl Revert after sqlite checks - LIBS="${saved_LIBS}" -fi - -dnl ------------------------------------------- -dnl Check if postgresql supports batch mode -dnl ------------------------------------------- -if test ! -z "$POSTGRESQL_LIB"; then - dnl For postgresql checking - saved_LIBS="${LIBS}" - LIBS="${saved_LIBS} ${POSTGRESQL_LFLAGS}" - - AC_CHECK_LIB(pq, PQisthreadsafe, AC_DEFINE(HAVE_PQISTHREADSAFE, 1, [Set if have PQisthreadsafe])) - AC_CHECK_LIB(pq, PQputCopyData, AC_DEFINE(HAVE_PQ_COPY, 1, [Set if have PQputCopyData])) - if test "x$ac_cv_lib_pq_PQputCopyData" = "xyes"; then - if test $support_batch_insert = yes ; then - AC_DEFINE(HAVE_POSTGRESQL_BATCH_FILE_INSERT, 1, [Set if PostgreSQL DB batch insert code enabled]) - fi - fi - - if test x$ac_cv_lib_pq_PQisthreadsafe != xyes -a x$support_batch_insert = xyes - then - echo "WARNING: Your PostgreSQL client library is too old to detect " - echo "if it was compiled with --enable-thread-safety, consider to " - echo "upgrade it in order to avoid problems with Batch insert mode" - echo - fi - - dnl Revert after postgresql checks - LIBS="${saved_LIBS}" -fi - -dnl ------------------------------------------- -dnl Check if dbi supports batch mode -dnl ------------------------------------------- -if test ! -z "$DBI_LIBS"; then - dnl ------------------------------------------- - dnl Push the DB_PROG onto the stack of supported database backends for DBI - dnl ------------------------------------------- - DB_BACKENDS="${DB_BACKENDS} ${DB_PROG}" - - dnl ------------------------------------------- - dnl Check for batch insert - dnl ------------------------------------------- - if test $DB_PROG = postgresql; then - AC_CHECK_LIB(pq, PQisthreadsafe, AC_DEFINE(HAVE_PQISTHREADSAFE)) - AC_CHECK_LIB(pq, PQputCopyData, AC_DEFINE(HAVE_PQ_COPY)) - test "x$ac_cv_lib_pq_PQputCopyData" = "xyes" - pkg=$? - if test $pkg = 0; then - if test $support_batch_insert = yes ; then - AC_DEFINE(HAVE_DBI_BATCH_FILE_INSERT, 1, [Set if DBI DB batch insert code enabled]) - fi - fi - fi -else - dnl ------------------------------------------- - dnl If dbi was not chosen, let the comment in file - dnl ------------------------------------------- - uncomment_dbi="#" -fi - -AC_SUBST(uncomment_dbi) - AC_DEFINE(PROTOTYPES) dnl -------------------------------------------------------------------------- @@ -3477,28 +3405,28 @@ Configuration on `date`: File Daemon User: ${fd_user} File Daemon Group: ${fd_group} - Large file support: $largefile_support - Bacula conio support: ${got_conio} ${CONS_LIBS} - readline support: ${got_readline} ${PRTREADLINE_SRC} - TCP Wrappers support: ${TCPW_MSG} ${WRAPLIBS} - TLS support: ${support_tls} - Encryption support: ${support_crypto} - ZLIB support: ${have_zlib} - LZO support: ${have_lzo} - enable-smartalloc: ${support_smartalloc} - enable-lockmgr: ${support_lockmgr} - bat support: ${support_bat} - enable-gnome: ${support_gnome} ${gnome_version} - enable-bwx-console: ${support_wx_console} ${wx_version} - enable-tray-monitor: ${support_tray_monitor} - client-only: ${build_client_only} - build-dird: ${build_dird} - build-stored: ${build_stored} - Plugin support: ${have_plugins} - ACL support: ${have_acl} - XATTR support: ${have_xattr} - Python support: ${support_python} ${PYTHON_LIBS} - Batch insert enabled: ${support_batch_insert} + Large file support: $largefile_support + Bacula conio support: ${got_conio} ${CONS_LIBS} + readline support: ${got_readline} ${PRTREADLINE_SRC} + TCP Wrappers support: ${TCPW_MSG} ${WRAPLIBS} + TLS support: ${support_tls} + Encryption support: ${support_crypto} + ZLIB support: ${have_zlib} + LZO support: ${have_lzo} + enable-smartalloc: ${support_smartalloc} + enable-lockmgr: ${support_lockmgr} + bat support: ${support_bat} + enable-gnome: ${support_gnome} ${gnome_version} + enable-bwx-console: ${support_wx_console} ${wx_version} + enable-tray-monitor: ${support_tray_monitor} + client-only: ${build_client_only} + build-dird: ${build_dird} + build-stored: ${build_stored} + Plugin support: ${have_plugins} + ACL support: ${have_acl} + XATTR support: ${have_xattr} + Python support: ${support_python} ${PYTHON_LIBS} + Batch insert enabled: ${batch_insert_db_backends} " > config.out -- 2.39.5