source: trunk/m4/sqlite.m4 @ 704

Revision 690, 8.1 KB checked in by dcarter, 3 years ago (diff)

close #134: Add checks for sqlite3_prepare_v2 and sqlite3_clear_bindings

Line 
1# Copyright (C) 2005-2008 David Carter <arm4@arm4.org>
2
3# This file is free software; as a special exception the author gives
4# unlimited permission to copy and/or distribute it, with or without
5# modifications, as long as this notice is preserved.
6#
7# This program is distributed in the hope that it will be useful, but
8# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
9# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
11# Macros to check the version for the Sqlite library, and to set whatever link flags are appropriate
12
13AC_DEFUN([__ARM4_SQLITE_CHECK_CLEAR_BINDINGS],
14[
15  AC_MSG_CHECKING(for sqlite3_clear_bindings)
16  SQLITE_LIBS="$1"
17  ac_save_LIBS="$LIBS"
18  LIBS="$LIBS $SQLITE_LIBS"
19  no_clear_bindings=""
20  AC_LINK_IFELSE([
21#include <sqlite3.h>
22#include <stdlib.h>
23
24main ()
25{
26        sqlite3_stmt *statement_ptr;
27        sqlite3_clear_bindings(statement_ptr);
28}
29], ,[no_clear_bindings="yes"])
30  LIBS="$ac_save_libs"
31  if test "x$no_clear_bindings" == "x" ; then
32    AC_DEFINE(HAVE_SQLITE_CLEAR_BINDINGS, 1,
33      [Defines wether the Sqlite function sqlite3_clear_bindings is supported by this library version])
34    AC_MSG_RESULT(yes)
35  else
36    AC_MSG_RESULT(no)
37  fi
38])
39
40AC_DEFUN([__ARM4_SQLITE_CHECK_PREPARE_V2],
41[
42  AC_MSG_CHECKING(for sqlite3_prepare_v2)
43  SQLITE_LIBS="$1"
44  ac_save_LIBS="$LIBS"
45  LIBS="$LIBS $SQLITE_LIBS"
46  no_prepare_v2=""
47  AC_LINK_IFELSE([
48#include <sqlite3.h>
49#include <stdlib.h>
50
51main ()
52{
53        sqlite3 *db_ptr;
54        sqlite3_stmt *statement_ptr;
55        sqlite3_prepare_v2(db_ptr, "test", 4, &statement_ptr, NULL);
56}
57], ,[no_prepare_v2="yes"])
58  LIBS="$ac_save_libs"
59  if test "x$no_prepare_v2" == "x" ; then
60    AC_DEFINE(HAVE_SQLITE_PREPARE_V2, 1,
61      [Defines wether the Sqlite function sqlite3_prepare_v2 is supported by this library version])
62    AC_MSG_RESULT(yes)
63  else
64    AC_MSG_RESULT(no)
65  fi
66])
67
68AC_DEFUN([__ARM4_SQLITE_CHECK_OPEN_V2],
69[
70  AC_MSG_CHECKING(for sqlite3_open_v2)
71  SQLITE_LIBS="$1"
72  ac_save_LIBS="$LIBS"
73  LIBS="$LIBS $SQLITE_LIBS"
74  no_open_v2=""
75  AC_LINK_IFELSE([
76#include <sqlite3.h>
77#include <stdlib.h>
78
79main ()
80{
81        sqlite3 *db_ptr;
82        sqlite3_open_v2 ("dummy", &db_ptr, SQLITE_OPEN_READONLY, NULL);
83}
84], ,[no_open_v2="yes"])
85  LIBS="$ac_save_libs"
86  if test "x$no_open_v2" == "x" ; then
87    AC_DEFINE(HAVE_SQLITE_OPEN_V2, 1,
88      [Defines wether the Sqlite function sqlite3_open_v2 is supported by this library version])
89    AC_MSG_RESULT(yes)
90  else
91    AC_MSG_RESULT(no)
92  fi
93])
94
95AC_DEFUN([__ARM4_SQLITE_CHECKLINK],
96[
97  SQLITE_LIBS="$1"
98  ac_save_LIBS="$LIBS"
99  LIBS="$LIBS $SQLITE_LIBS"
100  AC_LINK_IFELSE([
101#include <sqlite3.h>
102
103main ()
104{
105        sqlite3_close (0);
106}
107], ,[SQLITE_LIBS=""])
108  LIBS="$ac_save_libs"
109  AC_SUBST(SQLITE_LIBS)
110])
111
112AC_DEFUN([__ARM4_SQLITE_CHECK_VERSION],
113[
114  min_sqlite_version=ifelse([$1], ,3.3,$1)
115  sqlite="$2"
116  sqlite_path="$3"
117
118  if test "x$sqlite_path" = x ; then
119    AC_PATH_PROG(SQLITE_STAT, $sqlite, no,)
120  else
121    AC_PATH_PROG(SQLITE_STAT, $sqlite, no, [$sqlite_path])
122  fi
123  no_sqlite=""
124  if test "$SQLITE_STAT" = "no" ; then
125    no_sqlite=yes
126    AC_MSG_ERROR([unable to find $sqlite program $sqlite_path])
127  else
128    AC_MSG_CHECKING(for sqlite - version >= $min_sqlite_version)
129    sqlite_major_version=`$SQLITE_STAT -version | \
130         sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\1/'`
131    if test "x${sqlite_major_version}" = "x" ; then
132       sqlite_major_version=0
133    fi
134
135    sqlite_minor_version=`$SQLITE_STAT -version | \
136         sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\2/'`
137    if test "x${sqlite_minor_version}" = "x" ; then
138       sqlite_minor_version=0
139    fi
140
141    sqlite_micro_version=`$SQLITE_STAT -version | \
142         sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\3/'`
143    if test "x${sqlite_micro_version}" = "x" ; then
144       sqlite_micro_version=0
145    fi
146
147    enable_sqlitetest=yes
148    if test "x$enable_sqlitetest" = "xyes" ; then
149      rm -f conf.sqlitetest
150      AC_RUN_IFELSE([
151#include <stdio.h>
152#include <stdlib.h>
153#include <string.h>
154
155char* my_strdup (const char *str);
156
157char*
158my_strdup (const char *str)
159{
160  char *new_str;
161 
162  if (str)
163    {
164      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
165      strcpy (new_str, str);
166    }
167  else
168    new_str = NULL;
169 
170  return new_str;
171}
172
173int main (void)
174{
175  int major = 0, minor = 0, micro = 0;
176  int n;
177  char *tmp_version;
178
179  system ("touch conf.sqlitetest");
180
181  /* HP/UX 9 (%@#!) writes to sscanf strings */
182  tmp_version = my_strdup("$min_sqlite_version");
183
184  n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) ;
185
186  if (n != 2 && n != 3) {
187     printf("%s, bad version string\n", "$min_sqlite_version");
188     exit(1);
189   }
190
191   if (($sqlite_major_version > major) ||
192      (($sqlite_major_version == major) && ($sqlite_minor_version > minor)) ||
193      (($sqlite_major_version == major) && ($sqlite_minor_version == minor) && ($sqlite_micro_version >= micro)))
194    {
195      exit(0);
196    }
197  else
198    {
199      printf("\n*** 'sqlite3 -version' returned %d.%d.%d, but the minimum version\n", $sqlite_major_version, $sqlite_minor_version, $sqlite_micro_version);
200      printf("*** of sqlite3 required is %d.%d.%d. If sqlite3 is correct, then it is\n", major, minor, micro);
201      printf("*** best to upgrade to the required version.\n");
202      exit(1);
203    }
204}
205
206],, no_sqlite=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
207    fi
208  fi
209  if test "x$no_sqlite" = x ; then
210    AC_MSG_RESULT(yes)
211  else
212    AC_MSG_ERROR([sqlite version $min_sqlite_version or greater is required])
213  fi
214])
215
216AC_DEFUN([ARM4_VERSION_SQLITE],
217[
218  min_sqlite_version=ifelse([$1], ,3.3,$1)
219
220  sqlite_found="no"
221  sqlite_root=""
222  AC_MSG_CHECKING(for sqlite root)
223  AC_ARG_WITH(sqlite,
224  [  --with-sqlite=PATH      path to the sqlite root],
225  [
226    if test "$withval" = "no" || test "$withval" = "yes"; then
227      AC_MSG_ERROR([--with-sqlite requires the path to the sqlite root to be provided])
228    fi
229
230    if test -d "$withval" > /dev/null 2>&1 ; then
231      sqlite_found="yes"
232      sqlite_root="$withval"
233    fi
234
235    dnl if --with-sqlite is used, it is a fatal error for its argument
236    dnl to be invalid
237    if test "$sqlite_found" != "yes"; then
238      AC_MSG_ERROR([the --with-sqlite parameter is incorrect. It must specify the path to the sqlite root.])
239    fi
240  ],[
241    sqlite_found="yes"
242        sqlite_root="/usr"
243  ])
244  AC_MSG_RESULT($sqlite_root)
245
246  if test "$sqlite_found" = "yes"; then
247    if test "x$sqlite_root" = "x" ; then
248      AC_CHECK_HEADERS([sqlite3.h],,[AC_MSG_ERROR(unable to find sqlite header file)],)
249      __ARM4_SQLITE_CHECK_VERSION([$min_sqlite_version], [sqlite3])
250      AC_MSG_CHECKING(for sqlite flags)
251      __ARM4_SQLITE_CHECKLINK([-lsqlite3])
252      if test "x$SQLITE_LIBS" = "x" ; then
253        __ARM4_SQLITE_CHECKLINK([-lsqlite3 -lrt])
254      fi
255      AC_MSG_RESULT($SQLITE_LIBS)
256    else
257      CPPFLAGS="-I$sqlite_root/include $CPPFLAGS"
258      AC_CHECK_HEADERS([sqlite3.h],,[AC_MSG_ERROR(unable to find sqlite header file)],)
259      __ARM4_SQLITE_CHECK_VERSION([$min_sqlite_version], [sqlite3], [$sqlite_root/bin])
260      AC_MSG_CHECKING(for sqlite flags)
261      __ARM4_SQLITE_CHECKLINK([-L$sqlite_root/lib -lsqlite3])
262      if test "x$SQLITE_LIBS" = "x" ; then
263        __ARM4_SQLITE_CHECKLINK([-L$sqlite_root/lib -lsqlite3 -lrt])
264      fi
265      AC_MSG_RESULT($SQLITE_LIBS)
266    fi
267    if test "x$SQLITE_LIBS" = "x" ; then
268      AC_MSG_ERROR([unable to link $sqlite])
269    fi
270  fi
271])
272
273AC_DEFUN([ARM4_CHECK_SQLITE],
274[
275  min_sqlite_version=ifelse([$1], ,3.3,$1)
276
277  AC_MSG_CHECKING(for Sqlite)
278  AC_ARG_ENABLE(sqlite,
279  [  --enable-sqlite         enable Sqlite database back end],
280  [case "${enableval}" in
281     yes) sqlite=yes ;;
282     no)  sqlite=no ;;
283     *) AC_MSG_ERROR([bad value ${enableval} for --enable-sqlite]) ;;
284   esac],
285  [sqlite=no])
286  AC_MSG_RESULT($sqlite)
287  AM_CONDITIONAL([BUILD_SQLITE], [test "$sqlite" = "yes" ])
288  if test "$sqlite" = "yes" ; then
289    ARM4_VERSION_SQLITE([$min_sqlite_version])
290    AC_DEFINE(HAVE_SQLITE, 1,
291      [Define wether the Sqlite back end is implemented on this platform])
292    __ARM4_SQLITE_CHECK_OPEN_V2([$SQLITE_LIBS])
293    __ARM4_SQLITE_CHECK_PREPARE_V2([$SQLITE_LIBS])
294    __ARM4_SQLITE_CHECK_CLEAR_BINDINGS([$SQLITE_LIBS])
295  fi
296])
Note: See TracBrowser for help on using the repository browser.