1dnl
2dnl $Id$
3dnl
4dnl R embedding of the SQLite engine.
5dnl
6dnl Generate a "configure" script that will install the RSQLite
7dnl packge.  By default, we use embed the SQLite "amalgamation" that
8dnl is distributed with RSQLite.  Only if the user asks will we link
9dnl to a SQLite library already installed on the system.
10dnl
11dnl    USAGE:  autoconf
12dnl
13dnl Global variables:
14dnl    PKG_CPPFLAGS and PKG_LIBS
15dnl
16dnl The resulting configure script implements the following logic:
17dnl
18dnl 1. If both PKG_CPPFLAGS and PKG_LIBS are defined, use them and exit.
19dnl
20dnl 2. If the user specifies explicitly a particular SQLite
21dnl    installation we use that version. This can be requested through
22dnl         --with-sqlite-dir=DIR
23dnl         --with-sqlite-inc=<include-DIR>
24dnl    or   --with-sqlite-lib=<library-DIR>
25dnl
26dnl    In the first case, DIR is assumed to include the lib and include
27dnl    subdirectories;  individual locations of these two may be
28dnl    specified independently through <include-dir> and <library-dir>,
29dnl    respectively.  If we find these, we exit.
30dnl
31dnl 3. If the user did not specify a SQLite installation, we set a
32dnl    preprocessor define to include the SQLite amalgamation.
33dnl
34
35AC_INIT(src/rsqlite.h)
36
37# As suggested by BDR, I may need to use CFLAGS to compile under 64-bit
38# (I can't test this), but see "Writing R Extensions"
39: ${R_HOME=`R RHOME`}
40if test -z "${R_HOME}"; then
41   echo "could not determine R_HOME"
42   exit 1
43fi
44CC=`"${R_HOME}/bin/R" CMD config CC`
45CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
46AC_PROG_CPP
47AC_PROG_CC
48
49FOUND_ALL="no"
50
51#
52# if users provide both PKG_CPPFLAGS *and* PKG_LIBS, then we're done!
53#
54test -n "${PKG_CPPFLAGS}" -a -n "${PKG_LIBS}" && FOUND_ALL="yes"
55
56#
57# does user want a particular SQLite installation/version (possibly
58# overriding system directories)?
59#
60AC_ARG_WITH(sqlite-dir,
61            [--with-sqlite-dir=DIR    specifies an existing SQLite base dir],
62            SQLITE_DIR="${with_sqlite_dir}",
63            SQLITE_DIR="")
64AC_ARG_WITH(sqlite-lib,
65            [--with-sqlite-lib=DIR    specifies an existing SQLite lib dir],
66            SQLITE_LIB="${with_sqlite_lib}",
67            SQLITE_LIB="")
68AC_ARG_WITH(sqlite-inc,
69            [--with-sqlite-inc=DIR    specifies an existing SQLite include dir],
70            SQLITE_INC="${with_sqlite_inc}",
71            SQLITE_INC="")
72#
73# Use SQLITE_DIR (if specified) to initialize SQLITE_{INC,LIB}
74# (handle the uniformative cases --with-no-sqlite or w.o. DIR values,
75# and make sure the various directories actually exist).  Ignore
76# with-sqlite-inc and with-sqlite-lib if with-sqlite-dir is present,
77# but issue a warning.
78#
79if test "${FOUND_ALL}" = "no"; then
80    if test -n "${SQLITE_DIR}" ; then
81       test ! -d "${SQLITE_DIR}" && \
82                  AC_MSG_ERROR([dir ${SQLITE_DIR} does not exist])
83       test -n "${SQLITE_INC}" && \
84                  AC_WARN([Using sqlite-dir and ignoring sqlite-inc])
85       test -n "${SQLITE_LIB}" && \
86                  AC_WARN([Using sqlite-dir and ignoring sqlite-lib])
87       SQLITE_INC="${SQLITE_DIR}/include"
88       SQLITE_LIB="${SQLITE_DIR}/lib"
89       test ! -d "${SQLITE_INC}" && \
90                  AC_MSG_ERROR([dir ${SQLITE_INC} does not exist])
91       test ! -d "${SQLITE_LIB}" && \
92                  AC_MSG_ERROR([dir ${SQLITE_LIB} does not exist])
93       PKG_LIBS="-L${SQLITE_LIB} -lsqlite3"
94       PKG_CPPFLAGS="-I${SQLITE_INC}"
95       FOUND_ALL="yes"
96    else
97       if test -n "${SQLITE_INC}" || test -n "${SQLITE_LIB}"; then
98          ## must have both
99          test -n "${SQLITE_INC}" && test -n "${SQLITE_LIB}" || \
100               AC_MSG_ERROR([must specify sqlite-inc and sqlite-lib])
101          ## must be dirs
102          test ! -d "${SQLITE_INC}" && \
103               AC_MSG_ERROR([sqlite-inc dir ${SQLITE_INC} does not exist])
104          test ! -d "${SQLITE_LIB}" && \
105               AC_MSG_ERROR([sqlite-lib dir ${SQLITE_LIB} does not exist])
106          PKG_LIBS="-L${SQLITE_LIB} -lsqlite3"
107          PKG_CPPFLAGS="-I${SQLITE_INC}"
108          FOUND_ALL="yes"
109       fi
110    fi
111fi
112
113
114if test "${FOUND_ALL}" = "no" ; then
115   # Since we installed successfully, now we set PKG_* vars and exit
116   SQLITE_OPTS="-DSQLITE_ENABLE_RTREE"
117   SQLITE_OPTS="${SQLITE_OPTS} -DSQLITE_ENABLE_FTS3"
118   SQLITE_OPTS="${SQLITE_OPTS} -DSQLITE_ENABLE_FTS3_PARENTHESIS"
119   SQLITE_OPTS="${SQLITE_OPTS} -DSQLITE_SOUNDEX"
120   SQLITE_OPTS="${SQLITE_OPTS} -DSQLITE_MAX_VARIABLE_NUMBER=40000"
121   SQLITE_OPTS="${SQLITE_OPTS} -DSQLITE_MAX_COLUMN=30000"
122
123   PKG_CPPFLAGS="-DRSQLITE_USE_BUNDLED_SQLITE $SQLITE_OPTS"
124   PKG_LIBS=""
125   AC_SEARCH_LIBS(fdatasync, [rt])
126   PKG_LIBS="${PKG_LIBS} $LIBS"
127   FOUND_ALL="yes"
128fi
129
130AC_SUBST(PKG_CPPFLAGS)
131AC_SUBST(PKG_LIBS)
132
133AC_OUTPUT(src/Makevars)
134
135exit 0
136