Jeff Thompson | dc2c430 | 2013-11-22 12:04:16 -0800 | [diff] [blame] | 1 | # =========================================================================== |
| 2 | # http://www.gnu.org/software/autoconf-archive/ax_lib_sqlite3.html |
| 3 | # =========================================================================== |
| 4 | # |
| 5 | # SYNOPSIS |
| 6 | # |
| 7 | # AX_LIB_SQLITE3([MINIMUM-VERSION]) |
| 8 | # |
| 9 | # DESCRIPTION |
| 10 | # |
| 11 | # Test for the SQLite 3 library of a particular version (or newer) |
| 12 | # |
| 13 | # This macro takes only one optional argument, required version of SQLite |
| 14 | # 3 library. If required version is not passed, 3.0.0 is used in the test |
| 15 | # of existance of SQLite 3. |
| 16 | # |
| 17 | # If no intallation prefix to the installed SQLite library is given the |
| 18 | # macro searches under /usr, /usr/local, and /opt. |
| 19 | # |
| 20 | # This macro calls: |
| 21 | # |
| 22 | # AC_SUBST(SQLITE3_CFLAGS) |
| 23 | # AC_SUBST(SQLITE3_LDFLAGS) |
| 24 | # AC_SUBST(SQLITE3_VERSION) |
| 25 | # |
| 26 | # And sets: |
| 27 | # |
| 28 | # HAVE_SQLITE3 |
| 29 | # |
| 30 | # LICENSE |
| 31 | # |
| 32 | # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net> |
| 33 | # |
| 34 | # Copying and distribution of this file, with or without modification, are |
| 35 | # permitted in any medium without royalty provided the copyright notice |
| 36 | # and this notice are preserved. This file is offered as-is, without any |
| 37 | # warranty. |
| 38 | |
| 39 | #serial 14 |
| 40 | |
| 41 | AC_DEFUN([AX_LIB_SQLITE3], |
| 42 | [ |
| 43 | AC_ARG_WITH([sqlite3], |
| 44 | AS_HELP_STRING( |
| 45 | [--with-sqlite3=@<:@ARG@:>@], |
| 46 | [use SQLite 3 library @<:@default=yes@:>@, optionally specify the prefix for sqlite3 library] |
| 47 | ), |
| 48 | [ |
| 49 | if test "$withval" = "no"; then |
| 50 | WANT_SQLITE3="no" |
| 51 | elif test "$withval" = "yes"; then |
| 52 | WANT_SQLITE3="yes" |
| 53 | ac_sqlite3_path="" |
| 54 | else |
| 55 | WANT_SQLITE3="yes" |
| 56 | ac_sqlite3_path="$withval" |
| 57 | fi |
| 58 | ], |
| 59 | [WANT_SQLITE3="yes"] |
| 60 | ) |
| 61 | |
| 62 | SQLITE3_CFLAGS="" |
| 63 | SQLITE3_LDFLAGS="" |
| 64 | SQLITE3_VERSION="" |
| 65 | |
| 66 | if test "x$WANT_SQLITE3" = "xyes"; then |
| 67 | |
| 68 | ac_sqlite3_header="sqlite3.h" |
| 69 | |
| 70 | sqlite3_version_req=ifelse([$1], [], [3.0.0], [$1]) |
| 71 | sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([[0-9]]*\.[[0-9]]*\)'` |
| 72 | sqlite3_version_req_major=`expr $sqlite3_version_req : '\([[0-9]]*\)'` |
| 73 | sqlite3_version_req_minor=`expr $sqlite3_version_req : '[[0-9]]*\.\([[0-9]]*\)'` |
| 74 | sqlite3_version_req_micro=`expr $sqlite3_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` |
| 75 | if test "x$sqlite3_version_req_micro" = "x" ; then |
| 76 | sqlite3_version_req_micro="0" |
| 77 | fi |
| 78 | |
| 79 | sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \ |
| 80 | \+ $sqlite3_version_req_minor \* 1000 \ |
| 81 | \+ $sqlite3_version_req_micro` |
| 82 | |
| 83 | AC_MSG_CHECKING([for SQLite3 library >= $sqlite3_version_req]) |
| 84 | |
| 85 | if test "$ac_sqlite3_path" != ""; then |
| 86 | ac_sqlite3_ldflags="-L$ac_sqlite3_path/lib" |
| 87 | ac_sqlite3_cppflags="-I$ac_sqlite3_path/include" |
| 88 | else |
| 89 | for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do |
| 90 | if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \ |
| 91 | && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then |
| 92 | ac_sqlite3_path=$ac_sqlite3_path_tmp |
| 93 | ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include" |
| 94 | ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/lib" |
| 95 | break; |
| 96 | fi |
| 97 | done |
| 98 | fi |
| 99 | |
| 100 | ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3" |
| 101 | |
| 102 | saved_CPPFLAGS="$CPPFLAGS" |
| 103 | CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags" |
| 104 | |
| 105 | AC_LANG_PUSH(C) |
| 106 | AC_COMPILE_IFELSE( |
| 107 | [ |
| 108 | AC_LANG_PROGRAM([[@%:@include <sqlite3.h>]], |
| 109 | [[ |
| 110 | #if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number) |
| 111 | /* Everything is okay */ |
| 112 | #else |
| 113 | # error SQLite version is too old |
| 114 | #endif |
| 115 | ]] |
| 116 | ) |
| 117 | ], |
| 118 | [ |
| 119 | AC_MSG_RESULT([yes]) |
| 120 | success="yes" |
| 121 | ], |
| 122 | [ |
| 123 | AC_MSG_RESULT([not found]) |
| 124 | success="no" |
| 125 | ] |
| 126 | ) |
| 127 | AC_LANG_POP(C) |
| 128 | |
| 129 | CPPFLAGS="$saved_CPPFLAGS" |
| 130 | |
| 131 | if test "$success" = "yes"; then |
| 132 | |
| 133 | SQLITE3_CFLAGS="$ac_sqlite3_cppflags" |
| 134 | SQLITE3_LDFLAGS="$ac_sqlite3_ldflags" |
| 135 | |
| 136 | ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header" |
| 137 | |
| 138 | dnl Retrieve SQLite release version |
| 139 | if test "x$ac_sqlite3_header_path" != "x"; then |
| 140 | ac_sqlite3_version=`cat $ac_sqlite3_header_path \ |
| 141 | | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \ |
| 142 | | sed -e 's/"//'` |
| 143 | if test $ac_sqlite3_version != ""; then |
| 144 | SQLITE3_VERSION=$ac_sqlite3_version |
| 145 | else |
| 146 | AC_MSG_WARN([Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!]) |
| 147 | fi |
| 148 | fi |
| 149 | |
| 150 | AC_SUBST(SQLITE3_CFLAGS) |
| 151 | AC_SUBST(SQLITE3_LDFLAGS) |
| 152 | AC_SUBST(SQLITE3_VERSION) |
| 153 | AC_DEFINE([HAVE_SQLITE3], [], [Have the SQLITE3 library]) |
| 154 | fi |
| 155 | fi |
| 156 | ]) |