From 18e0b8065af3b660a73af93dabb4767cbc64ec35 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Mar 2011 13:10:42 +0200 Subject: Autotools support for SQLite --- Makefile.am | 4 ++ boost/Makefile.am | 5 +++ boost/common/template/Makefile.am | 1 + boost/mysql/template/Makefile.am | 1 + common/query/makefile | 2 +- common/template/Makefile.am | 1 + configure.ac | 4 ++ libcommon/common/Makefile.am | 3 +- libcommon/common/config.h.in | 1 + m4/database.m4 | 7 +++- m4/libodb-sqlite.m4 | 84 +++++++++++++++++++++++++++++++++++++++ m4/mysql.m4 | 2 +- m4/sqlite.m4 | 61 ++++++++++++++++++++++++++++ makefile | 2 +- mysql/template/Makefile.am | 1 + sqlite/mysql-vc10.sln | 15 ------- sqlite/mysql-vc9.sln | 15 ------- sqlite/sqlite-vc10.sln | 15 +++++++ sqlite/sqlite-vc9.sln | 15 +++++++ sqlite/template/Makefile.am | 1 + tracer/template/Makefile.am | 1 + 21 files changed, 206 insertions(+), 35 deletions(-) create mode 100644 m4/libodb-sqlite.m4 create mode 100644 m4/sqlite.m4 delete mode 100644 sqlite/mysql-vc10.sln delete mode 100644 sqlite/mysql-vc9.sln create mode 100644 sqlite/sqlite-vc10.sln create mode 100644 sqlite/sqlite-vc9.sln diff --git a/Makefile.am b/Makefile.am index b0070f3..0a15f76 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,5 +13,9 @@ if DATABASE_MYSQL SUBDIRS += mysql endif +if DATABASE_SQLITE +SUBDIRS += sqlite +endif + EXTRA_DIST = __file__(extra_dist) ACLOCAL_AMFLAGS = -I m4 diff --git a/boost/Makefile.am b/boost/Makefile.am index 85915d2..9b08372 100644 --- a/boost/Makefile.am +++ b/boost/Makefile.am @@ -9,4 +9,9 @@ if DATABASE_MYSQL SUBDIRS += mysql endif +if DATABASE_SQLITE +# @@ enable +#SUBDIRS += sqlite +endif + EXTRA_DIST = __file__(extra_dist) diff --git a/boost/common/template/Makefile.am b/boost/common/template/Makefile.am index 4ab6efe..6cd68eb 100644 --- a/boost/common/template/Makefile.am +++ b/boost/common/template/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) LDADD = $(top_builddir)/libcommon/common/libcommon.la AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; diff --git a/boost/mysql/template/Makefile.am b/boost/mysql/template/Makefile.am index 29017fa..6bab1d5 100644 --- a/boost/mysql/template/Makefile.am +++ b/boost/mysql/template/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) LDADD = $(top_builddir)/libcommon/common/libcommon.la AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; diff --git a/common/query/makefile b/common/query/makefile index 5e98970..c41b1d5 100644 --- a/common/query/makefile +++ b/common/query/makefile @@ -53,7 +53,7 @@ name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) $(dist): db_id := @database@ $(dist): sources := $(cxx_tun) $(dist): headers := $(odb_hdr) -$(dist): export extra_headers := traits.hxx +$(dist): export extra_headers := traits.hxx $(databases:%=traits-%.hxx) $(dist): data_dist := test.std $(dist): export name := $(name) $(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ diff --git a/common/template/Makefile.am b/common/template/Makefile.am index 758d015..eb1ae97 100644 --- a/common/template/Makefile.am +++ b/common/template/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) LDADD = $(top_builddir)/libcommon/common/libcommon.la AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; diff --git a/configure.ac b/configure.ac index 81d4a1a..cea2bd2 100644 --- a/configure.ac +++ b/configure.ac @@ -63,6 +63,10 @@ case $database in LIBODB_MYSQL([], [AC_MSG_ERROR([libodb-mysql is not found; consider using --with-libodb-mysql=DIR])]) MYSQL ;; + sqlite) + LIBODB_SQLITE([], [AC_MSG_ERROR([libodb-sqlite is not found; consider using --with-libodb-sqlite=DIR])]) + SQLITE + ;; esac # Check for the ODB compiler. diff --git a/libcommon/common/Makefile.am b/libcommon/common/Makefile.am index f4886fe..405a2ed 100644 --- a/libcommon/common/Makefile.am +++ b/libcommon/common/Makefile.am @@ -8,5 +8,6 @@ libcommon_la_SOURCES = __path__(sources) __path__(headers) EXTRA_DIST = __file__(extra_dist) -AM_CPPFLAGS= -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' -DLIBCOMMON_DYNAMIC_LIB +AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -DLIBCOMMON_DYNAMIC_LIB AM_LDFLAGS = -no-undefined -rpath '$(libdir)' diff --git a/libcommon/common/config.h.in b/libcommon/common/config.h.in index ad30893..8a504a0 100644 --- a/libcommon/common/config.h.in +++ b/libcommon/common/config.h.in @@ -10,6 +10,7 @@ #define LIBCOMMON_COMMON_CONFIG_H #undef DATABASE_MYSQL +#undef DATABASE_SQLITE #undef HAVE_TR1_MEMORY #undef LIBCOMMON_STATIC_LIB diff --git a/m4/database.m4 b/m4/database.m4 index 6f75e27..9478016 100644 --- a/m4/database.m4 +++ b/m4/database.m4 @@ -13,7 +13,7 @@ AC_MSG_CHECKING([for database to use]) AC_ARG_WITH( [database], [AC_HELP_STRING([--with-database=db], - [database to use for tests; valid values are: 'mysql'])], + [database to use for tests; valid values are: 'mysql', 'sqlite'])], [case $withval in no | yes) AC_MSG_RESULT([]) @@ -23,6 +23,10 @@ AC_ARG_WITH( database=mysql AC_DEFINE([DATABASE_MYSQL], [1], [Using MySQL.]) ;; + sqlite) + database=sqlite + AC_DEFINE([DATABASE_SQLITE], [1], [Using SQLite.]) + ;; *) AC_MSG_RESULT([]) AC_MSG_ERROR([unknown database $withval]) @@ -37,5 +41,6 @@ AC_MSG_RESULT([$database]) AC_SUBST([database]) AM_CONDITIONAL([DATABASE_MYSQL], [test x$database = xmysql]) +AM_CONDITIONAL([DATABASE_SQLITE], [test x$database = xsqlite]) ])dnl diff --git a/m4/libodb-sqlite.m4 b/m4/libodb-sqlite.m4 new file mode 100644 index 0000000..b85614f --- /dev/null +++ b/m4/libodb-sqlite.m4 @@ -0,0 +1,84 @@ +dnl file : m4/libodb-sqlite.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_SQLITE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl +AC_DEFUN([LIBODB_SQLITE], [ +libodb_sqlite_found=no + +AC_ARG_WITH( + [libodb-sqlite], + [AC_HELP_STRING([--with-libodb-sqlite=DIR],[location of libodb-sqlite build directory])], + [libodb_sqlite_dir=${withval}], + [libodb_sqlite_dir=]) + +AC_MSG_CHECKING([for libodb-sqlite]) + +# If libodb_sqlite_dir was given, add the necessary preprocessor and +# linker flags. +# +if test x"$libodb_sqlite_dir" != x; then + save_CPPFLAGS="$CPPFLAGS" + save_LDFLAGS="$LDFLAGS" + + AS_SET_CATFILE([abs_libodb_sqlite_dir], [$ac_pwd], [$libodb_sqlite_dir]) + + CPPFLAGS="$CPPFLAGS -I$abs_libodb_sqlite_dir" + LDFLAGS="$LDFLAGS -L$abs_libodb_sqlite_dir/odb/sqlite" +fi + +save_LIBS="$LIBS" +LIBS="-lodb-sqlite $LIBS" + +CXX_LIBTOOL_LINK_IFELSE( +AC_LANG_SOURCE([[ +#include + +void +f () +{ +} + +const char* +g () +{ + try + { + f (); + } + catch (const odb::sqlite::database_exception& e) + { + return e.what (); + } + return 0; +} + +int +main () +{ + const char* m (g ()); + return m != 0; +} +]]), +[libodb_sqlite_found=yes]) + +if test x"$libodb_sqlite_found" = xno; then + LIBS="$save_LIBS" + + if test x"$libodb_sqlite_dir" != x; then + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + fi +fi + +if test x"$libodb_sqlite_found" = xyes; then + AC_MSG_RESULT([yes]) + $1 +else + AC_MSG_RESULT([no]) + $2 +fi +])dnl diff --git a/m4/mysql.m4 b/m4/mysql.m4 index 5f35c91..102f150 100644 --- a/m4/mysql.m4 +++ b/m4/mysql.m4 @@ -202,7 +202,7 @@ fi # Create options file. # -AC_CONFIG_COMMANDS([db.options], +AC_CONFIG_COMMANDS([mysql.options], [ rm -f db.options echo '#! /bin/sh' >db-driver diff --git a/m4/sqlite.m4 b/m4/sqlite.m4 new file mode 100644 index 0000000..de5503e --- /dev/null +++ b/m4/sqlite.m4 @@ -0,0 +1,61 @@ +dnl file : m4/sqlite.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 SQLITE +dnl +AC_DEFUN([SQLITE], [ + +# Database file. +# +AC_MSG_CHECKING([for sqlite database file]) +AC_ARG_WITH( + [sqlite-db], + [AC_HELP_STRING([--with-sqlite-db=file], [SQLite database file (odb_test.db by default). Note that all data in this database WILL BE LOST!])], + [case $withval in + yes) + sqlite_db=odb_test.db + sqlite_db_set=yes + ;; + no) + sqlite_db_set=no + ;; + *) + sqlite_db=$withval + sqlite_db_set=yes + ;; + esac], + [sqlite_db=odb_test.db + sqlite_db_set=yes]) + +if test x$sqlite_db_set = xyes; then + + # Make it an absolute path unless it is one of the special values. + # + if test x$sqlite_db != x -a x$sqlite_db != x:memory:; then + AS_SET_CATFILE([abs_sqlite_db], [$ac_pwd], [$sqlite_db]) + sqlite_db=$abs_sqlite_db + fi + + AC_MSG_RESULT(['$sqlite_db']) +else + AC_MSG_RESULT([none]) +fi + +# Create options file. +# +AC_CONFIG_COMMANDS([sqlite.options], + [ + rm -f db.options + + if test x$sqlite_db_set = xyes; then + echo "--database '$sqlite_db'" >>db.options + fi + ], + [ + sqlite_db="$sqlite_db" + sqlite_db_set="$sqlite_db_set" + ]) + +])dnl diff --git a/makefile b/makefile index 0eaf04d..ad2f5b9 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))build/bootstrap.make -all_dirs := libcommon common tracer mysql boost +all_dirs := libcommon common tracer mysql sqlite boost dirs := common tracer boost ifeq ($(db_id),mysql) diff --git a/mysql/template/Makefile.am b/mysql/template/Makefile.am index 7571e28..af5895f 100644 --- a/mysql/template/Makefile.am +++ b/mysql/template/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) LDADD = $(top_builddir)/libcommon/common/libcommon.la AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; diff --git a/sqlite/mysql-vc10.sln b/sqlite/mysql-vc10.sln deleted file mode 100644 index 9a5dc32..0000000 --- a/sqlite/mysql-vc10.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/sqlite/mysql-vc9.sln b/sqlite/mysql-vc9.sln deleted file mode 100644 index 2ec9432..0000000 --- a/sqlite/mysql-vc9.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/sqlite/sqlite-vc10.sln b/sqlite/sqlite-vc10.sln new file mode 100644 index 0000000..9a5dc32 --- /dev/null +++ b/sqlite/sqlite-vc10.sln @@ -0,0 +1,15 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +__projects__ +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +__solution_configurations__ + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +__project_configurations__ + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/sqlite/sqlite-vc9.sln b/sqlite/sqlite-vc9.sln new file mode 100644 index 0000000..2ec9432 --- /dev/null +++ b/sqlite/sqlite-vc9.sln @@ -0,0 +1,15 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +__projects__ +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +__solution_configurations__ + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +__project_configurations__ + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/sqlite/template/Makefile.am b/sqlite/template/Makefile.am index 5591b10..ba169b3 100644 --- a/sqlite/template/Makefile.am +++ b/sqlite/template/Makefile.am @@ -9,6 +9,7 @@ noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) LDADD = $(top_builddir)/libcommon/common/libcommon.la AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; diff --git a/tracer/template/Makefile.am b/tracer/template/Makefile.am index c6cbb16..4305788 100644 --- a/tracer/template/Makefile.am +++ b/tracer/template/Makefile.am @@ -8,6 +8,7 @@ EXTRA_DIST = __file__(extra_dist) noinst_PROGRAMS = driver driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' TESTS=$(top_builddir)/tester TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; -- cgit v1.1