1# =========================================================================== 2# https://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 existence of SQLite 3. 16# 17# If no installation 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 18 40 41AC_DEFUN([AX_LIB_SQLITE3], 42[ 43 AC_REQUIRE([AX_EXT_HAVE_STATIC_LIB_DETECT]) 44 AC_ARG_WITH([sqlite3], 45 AS_HELP_STRING( 46 [--with-sqlite3=@<:@ARG@:>@], 47 [use SQLite 3 library @<:@default=yes@:>@, optionally specify the prefix for sqlite3 library] 48 ), 49 [ 50 if test "$withval" = "no"; then 51 WANT_SQLITE3="no" 52 elif test "$withval" = "yes"; then 53 WANT_SQLITE3="yes" 54 ac_sqlite3_path="" 55 else 56 WANT_SQLITE3="yes" 57 ac_sqlite3_path="$withval" 58 fi 59 ], 60 [WANT_SQLITE3="yes"] 61 ) 62 63 SQLITE3_CFLAGS="" 64 SQLITE3_LDFLAGS="" 65 SQLITE3_VERSION="" 66 67 if test "x$WANT_SQLITE3" = "xyes"; then 68 69 ac_sqlite3_header="sqlite3.h" 70 71 sqlite3_version_req=ifelse([$1], [], [3.0.0], [$1]) 72 sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([[0-9]]*\.[[0-9]]*\)'` 73 sqlite3_version_req_major=`expr $sqlite3_version_req : '\([[0-9]]*\)'` 74 sqlite3_version_req_minor=`expr $sqlite3_version_req : '[[0-9]]*\.\([[0-9]]*\)'` 75 sqlite3_version_req_micro=`expr $sqlite3_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` 76 if test "x$sqlite3_version_req_micro" = "x" ; then 77 sqlite3_version_req_micro="0" 78 fi 79 80 sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \ 81 \+ $sqlite3_version_req_minor \* 1000 \ 82 \+ $sqlite3_version_req_micro` 83 84 AC_MSG_CHECKING([for SQLite3 header]) 85 86 if test "$ac_sqlite3_path" != ""; then 87 ac_sqlite3_ldflags="-L$ac_sqlite3_path/${STATIC_LIBDIR_NAME}" 88 ac_sqlite3_cppflags="-I$ac_sqlite3_path/include" 89 AC_MSG_RESULT([explicitly set; $ac_sqlite3_path]) 90 else 91 for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do 92 if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \ 93 && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then 94 ac_sqlite3_path=$ac_sqlite3_path_tmp 95 ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include" 96 ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/${STATIC_LIBDIR_NAME}" 97 AC_MSG_RESULT([found; $ac_sqlite3_path_tmp/include/$ac_sqlite3_header]) 98 break; 99 fi 100 done 101 102 if test "$ac_sqlite3_path" = ""; then 103 AC_MSG_RESULT([not found]) 104 fi 105 fi 106 107 ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3" 108 109 saved_CPPFLAGS="$CPPFLAGS" 110 saved_LDFLAGS="$LDFLAGS" 111 CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags" 112 LDFLAGS="$LDFLAGS $ac_sqlite3_ldflags" 113 114 AC_LANG_PUSH(C) 115 116 AC_CHECK_HEADERS([sqlite3.h], [HAVE_SQLITE3=yes], [HAVE_SQLITE3=no]) 117 118 AS_IF([test "$HAVE_SQLITE3" = yes], [ 119 AC_CHECK_LIB([sqlite3], [sqlite3_open], [:], [HAVE_SQLITE3=no]) 120 ]) 121 122 AS_IF([test "$HAVE_SQLITE3" = yes], [ 123 AC_MSG_CHECKING([for SQLite3 library version >= $sqlite3_version_req]) 124 125 AC_COMPILE_IFELSE( 126 [ 127 AC_LANG_PROGRAM([[@%:@include <sqlite3.h>]], 128 [[ 129 #if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number) 130 /* Everything is okay */ 131 #else 132 # error SQLite version is too old 133 #endif 134 ]] 135 ) 136 ], 137 [ 138 AC_MSG_RESULT([yes]) 139 ], 140 [ 141 AC_MSG_RESULT([not found]) 142 HAVE_SQLITE3=no 143 ] 144 ) 145 ]) 146 147 AC_LANG_POP(C) 148 149 CPPFLAGS="$saved_CPPFLAGS" 150 LDFLAGS="$saved_LDFLAGS" 151 152 if test "$HAVE_SQLITE3" = "yes"; then 153 154 SQLITE3_CFLAGS="$ac_sqlite3_cppflags" 155 SQLITE3_LDFLAGS="$ac_sqlite3_ldflags" 156 157 ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header" 158 159 dnl Retrieve SQLite release version 160 if test "x$ac_sqlite3_header_path" != "x"; then 161 ac_sqlite3_version=`cat $ac_sqlite3_header_path \ 162 | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \ 163 | sed -e 's/"//'` 164 if test $ac_sqlite3_version != ""; then 165 SQLITE3_VERSION=$ac_sqlite3_version 166 else 167 AC_MSG_WARN([Cannot find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!]) 168 fi 169 fi 170 171 AC_SUBST(SQLITE3_CFLAGS) 172 AC_SUBST(SQLITE3_LDFLAGS) 173 AC_SUBST(SQLITE3_VERSION) 174 AC_SUBST(HAVE_SQLITE3) 175 AC_DEFINE([HAVE_SQLITE3], [1], [Have the SQLITE3 library]) 176 fi 177 fi 178]) 179