+# Test whether this shell is capable of parameter substring processing.
+( option='a/b'; : ${option#*/} ) 2>/dev/null || {
+ echo "
+The shell interpreting '$0' is lacking some required features.
+
+To work around this problem you may try to execute:
+
+ ksh $0 $*
+ or
+ bash $0 $*
+"
+ exit 1
+}
+
+# Store original IFS value so it can be changed (and restored) in many places.
+readonly DEFAULT_IFS="$IFS"
+
+srcdir=$(dirname "$0")
+
+# For a non-srcdir configure invocation (such as ../configure), create
+# the directory structure and copy Makefiles.
+if [ "$srcdir" != "." ]; then
+
+ for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do
+ mkdir -p "$dir"
+ cp "$srcdir"/"$dir"/Makefile.local "$dir"
+ cp "$srcdir"/"$dir"/Makefile "$dir"
+ done
+
+ # Easiest way to get the test suite to work is to just copy the
+ # whole thing into the build directory.
+ cp -a "$srcdir"/test/* test
+
+ # Emacs only likes to generate compiled files next to the .el files
+ # by default so copy these as well (which is not ideal0.
+ cp -a "$srcdir"/emacs/*.el emacs
+fi
+
+# Set several defaults (optionally specified by the user in
+# environment variables)
+CC=${CC:-gcc}
+CXX=${CXX:-g++}
+CFLAGS=${CFLAGS:--O2}
+CXXFLAGS=${CXXFLAGS:-\$(CFLAGS)}
+LDFLAGS=${LDFLAGS:-}
+XAPIAN_CONFIG=${XAPIAN_CONFIG:-xapian-config}
+
+# We don't allow the EMACS or GZIP Makefile variables inherit values
+# from the environment as we do with CC and CXX above. The reason is
+# that these names as environment variables have existing uses other
+# than the program name that we want. (EMACS is set to 't' when a
+# shell is running within emacs and GZIP specifies arguments to pass
+# on the gzip command line).
+
+# Set the defaults for values the user can specify with command-line
+# options.
+PREFIX=/usr/local
+LIBDIR=
+WITH_EMACS=1
+WITH_BASH=1
+WITH_ZSH=1
+
+# Compatible GMime versions (with constraints).
+# If using GMime 2.6, we need to have a version >= 2.6.5 to avoid a
+# crypto bug. We need 2.6.7 for permissive "From " header handling.
+GMIME_24_VERSION_CTR=''
+GMIME_24_VERSION="gmime-2.4 $GMIME_24_VERSION_CTR"
+GMIME_26_VERSION_CTR='>= 2.6.7'
+GMIME_26_VERSION="gmime-2.6 $GMIME_26_VERSION_CTR"
+
+WITH_GMIME_VERSIONS="$GMIME_26_VERSION;$GMIME_24_VERSION"
+
+usage ()
+{
+ cat <<EOF
+Usage: ./configure [options]...
+
+This script configures notmuch to build on your system.
+
+It verifies that dependencies are available, determines flags needed
+to compile and link against various required libraries, and identifies
+whether various system functions can be used or if locally-provided
+replacements will be built instead.
+
+Finally, it allows you to control various aspects of the build and
+installation process.
+
+First, some common variables can specified via environment variables:
+
+ CC The C compiler to use
+ CFLAGS Flags to pass to the C compiler
+ CXX The C++ compiler to use
+ CXXFLAGS Flags to pass to the C compiler
+ LDFLAGS Flags to pass when linking
+
+Each of these values can further be controlled by specifying them
+later on the "make" command line.
+
+Other environment variables can be used to control configure itself,
+(and for which there is no equivalent build-time control):
+
+ XAPIAN_CONFIG The program to use to determine flags for
+ compiling and linking against the Xapian
+ library. [$XAPIAN_CONFIG]
+
+Additionally, various options can be specified on the configure
+command line.
+
+ --prefix=PREFIX Install files in PREFIX [$PREFIX]
+
+By default, "make install" will install the resulting program to
+$PREFIX/bin, documentation to $PREFIX/man, etc. You can
+specify an installation prefix other than $PREFIX using
+--prefix, for instance:
+
+ ./configure --prefix=\$HOME
+
+Fine tuning of some installation directories is available:
+
+ --libdir=DIR Install libraries to DIR [PREFIX/lib]
+ --includedir=DIR Install header files to DIR [PREFIX/include]
+ --mandir=DIR Install man pages to DIR [PREFIX/share/man]
+ --sysconfdir=DIR Read-only single-machine data [PREFIX/etc]
+ --emacslispdir=DIR Emacs code [PREFIX/share/emacs/site-lisp]
+ --emacsetcdir=DIR Emacs miscellaneous files [PREFIX/share/emacs/site-lisp]
+ --bashcompletiondir=DIR Bash completions files [SYSCONFDIR/bash_completion.d]
+ --zshcompletiondir=DIR Zsh completions files [PREFIX/share/zsh/functions/Completion/Unix]
+
+Some specific library versions can be specified (auto-detected otherwise):
+
+ --with-gmime-version=VERS Specify GMIME version (2.4 or 2.6)
+
+Some features can be disabled (--with-feature=no is equivalent to
+--without-feature) :
+
+ --without-emacs Do not install lisp file
+ --without-bash-completion Do not install bash completions files
+ --without-zsh-completion Do not install zsh completions files
+
+Additional options are accepted for compatibility with other
+configure-script calling conventions, but don't do anything yet:
+
+ --build=<cpu>-<vendor>-<os> Currently ignored
+ --host=<cpu>-<vendor>-<os> Currently ignored
+ --infodir=DIR Currently ignored
+ --datadir=DIR Currently ignored
+ --localstatedir=DIR Currently ignored
+ --libexecdir=DIR Currently ignored
+ --disable-maintainer-mode Currently ignored
+ --disable-dependency-tracking Currently ignored
+
+EOF
+}
+
+# Parse command-line options
+for option; do
+ if [ "${option}" = '--help' ] ; then
+ usage
+ exit 0
+ elif [ "${option%%=*}" = '--prefix' ] ; then
+ PREFIX="${option#*=}"
+ elif [ "${option%%=*}" = '--libdir' ] ; then
+ LIBDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--includedir' ] ; then
+ INCLUDEDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--mandir' ] ; then
+ MANDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--sysconfdir' ] ; then
+ SYSCONFDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--emacslispdir' ] ; then
+ EMACSLISPDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--emacsetcdir' ] ; then
+ EMACSETCDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--bashcompletiondir' ] ; then
+ BASHCOMPLETIONDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--zshcompletiondir' ] ; then
+ ZSHCOMLETIONDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--with-emacs' ]; then
+ if [ "${option#*=}" = 'no' ]; then
+ WITH_EMACS=0
+ else
+ WITH_EMACS=1
+ fi
+ elif [ "${option}" = '--without-emacs' ] ; then
+ WITH_EMACS=0
+ elif [ "${option%%=*}" = '--with-bash-completion' ]; then
+ if [ "${option#*=}" = 'no' ]; then
+ WITH_BASH=0
+ else
+ WITH_BASH=1
+ fi
+ elif [ "${option}" = '--without-bash-completion' ] ; then
+ WITH_BASH=0
+ elif [ "${option%%=*}" = '--with-zsh-completion' ]; then
+ if [ "${option#*=}" = 'no' ]; then
+ WITH_ZSH=0
+ else
+ WITH_ZSH=1
+ fi
+ elif [ "${option}" = '--without-zsh-completion' ] ; then
+ WITH_ZSH=0
+ elif [ "${option%%=*}" = '--with-gmime-version' ] ; then
+ if [ "${option#*=}" = '2.4' ]; then
+ WITH_GMIME_VERSIONS=$GMIME_24_VERSION
+ elif [ "${option#*=}" = '2.6' ]; then
+ WITH_GMIME_VERSIONS=$GMIME_26_VERSION
+ fi
+ elif [ "${option%%=*}" = '--build' ] ; then
+ true
+ elif [ "${option%%=*}" = '--host' ] ; then
+ true
+ elif [ "${option%%=*}" = '--infodir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--datadir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--localstatedir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--libexecdir' ] ; then
+ true
+ elif [ "${option}" = '--disable-maintainer-mode' ] ; then
+ true
+ elif [ "${option}" = '--disable-dependency-tracking' ] ; then
+ true
+ else
+ echo "Unrecognized option: ${option}"
+ echo "See:"
+ echo " $0 --help"
+ echo ""
+ exit 1
+ fi
+done
+
+# We set this value early, (rather than just while printing the
+# Makefile.config file later like most values), because we need to
+# actually investigate this value compared to the ldconfig_paths value
+# below.
+libdir_expanded=${LIBDIR:-${PREFIX}/lib}
+