downgrade memory unlock failures to info level and fix function name in log output
[sqlcipher.git] / configure.ac
blob50273b4932b0d9590f5a4dd6da1bf60d8d9852cb
2 # The build process allows for using a cross-compiler.  But the default
3 # action is to target the same platform that we are running on.  The
4 # configure script needs to discover the following properties of the 
5 # build and target systems:
7 #    srcdir
9 #        The is the name of the directory that contains the
10 #        "configure" shell script.  All source files are
11 #        located relative to this directory.
13 #    bindir
15 #        The name of the directory where executables should be
16 #        written by the "install" target of the makefile.
18 #    program_prefix
20 #        Add this prefix to the names of all executables that run
21 #        on the target machine.  Default: ""
23 #    ENABLE_SHARED
25 #        True if shared libraries should be generated.
27 #    BUILD_CC
29 #        The name of a command that is used to convert C
30 #        source files into executables that run on the build
31 #        platform.
33 #    BUILD_CFLAGS
35 #        Switches that the build compiler needs in order to construct
36 #        command-line programs.
38 #    BUILD_LIBS
40 #        Libraries that the build compiler needs in order to construct
41 #        command-line programs.
43 #    BUILD_EXEEXT
45 #        The filename extension for executables on the build
46 #        platform.  "" for Unix and ".exe" for Windows.
48 #    TCL_*
50 #        Lots of values are read in from the tclConfig.sh script,
51 #        if that script is available.  This values are used for
52 #        constructing and installing the TCL extension.
54 #    TARGET_READLINE_LIBS
56 #        This is the library directives passed to the target linker
57 #        that cause the executable to link against the readline library.
58 #        This might be a switch like "-lreadline" or pathnames of library
59 #        file like "../../src/libreadline.a".
61 #    TARGET_READLINE_INC
63 #        This variables define the directory that contain header
64 #        files for the readline library.  If the compiler is able 
65 #        to find <readline.h> on its own, then this can be blank.
67 #    TARGET_EXEEXT
69 #        The filename extension for executables on the
70 #        target platform.  "" for Unix and ".exe" for windows.
72 # This configure.in file is easy to reuse on other projects.  Just
73 # change the argument to AC_INIT.  And disable any features that
74 # you don't need (for example BLT) by erasing or commenting out
75 # the corresponding code.
77 AC_INIT([sqlcipher],m4_esyscmd(cat VERSION | tr -d '\n'))
79 dnl Make sure the local VERSION file matches this configure script
80 sqlite_version_sanity_check=`cat $srcdir/VERSION | tr -d '\n'`
81 if test "$PACKAGE_VERSION" != "$sqlite_version_sanity_check" ; then
82 AC_MSG_ERROR([configure script is out of date:
83  configure \$PACKAGE_VERSION = $PACKAGE_VERSION
84  top level VERSION file     = $sqlite_version_sanity_check
85 please regen with autoconf])
88 #########
89 # Programs needed
91 LT_INIT
92 AC_PROG_INSTALL
94 #########
95 # Enable large file support (if special flags are necessary)
97 AC_SYS_LARGEFILE
99 #########
100 # Check for needed/wanted data types
101 AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, intptr_t, uint8_t,
102                 uint16_t, uint32_t, uint64_t, uintptr_t])
104 #########
105 # Check for needed/wanted headers
106 AC_CHECK_HEADERS([sys/types.h stdlib.h stdint.h inttypes.h malloc.h])
108 #########
109 # Figure out whether or not we have these functions
111 AC_CHECK_FUNCS([fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64])
113 #########
114 # By default, we use the amalgamation (this may be changed below...)
116 USE_AMALGAMATION=1
118 #########
119 # See whether we can run specific tclsh versions known to work well;
120 # if not, then we fall back to plain tclsh.
121 # TODO: try other versions before falling back?
123 AC_CHECK_PROGS(TCLSH_CMD, [tclsh8.7 tclsh8.6 tclsh8.5 tclsh], none)
124 if test "$TCLSH_CMD" = "none"; then
125   # If we can't find a local tclsh, then building the amalgamation will fail.
126   # We act as though --disable-amalgamation has been used.
127   echo "Warning: can't find tclsh - defaulting to non-amalgamation build."
128   USE_AMALGAMATION=0
129   TCLSH_CMD="tclsh"
131 AC_SUBST(TCLSH_CMD)
133 AC_ARG_VAR([TCLLIBDIR], [Where to install tcl plugin])
134 if test "x${TCLLIBDIR+set}" != "xset" ; then
135   TCLLIBDIR='$(libdir)'
136   for i in `echo 'puts stdout $auto_path' | ${TCLSH_CMD}` ; do
137     if test -d $i ; then
138       TCLLIBDIR=$i
139       break
140     fi
141   done
142   TCLLIBDIR="${TCLLIBDIR}/sqlite3"
145 #########
146 # Set up an appropriate program prefix
148 if test "$program_prefix" = "NONE"; then
149   program_prefix=""
151 AC_SUBST(program_prefix)
153 VERSION=[`cat $srcdir/VERSION | sed 's/^\([0-9]*\.*[0-9]*\).*/\1/'`]
154 AC_MSG_NOTICE(Version set to $VERSION)
155 AC_SUBST(VERSION)
156 RELEASE=`cat $srcdir/VERSION`
157 AC_MSG_NOTICE(Release set to $RELEASE)
158 AC_SUBST(RELEASE)
160 ##########
161 # Handle --with-wasi-sdk=DIR
163 # This must be early because it changes the toolchain.
165 AC_ARG_WITH(wasi-sdk,
166 AS_HELP_STRING([--with-wasi-sdk=DIR],
167        [directory containing the WASI SDK. Triggers cross-compile to WASM.]), with_wasisdk=${withval})
168 AC_MSG_CHECKING([for WASI SDK directory])
169 AC_CACHE_VAL(ac_cv_c_wasi_sdk,[
170   # First check to see if --with-tcl was specified.
171   if test x"${with_wasi_sdk}" != x ; then
172     if ! test -d "${with_wasi_sdk}" ; then
173       AC_MSG_ERROR([${with_wasi_sdk} directory doesn't exist])
174     fi
175     AC_MSG_RESULT([${with_wasi_sdk}: using wasi-sdk clang, disabling: tcl, CLI shell, DLL])
176     use_wasi_sdk=yes
177   else
178     use_wasi_sdk=no
179   fi
181 if test "${use_wasi_sdk}" = "no" ; then
182   HAVE_WASI_SDK=""
183   AC_MSG_RESULT([no])
184 else
185   HAVE_WASI_SDK=1
186 # Changing --host and --target have no effect here except to possibly
187 # cause confusion. autoconf has finished processing them by this
188 # point.
190 #  host_alias=wasm32-wasi
191 #  target=wasm32-wasi
193 # Merely changing CC and LD to the wasi-sdk's is enough to get
194 # sqlite3.o building in WASM format.
195   CC="${with_wasi_sdk}/bin/clang"
196   LD="${with_wasi_sdk}/bin/wasm-ld"
197   RANLIB="${with_wasi_sdk}/bin/llvm-ranlib"
198   cross_compiling=yes
199   enable_threadsafe=no
200   use_tcl=no
201   enable_tcl=no
202   # libtool is apparently hard-coded to use gcc for linking DLLs, so
203   # we disable the DLL build...
204   enable_shared=no
205   AC_MSG_RESULT([yes])
207 AC_SUBST(HAVE_WASI_SDK)
210 #########
211 # Locate a compiler for the build machine.  This compiler should
212 # generate command-line programs that run on the build machine.
214 if test x"$cross_compiling" = xno; then
215         BUILD_CC=$CC
216         BUILD_CFLAGS=$CFLAGS
217 else
218         if test "${BUILD_CC+set}" != set; then
219                 AC_CHECK_PROGS(BUILD_CC, gcc cc cl)
220         fi
221         if test "${BUILD_CFLAGS+set}" != set; then
222                 BUILD_CFLAGS="-g"
223         fi
225 AC_SUBST(BUILD_CC)
227 ##########
228 # Do we want to support multithreaded use of sqlite
230 AC_ARG_ENABLE(threadsafe, 
231 AS_HELP_STRING([--disable-threadsafe],[Disable mutexing]))
232 AC_MSG_CHECKING([whether to support threadsafe operation])
233 if test "$enable_threadsafe" = "no"; then
234   SQLITE_THREADSAFE=0
235   AC_MSG_RESULT([no])
236 else
237   SQLITE_THREADSAFE=1
238   AC_MSG_RESULT([yes])
240 AC_SUBST(SQLITE_THREADSAFE)
242 if test "$SQLITE_THREADSAFE" = "1"; then
243   AC_SEARCH_LIBS(pthread_create, pthread)
244   AC_SEARCH_LIBS(pthread_mutexattr_init, pthread)
247 ##########
248 # Which crypto library do we use
250 AC_ARG_WITH([crypto-lib],
251 AC_HELP_STRING([--with-crypto-lib],[Specify which crypto library to use]),
252 crypto_lib=$withval)
253 AC_MSG_CHECKING([for crypto library to use])
254 if test "$crypto_lib" = "none"; then
255   AC_MSG_RESULT([none])
256 else
257   if test "$crypto_lib" = "commoncrypto"; then
258     CFLAGS="$CFLAGS -DSQLCIPHER_CRYPTO_CC"
259     BUILD_CFLAGS="$BUILD_CFLAGS -DSQLCIPHER_CRYPTO_CC"
260           AC_MSG_RESULT([commoncrypto])
261   else
262     if test "$crypto_lib" = "libtomcrypt"; then
263       CFLAGS="$CFLAGS -DSQLCIPHER_CRYPTO_LIBTOMCRYPT"
264       BUILD_CFLAGS="$BUILD_CFLAGS -DSQLCIPHER_CRYPTO_LIBTOMCRYPT"
265       AC_MSG_RESULT([libtomcrypt])
266       AC_CHECK_LIB([tomcrypt], [register_cipher], ,
267                    AC_MSG_ERROR([Library crypto not found. Install libtomcrypt!"]))
268     else
269       if test "$crypto_lib" = "nss"; then
270         CFLAGS="$CFLAGS -DSQLCIPHER_CRYPTO_NSS"
271         BUILD_CFLAGS="$BUILD_CFLAGS -DSQLCIPHER_CRYPTO_NSS"
272         AC_MSG_RESULT([nss3])
273         AC_CHECK_LIB([nss3], [PK11_Decrypt], ,
274                      AC_MSG_ERROR([Library crypto not found. Install nss!"]))
275       else
276         CFLAGS="$CFLAGS -DSQLCIPHER_CRYPTO_OPENSSL"
277         BUILD_CFLAGS="$BUILD_CFLAGS -DSQLCIPHER_CRYPTO_OPENSSL"
278               AC_MSG_RESULT([openssl])
279         AC_CHECK_LIB([crypto], [HMAC_Init_ex], ,
280                      AC_MSG_ERROR([Library crypto not found. Install openssl!"]))
281       fi
282     fi
283   fi
286 ##########
287 # Do we want to allow a connection created in one thread to be used
288 # in another thread.  This does not work on many Linux systems (ex: RedHat 9)
289 # due to bugs in the threading implementations.  This is thus off by default.
291 AC_ARG_ENABLE(cross-thread-connections, 
292 AC_HELP_STRING([--enable-cross-thread-connections],[Allow connection sharing across threads]),,enable_xthreadconnect=no)
293 AC_MSG_CHECKING([whether to allow connections to be shared across threads])
294 if test "$enable_xthreadconnect" = "no"; then
295   XTHREADCONNECT=''
296   AC_MSG_RESULT([no])
297 else
298   XTHREADCONNECT='-DSQLITE_ALLOW_XTHREAD_CONNECT=1'
299   AC_MSG_RESULT([yes])
301 AC_SUBST(XTHREADCONNECT)
303 ##########
304 # Do we want to support release
306 AC_ARG_ENABLE(releasemode, 
307 AS_HELP_STRING([--enable-releasemode],[Support libtool link to release mode]),,enable_releasemode=no)
308 AC_MSG_CHECKING([whether to support shared library linked as release mode or not])
309 if test "$enable_releasemode" = "no"; then
310   ALLOWRELEASE=""
311   AC_MSG_RESULT([no])
312 else
313   ALLOWRELEASE="-release `cat $srcdir/VERSION`"
314   AC_MSG_RESULT([yes])
316 AC_SUBST(ALLOWRELEASE)
318 ##########
319 # Do we want temporary databases in memory
321 AC_ARG_ENABLE(tempstore, 
322 AS_HELP_STRING([--enable-tempstore],[Use an in-ram database for temporary tables (never,no,yes,always)]),,enable_tempstore=no)
323 AC_MSG_CHECKING([whether to use an in-ram database for temporary tables])
324 case "$enable_tempstore" in
325   never ) 
326     TEMP_STORE=0
327     AC_MSG_RESULT([never])
328   ;;
329   no ) 
330     TEMP_STORE=1
331     AC_MSG_RESULT([no])
332   ;;
333   yes ) 
334      TEMP_STORE=2
335     AC_MSG_RESULT([yes])
336   ;;
337   always ) 
338      TEMP_STORE=3
339     AC_MSG_RESULT([always])
340   ;;
341   * ) 
342     TEMP_STORE=1
343     AC_MSG_RESULT([no])
344   ;;
345 esac
347 AC_SUBST(TEMP_STORE)
349 ###########
350 # Lots of things are different if we are compiling for Windows using
351 # the CYGWIN environment.  So check for that special case and handle
352 # things accordingly.
354 AC_MSG_CHECKING([if executables have the .exe suffix])
355 if test "$config_BUILD_EXEEXT" = ".exe"; then
356   CYGWIN=yes
357   AC_MSG_RESULT(yes)
358 else
359   AC_MSG_RESULT(unknown)
361 if test "$CYGWIN" != "yes"; then
362   m4_warn([obsolete],
363 [AC_CYGWIN is obsolete: use AC_CANONICAL_HOST and check if $host_os
364 matches *cygwin*])dnl
365 AC_CANONICAL_HOST
366 case $host_os in
367   *cygwin* ) CYGWIN=yes;;
368          * ) CYGWIN=no;;
369 esac
372 if test "$CYGWIN" = "yes"; then
373   BUILD_EXEEXT=.exe
374 else
375   BUILD_EXEEXT=$EXEEXT
377 if test x"$cross_compiling" = xno; then
378   TARGET_EXEEXT=$BUILD_EXEEXT
379 else
380   TARGET_EXEEXT=$config_TARGET_EXEEXT
382 if test "$TARGET_EXEEXT" = ".exe"; then
383   SQLITE_OS_UNIX=0
384   SQLITE_OS_WIN=1
385   CFLAGS="$CFLAGS -DSQLITE_OS_WIN=1"
386 else
387   SQLITE_OS_UNIX=1
388   SQLITE_OS_WIN=0
389   CFLAGS="$CFLAGS -DSQLITE_OS_UNIX=1"
392 AC_SUBST(BUILD_EXEEXT)
393 AC_SUBST(SQLITE_OS_UNIX)
394 AC_SUBST(SQLITE_OS_WIN)
395 AC_SUBST(TARGET_EXEEXT)
397 ##########
398 # Figure out all the parameters needed to compile against Tcl.
400 # This code is derived from the SC_PATH_TCLCONFIG and SC_LOAD_TCLCONFIG
401 # macros in the in the tcl.m4 file of the standard TCL distribution.
402 # Those macros could not be used directly since we have to make some
403 # minor changes to accomodate systems that do not have TCL installed.
405 AC_ARG_ENABLE(tcl, AS_HELP_STRING([--disable-tcl],[do not build TCL extension]),
406       [use_tcl=$enableval],[use_tcl=yes])
407 if test "${use_tcl}" = "yes" ; then
408   AC_ARG_WITH(tcl, AS_HELP_STRING([--with-tcl=DIR],[directory containing tcl configuration (tclConfig.sh)]), with_tclconfig=${withval})
409   AC_MSG_CHECKING([for Tcl configuration])
410   AC_CACHE_VAL(ac_cv_c_tclconfig,[
411     # First check to see if --with-tcl was specified.
412     if test x"${with_tclconfig}" != x ; then
413       if test -f "${with_tclconfig}/tclConfig.sh" ; then
414         ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
415       else
416         AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
417       fi
418     fi
420     # Start autosearch by asking tclsh
421     if test x"${ac_cv_c_tclconfig}" = x ; then
422       if test x"$cross_compiling" = xno; then
423         for i in `echo 'puts stdout $auto_path' | ${TCLSH_CMD}`
424         do
425           if test -f "$i/tclConfig.sh" ; then
426             ac_cv_c_tclconfig="$i"
427             break
428           fi
429         done
430       fi
431     fi
433     # On ubuntu 14.10, $auto_path on tclsh is not quite correct.
434     # So try again after applying corrections.
435     if test x"${ac_cv_c_tclconfig}" = x ; then
436       if test x"$cross_compiling" = xno; then
437         for i in `echo 'puts stdout $auto_path' | ${TCLSH_CMD} | sed 's,/tcltk/tcl,/tcl,g'`
438         do
439           if test -f "$i/tclConfig.sh" ; then
440             ac_cv_c_tclconfig="$i"
441             break
442           fi
443         done
444       fi
445     fi
447     # Recent versions of Xcode on Macs hid the tclConfig.sh file
448     # in a strange place.
449     if test x"${ac_cv_c_tclconfig}" = x ; then
450       if test x"$cross_compiling" = xno; then
451         for i in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.sdk/usr/lib
452         do
453           if test -f "$i/tclConfig.sh" ; then
454             ac_cv_c_tclconfig="$i"
455             break
456           fi
457         done
458       fi
459     fi
461     # then check for a private Tcl installation
462     if test x"${ac_cv_c_tclconfig}" = x ; then
463       for i in \
464             ../tcl \
465             `ls -dr ../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
466             `ls -dr ../tcl[[8-9]].[[0-9]] 2>/dev/null` \
467             `ls -dr ../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
468             ../../tcl \
469             `ls -dr ../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
470             `ls -dr ../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
471             `ls -dr ../../tcl[[8-9]].[[0-9]]* 2>/dev/null` \
472             ../../../tcl \
473             `ls -dr ../../../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
474             `ls -dr ../../../tcl[[8-9]].[[0-9]] 2>/dev/null` \
475             `ls -dr ../../../tcl[[8-9]].[[0-9]]* 2>/dev/null`
476       do
477         if test -f "$i/unix/tclConfig.sh" ; then
478           ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
479           break
480         fi
481       done
482     fi
484     # check in a few common install locations
485     if test x"${ac_cv_c_tclconfig}" = x ; then
486       for i in \
487             `ls -d ${libdir} 2>/dev/null` \
488             `ls -d /usr/local/lib 2>/dev/null` \
489             `ls -d /usr/contrib/lib 2>/dev/null` \
490             `ls -d /usr/lib 2>/dev/null`
491       do
492         if test -f "$i/tclConfig.sh" ; then
493            ac_cv_c_tclconfig=`(cd $i; pwd)`
494            break
495         fi
496       done
497     fi
499     # check in a few other private locations
500     if test x"${ac_cv_c_tclconfig}" = x ; then
501       for i in \
502          ${srcdir}/../tcl \
503          `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]].[[0-9]]* 2>/dev/null` \
504          `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]] 2>/dev/null` \
505          `ls -dr ${srcdir}/../tcl[[8-9]].[[0-9]]* 2>/dev/null`
506       do
507         if test -f "$i/unix/tclConfig.sh" ; then
508           ac_cv_c_tclconfig=`(cd $i/unix; pwd)`
509           break
510         fi
511       done
512     fi
513   ])
515   if test x"${ac_cv_c_tclconfig}" = x ; then
516     use_tcl=no
517     AC_MSG_WARN(Can't find Tcl configuration definitions)
518     AC_MSG_WARN(*** Without Tcl the regression tests cannot be executed ***)
519     AC_MSG_WARN(*** Consider using --with-tcl=... to define location of Tcl ***)
520   else
521     TCL_BIN_DIR=${ac_cv_c_tclconfig}
522     AC_MSG_RESULT(found $TCL_BIN_DIR/tclConfig.sh)
524     AC_MSG_CHECKING([for existence of $TCL_BIN_DIR/tclConfig.sh])
525     if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
526       AC_MSG_RESULT([loading])
527       . $TCL_BIN_DIR/tclConfig.sh
528     else
529       AC_MSG_RESULT([file not found])
530     fi
531     
532     #
533     # If the TCL_BIN_DIR is the build directory (not the install directory),
534     # then set the common variable name to the value of the build variables.
535     # For example, the variable TCL_LIB_SPEC will be set to the value
536     # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
537     # instead of TCL_BUILD_LIB_SPEC since it will work with both an
538     # installed and uninstalled version of Tcl.
539     #
540     
541     if test -f $TCL_BIN_DIR/Makefile ; then
542       TCL_LIB_SPEC=${TCL_BUILD_LIB_SPEC}
543       TCL_STUB_LIB_SPEC=${TCL_BUILD_STUB_LIB_SPEC}
544       TCL_STUB_LIB_PATH=${TCL_BUILD_STUB_LIB_PATH}
545     fi
546     
547     #
548     # eval is required to do the TCL_DBGX substitution
549     #
550     
551     eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\""
552     eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\""
553     eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\""
554     
555     eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\""
556     eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\""
557     eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\""
558     
559     AC_SUBST(TCL_VERSION)
560     AC_SUBST(TCL_BIN_DIR)
561     AC_SUBST(TCL_SRC_DIR)
562     AC_SUBST(TCL_INCLUDE_SPEC)
563     
564     AC_SUBST(TCL_LIB_FILE)
565     AC_SUBST(TCL_LIB_FLAG)
566     AC_SUBST(TCL_LIB_SPEC)
567     
568     AC_SUBST(TCL_STUB_LIB_FILE)
569     AC_SUBST(TCL_STUB_LIB_FLAG)
570     AC_SUBST(TCL_STUB_LIB_SPEC)
571     AC_SUBST(TCL_SHLIB_SUFFIX)
572   fi
574 if test "${use_tcl}" = "no" ; then
575   HAVE_TCL=""
576 else
577   HAVE_TCL=1
579 AC_SUBST(HAVE_TCL)
581 ##########
582 # Figure out what C libraries are required to compile programs
583 # that use "readline()" library.
585 TARGET_READLINE_LIBS=""
586 TARGET_READLINE_INC=""
587 TARGET_HAVE_READLINE=0
588 TARGET_HAVE_EDITLINE=0
589 AC_ARG_ENABLE([editline],
590         [AS_HELP_STRING([--enable-editline],[enable BSD editline support])],
591         [with_editline=$enableval],
592         [with_editline=auto])
593 AC_ARG_ENABLE([readline],
594         [AS_HELP_STRING([--disable-readline],[disable readline support])],
595         [with_readline=$enableval],
596         [with_readline=auto])
598 if test x"$with_editline" != xno; then
599         sLIBS=$LIBS
600         LIBS=""
601         TARGET_HAVE_EDITLINE=1
602         AC_SEARCH_LIBS(readline,edit,[with_readline=no],[TARGET_HAVE_EDITLINE=0])
603         TARGET_READLINE_LIBS=$LIBS
604         LIBS=$sLIBS
606 if test x"$with_readline" != xno; then
607         found="yes"
609         AC_ARG_WITH([readline-lib],
610                 [AS_HELP_STRING([--with-readline-lib],[specify readline library])],
611                 [with_readline_lib=$withval],
612                 [with_readline_lib="auto"])
613         if test "x$with_readline_lib" = xauto; then
614                 save_LIBS="$LIBS"
615                 LIBS=""
616                 AC_SEARCH_LIBS(tgetent, [readline ncurses curses termcap], [term_LIBS="$LIBS"], [term_LIBS=""])
617                 AC_CHECK_LIB([readline], [readline], [TARGET_READLINE_LIBS="-lreadline"], [found="no"])
618                 TARGET_READLINE_LIBS="$TARGET_READLINE_LIBS $term_LIBS"
619                 LIBS="$save_LIBS"
620         else
621                 TARGET_READLINE_LIBS="$with_readline_lib"
622         fi
624         AC_ARG_WITH([readline-inc],
625                 [AS_HELP_STRING([--with-readline-inc],[specify readline include paths])],
626                 [with_readline_inc=$withval],
627                 [with_readline_inc="auto"])
628         if test "x$with_readline_inc" = xauto; then
629                 AC_CHECK_HEADER(readline.h, [found="yes"], [
630                         found="no"
631                         if test "$cross_compiling" != yes; then
632                                 for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do
633                                         for subdir in include include/readline; do
634                                                 AC_CHECK_FILE($dir/$subdir/readline.h, found=yes)
635                                                 if test "$found" = "yes"; then
636                                                         TARGET_READLINE_INC="-I$dir/$subdir"
637                                                         break
638                                                 fi
639                                         done
640                                         test "$found" = "yes" && break
641                                 done
642                         fi
643                 ])
644         else
645                 TARGET_READLINE_INC="$with_readline_inc"
646         fi
648         if test x"$found" = xno; then
649                 TARGET_READLINE_LIBS=""
650                 TARGET_READLINE_INC=""
651                 TARGET_HAVE_READLINE=0
652         else
653                 TARGET_HAVE_READLINE=1
654         fi
656 AC_ARG_WITH([linenoise],
657             [AS_HELP_STRING([--with-linenoise=DIR],[source directory for linenoise library])],
658             [with_linenoise=$withval],
659             [with_linenoise="no"])
660 if test "x$with_linenoise" != "xno"; then
661    TARGET_HAVE_READLINE=0
662    TARGET_HAVE_EDITLINE=0
663    TARGET_HAVE_LINENOISE=1
664    TARGET_READLINE_INC="-I${with_linenoise}"
665    TARGET_READLINE_LIBS="${with_linenoise}/linenoise.c"
666    echo "using linenoise source code at ${with_linenoise}"
667 else
668    TARGET_HAVE_LINENOISE=0
669    echo "not using linenoise"
672 AC_SUBST(TARGET_READLINE_LIBS)
673 AC_SUBST(TARGET_READLINE_INC)
674 AC_SUBST(TARGET_HAVE_READLINE)
675 AC_SUBST(TARGET_HAVE_EDITLINE)
676 AC_SUBST(TARGET_HAVE_LINENOISE)
679 ##########
680 # Figure out what C libraries are required to compile programs
681 # that use "fdatasync()" function.
683 AC_SEARCH_LIBS(fdatasync, [rt])
685 #########
686 # check for debug enabled
687 AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],[enable debugging & verbose explain]))
688 AC_MSG_CHECKING([build type])
689 if test "${enable_debug}" = "yes" ; then
690   TARGET_DEBUG="-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0 -Wall"
691   AC_MSG_RESULT([debug])
692 else
693   TARGET_DEBUG="-DNDEBUG"
694   AC_MSG_RESULT([release])
696 AC_SUBST(TARGET_DEBUG)
698 #########
699 # See whether we should use the amalgamation to build
701 AC_ARG_ENABLE(amalgamation, AS_HELP_STRING([--disable-amalgamation],
702       [Disable the amalgamation and instead build all files separately]))
703 if test "${enable_amalgamation}" = "no" ; then
704   USE_AMALGAMATION=0
706 AC_SUBST(USE_AMALGAMATION)
708 #########
709 # By default, amalgamation sqlite3.c will have #line directives.
710 # This is a build option not shown by ./configure --help
711 # To control it, use configure option: amalgamation_line_macros=?
712 # where ? is no to suppress #line directives or yes to create them.
713 AMALGAMATION_LINE_MACROS=--linemacros=1
714 AC_ARG_VAR(amalgamation_line_macros,)
715 AC_SUBST(AMALGAMATION_LINE_MACROS)
716 if test "${amalgamation_line_macros+set}" = set; then :
717   enableval=$amalgamation_line_macros;
719 if test "${amalgamation_line_macros}" = "yes" ; then
720   AMALGAMATION_LINE_MACROS=--linemacros=1
722 if test "${amalgamation_line_macros}" = "no" ; then
723   AMALGAMATION_LINE_MACROS=--linemacros=0
726 #########
727 # Look for zlib.  Only needed by extensions and by the sqlite3.exe shell
728 AC_CHECK_HEADERS(zlib.h)
729 AC_SEARCH_LIBS(deflate, z, [HAVE_ZLIB="-DSQLITE_HAVE_ZLIB=1"], [HAVE_ZLIB=""])
730 AC_SUBST(HAVE_ZLIB)
732 #########
733 # See whether we should allow loadable extensions
734 AC_ARG_ENABLE(load-extension, AS_HELP_STRING([--disable-load-extension],
735       [Disable loading of external extensions]),,[enable_load_extension=yes])
736 if test "${enable_load_extension}" = "yes" ; then
737   OPT_FEATURE_FLAGS=""
738   AC_SEARCH_LIBS(dlopen, dl)
739 else
740   OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
743 ##########
744 # Do we want to support math functions
746 AC_ARG_ENABLE(math, 
747 AS_HELP_STRING([--disable-math],[Disable math functions]))
748 AC_MSG_CHECKING([whether to support math functions])
749 if test "$enable_math" = "no"; then
750   AC_MSG_RESULT([no])
751 else
752   AC_MSG_RESULT([yes])
753   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MATH_FUNCTIONS"
754   AC_SEARCH_LIBS(ceil, m)
757 ##########
758 # Do we want to support JSON functions
760 AC_ARG_ENABLE(json, 
761 AS_HELP_STRING([--disable-json],[Disable JSON functions]))
762 AC_MSG_CHECKING([whether to support JSON functions])
763 if test "$enable_json" = "no"; then
764   AC_MSG_RESULT([no])
765   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_OMIT_JSON"
766 else
767   AC_MSG_RESULT([yes])
770 ########
771 # The --enable-all argument is short-hand to enable
772 # multiple extensions.
773 AC_ARG_ENABLE(all, AS_HELP_STRING([--enable-all],
774       [Enable FTS4, FTS5, Geopoly, RTree, Sessions]))
776 ##########
777 # Do we want to support memsys3 and/or memsys5
779 AC_ARG_ENABLE(memsys5, 
780   AS_HELP_STRING([--enable-memsys5],[Enable MEMSYS5]))
781 AC_MSG_CHECKING([whether to support MEMSYS5])
782 if test "${enable_memsys5}" = "yes"; then
783   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS5"
784   AC_MSG_RESULT([yes])
785 else
786   AC_MSG_RESULT([no])
788 AC_ARG_ENABLE(memsys3, 
789   AS_HELP_STRING([--enable-memsys3],[Enable MEMSYS3]))
790 AC_MSG_CHECKING([whether to support MEMSYS3])
791 if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
792   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
793   AC_MSG_RESULT([yes])
794 else
795   AC_MSG_RESULT([no])
798 #########
799 # See whether we should enable Full Text Search extensions
800 AC_ARG_ENABLE(fts3, AS_HELP_STRING([--enable-fts3],
801       [Enable the FTS3 extension]))
802 AC_MSG_CHECKING([whether to support FTS3])
803 if test "${enable_fts3}" = "yes" ; then
804   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
805   AC_MSG_RESULT([yes])
806 else
807   AC_MSG_RESULT([no])
809 AC_ARG_ENABLE(fts4, AS_HELP_STRING([--enable-fts4],
810       [Enable the FTS4 extension]))
811 AC_MSG_CHECKING([whether to support FTS4])
812 if test "${enable_fts4}" = "yes" -o "${enable_all}" = "yes" ; then
813   AC_MSG_RESULT([yes])
814   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
815   AC_SEARCH_LIBS([log],[m])
816 else
817   AC_MSG_RESULT([no])
819 AC_ARG_ENABLE(fts5, AS_HELP_STRING([--enable-fts5],
820       [Enable the FTS5 extension]))
821 AC_MSG_CHECKING([whether to support FTS5])
822 if test "${enable_fts5}" = "yes" -o "${enable_all}" = "yes" ; then
823   AC_MSG_RESULT([yes])
824   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
825   AC_SEARCH_LIBS([log],[m])
826 else
827   AC_MSG_RESULT([no])
830 #########
831 # See whether we should enable the LIMIT clause on UPDATE and DELETE
832 # statements.
833 AC_ARG_ENABLE(update-limit, AS_HELP_STRING([--enable-update-limit],
834       [Enable the UPDATE/DELETE LIMIT clause]))
835 AC_MSG_CHECKING([whether to support LIMIT on UPDATE and DELETE statements])
836 if test "${enable_update_limit}" = "yes" ; then
837   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
838   AC_MSG_RESULT([yes])
839 else
840   AC_MSG_RESULT([no])
843 #########
844 # See whether we should enable GEOPOLY
845 AC_ARG_ENABLE(geopoly, AS_HELP_STRING([--enable-geopoly],
846       [Enable the GEOPOLY extension]),
847       [enable_geopoly=yes],[enable_geopoly=no])
848 AC_MSG_CHECKING([whether to support GEOPOLY])
849 if test "${enable_geopoly}" = "yes" -o "${enable_all}" = "yes" ; then
850   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_GEOPOLY"
851   enable_rtree=yes
852   AC_MSG_RESULT([yes])
853 else
854   AC_MSG_RESULT([no])
857 #########
858 # See whether we should enable RTREE
859 AC_ARG_ENABLE(rtree, AS_HELP_STRING([--enable-rtree],
860       [Enable the RTREE extension]))
861 AC_MSG_CHECKING([whether to support RTREE])
862 if test "${enable_rtree}" = "yes" ; then
863   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
864   AC_MSG_RESULT([yes])
865 else
866   AC_MSG_RESULT([no])
869 #########
870 # See whether we should enable the SESSION extension
871 AC_ARG_ENABLE(session, AS_HELP_STRING([--enable-session],
872       [Enable the SESSION extension]))
873 AC_MSG_CHECKING([whether to support SESSION])
874 if test "${enable_session}" = "yes" -o "${enable_all}" = "yes" ; then
875   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
876   OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
877   AC_MSG_RESULT([yes])
878 else
879   AC_MSG_RESULT([no])
882 #########
883 # attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
884 for option in $CFLAGS $CPPFLAGS
886   case $option in
887     -DSQLITE_OMIT*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
888     -DSQLITE_ENABLE*) OPT_FEATURE_FLAGS="$OPT_FEATURE_FLAGS $option";;
889   esac
890 done
891 AC_SUBST(OPT_FEATURE_FLAGS)
894 # attempt to remove any OMITS and ENABLES from the $(CFLAGS) parameter
895 ac_temp_CFLAGS=""
896 for option in $CFLAGS
898   case $option in
899     -DSQLITE_OMIT*) ;;
900     -DSQLITE_ENABLE*) ;;
901     *) ac_temp_CFLAGS="$ac_temp_CFLAGS $option";;
902   esac
903 done
904 CFLAGS=$ac_temp_CFLAGS
907 # attempt to remove any OMITS and ENABLES from the $(CPPFLAGS) parameter
908 ac_temp_CPPFLAGS=""
909 for option in $CPPFLAGS
911   case $option in
912     -DSQLITE_OMIT*) ;;
913     -DSQLITE_ENABLE*) ;;
914     *) ac_temp_CPPFLAGS="$ac_temp_CPPFLAGS $option";;
915   esac
916 done
917 CPPFLAGS=$ac_temp_CPPFLAGS
920 # attempt to remove any OMITS and ENABLES from the $(BUILD_CFLAGS) parameter
921 ac_temp_BUILD_CFLAGS=""
922 for option in $BUILD_CFLAGS
924   case $option in
925     -DSQLITE_OMIT*) ;;
926     -DSQLITE_ENABLE*) ;;
927     *) ac_temp_BUILD_CFLAGS="$ac_temp_BUILD_CFLAGS $option";;
928   esac
929 done
930 BUILD_CFLAGS=$ac_temp_BUILD_CFLAGS
933 #########
934 # See whether we should use GCOV
935 AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],
936       [Enable coverage testing using gcov]))
937 if test "${use_gcov}" = "yes" ; then
938   USE_GCOV=1
939 else
940   USE_GCOV=0
942 AC_SUBST(USE_GCOV)
944 #########
945 # Enable/disabled amalagamation line macros
946 ########
947 AMALGAMATION_LINE_MACROS=--linemacros=0
948 if test "${amalgamation_line_macros}" = "yes" ; then
949   AMALGAMATION_LINE_MACROS=--linemacros=1
951 if test "${amalgamation_line_macros}" = "no" ; then
952   AMALGAMATION_LINE_MACROS=--linemacros=0
954 AC_SUBST(AMALGAMATION_LINE_MACROS)
956 #########
957 # Output the config header
958 AC_CONFIG_HEADERS(sqlite_cfg.h)
960 #########
961 # Generate the output files.
963 AC_SUBST(BUILD_CFLAGS)
964 AC_CONFIG_FILES([
965 Makefile
966 sqlcipher.pc
968 AC_OUTPUT