summaryrefslogtreecommitdiffstats
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure388
1 files changed, 364 insertions, 24 deletions
diff --git a/configure b/configure
index 0ae06d53..6f521237 100755
--- a/configure
+++ b/configure
@@ -14,38 +14,378 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-echo "/* RUNNING ./CONFIGURE - SHOULD BE USED ONLY VIA MAKE, READ INSTALL */"
-
set -e
-exec > config.h 2> config.log
-CFLAGS="${CFLAGS} -Wno-unused -Werror"
+[ -e config.log ] && mv config.log config.log.old
+[ -e config.h ] && mv config.h config.h.old
+
+# Output file descriptor usage:
+# 1 (stdout): config.h, Makefile.local
+# 2 (stderr): original stderr, usually to the console
+# 3: config.log
+
+exec 3> config.log
+echo "config.log: writing..."
+
+# --- default settings -------------------------------------------------
+# Initialize all variables here,
+# such that nothing can leak in from the environment.
+
+VERSION="1.13.1"
+echo "VERSION=\"${VERSION}\"" 1>&2
+echo "VERSION=\"${VERSION}\"" 1>&3
+
+OSNAME=
+
+CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
+CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
+DBLIB=
+STATIC="-static"
+
+BUILD_DB=1
+BUILD_CGI=0
+
+HAVE_DIRENT_NAMLEN=
+HAVE_FGETLN=
+HAVE_FTS=
+HAVE_GETSUBOPT=
+HAVE_MMAP=
+HAVE_REALLOCARRAY=
+HAVE_STRCASESTR=
+HAVE_STRLCAT=
+HAVE_STRLCPY=
+HAVE_STRPTIME=
+HAVE_STRSEP=
+HAVE_WCHAR=
+
+HAVE_SQLITE3=
+HAVE_SQLITE3_ERRSTR=
+HAVE_OHASH=
+HAVE_MANPATH=
+
+PREFIX="/usr/local"
+BINDIR=
+SBINDIR=
+INCLUDEDIR=
+LIBDIR=
+MANDIR=
+EXAMPLEDIR=
+
+WWWPREFIX="/var/www"
+HTDOCDIR=
+CGIBINDIR=
+
+INSTALL="install"
+INSTALL_PROGRAM=
+INSTALL_LIB=
+INSTALL_MAN=
+INSTALL_DATA=
+
+# --- manual settings from configure.local -----------------------------
+
+if [ -e ./configure.local ]; then
+ echo "configure.local: reading..." 1>&2
+ echo "configure.local: reading..." 1>&3
+ cat ./configure.local 1>&3
+ . ./configure.local
+else
+ echo "configure.local: no (fully automatic configuration)" 1>&2
+ echo "configure.local: no (fully automatic configuration)" 1>&3
+fi
+echo 1>&3
+# --- tests for config.h ----------------------------------------------
+
+COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
+
+# Check whether this HAVE_ setting is manually overridden.
+# If yes, use the override, if no, do not decide anything yet.
+# Arguments: lower-case test name, manual value
+ismanual() {
+ [ -z "${2}" ] && return 1
+ echo "${1}: manual (${2})" 1>&2
+ echo "${1}: manual (${2})" 1>&3
+ echo 1>&3
+ return 0
+}
+
+# Run a single autoconfiguration test.
+# In case of success, enable the feature.
+# In case of failure, do not decide anything yet.
+# Arguments: lower-case test name, upper-case test name, additional CFLAGS
+singletest() {
+ cat 1>&3 << __HEREDOC__
+${1}: testing...
+${COMP} ${3} -o test-${1} test-${1}.c
+__HEREDOC__
+
+ if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
+ echo "${1}: ${CC} succeeded" 1>&3
+ else
+ echo "${1}: ${CC} failed with $?" 1>&3
+ echo 1>&3
+ return 1
+ fi
+
+ if ./test-${1} 1>&3 2>&3; then
+ echo "${1}: yes" 1>&2
+ echo "${1}: yes" 1>&3
+ echo 1>&3
+ eval HAVE_${2}=1
+ rm "test-${1}"
+ return 0
+ else
+ echo "${1}: execution failed with $?" 1>&3
+ echo 1>&3
+ rm "test-${1}"
+ return 1
+ fi
+}
+
+# Run a complete autoconfiguration test, including the check for
+# a manual override and disabling the feature on failure.
+# Arguments: lower case name, upper case name, additional CFLAGS
runtest() {
- echo ${CC} ${CFLAGS} ${3} -o test-${1} test-${1}.c 1>&2
- ${CC} ${CFLAGS} ${3} -o "test-${1}" "test-${1}.c" 1>&2 || return 0
- "./test-${1}" && echo "#define HAVE_${2}" \
- || echo FAILURE: test-${1} returned $? 1>&2
- rm "test-${1}"
+ eval _manual=\${HAVE_${2}}
+ ismanual "${1}" "${_manual}" && return 0
+ singletest "${1}" "${2}" "${3}" && return 0
+ echo "${1}: no" 1>&2
+ eval HAVE_${2}=0
+ return 1
}
-cat config.h.pre
+# --- library functions ---
+runtest dirent-namlen DIRENT_NAMLEN || true
+runtest fgetln FGETLN || true
+runtest fts FTS || true
+runtest getsubopt GETSUBOPT || true
+runtest mmap MMAP || true
+runtest reallocarray REALLOCARRAY || true
+runtest strcasestr STRCASESTR || true
+runtest strlcat STRLCAT || true
+runtest strlcpy STRLCPY || true
+runtest strptime STRPTIME || true
+runtest strsep STRSEP || true
+runtest wchar WCHAR || true
+
+# --- sqlite3 ---
+DETECTLIB=
+if [ ${BUILD_DB} -eq 0 ]; then
+ echo "BUILD_DB=0 (manual)" 1>&2
+ echo "BUILD_DB=0 (manual)" 1>&3
+ echo 1>&3
+ HAVE_SQLITE3=0
+elif ismanual sqlite3 "${HAVE_SQLITE3}"; then
+ DETECTLIB="-lsqlite3"
+elif [ -n "${DBLIB}" ]; then
+ runtest sqlite3 SQLITE3 "${DBLIB}" || true
+elif singletest sqlite3 SQLITE3 "-lsqlite3"; then
+ DETECTLIB="-lsqlite3"
+elif runtest sqlite3 SQLITE3 \
+ "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
+ DETECTLIB="-L/usr/local/lib -lsqlite3"
+ CFLAGS="${CFLAGS} -I/usr/local/include"
+fi
+if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
+ echo "BUILD_DB=0 (no sqlite3)" 1>&2
+ echo "BUILD_DB=0 (no sqlite3)" 1>&3
+ echo 1>&3
+ BUILD_DB=0
+fi
+
+# --- sqlite3_errstr ---
+if [ ${BUILD_DB} -eq 0 ]; then
+ HAVE_SQLITE3_ERRSTR=1
+elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then
+ :
+elif [ -n "${DBLIB}" ]; then
+ runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" || true
+else
+ runtest sqlite3_errstr SQLITE3_ERRSTR "${DETECTLIB}" || true
+fi
+
+# --- ohash ---
+if [ ${BUILD_DB} -eq 0 ]; then
+ HAVE_OHASH=1
+elif ismanual ohash "${HAVE_OHASH}"; then
+ :
+elif [ -n "${DBLIB}" ]; then
+ runtest ohash OHASH "${DBLIB}" || true
+elif singletest ohash OHASH; then
+ :
+elif runtest ohash OHASH "-lutil"; then
+ DETECTLIB="${DETECTLIB} -lutil"
+fi
+
+# --- DBLIB ---
+if [ ${BUILD_DB} -eq 0 ]; then
+ DBLIB=
+elif [ -z "${DBLIB}" ]; then
+ DBLIB="${DETECTLIB}"
+ echo "DBLIB=\"${DBLIB}\"" 1>&2
+ echo "DBLIB=\"${DBLIB}\"" 1>&3
+ echo 1>&3
+fi
+
+# --- manpath ---
+if [ ${BUILD_DB} -eq 0 ]; then
+ HAVE_MANPATH=0
+elif ismanual manpath "${HAVE_MANPATH}"; then
+ :
+elif manpath 1>&3 2>&3; then
+ echo "manpath: yes" 1>&2
+ echo "manpath: yes" 1>&3
+ echo 1>&3
+ HAVE_MANPATH=1
+else
+ echo "manpath: no" 1>&2
+ echo "manpath: no" 1>&3
+ echo 1>&3
+ HAVE_MANPATH=0
+fi
+
+# --- write config.h ---
+
+exec > config.h
+
+cat << __HEREDOC__
+#ifndef MANDOC_CONFIG_H
+#define MANDOC_CONFIG_H
+
+#if defined(__linux__) || defined(__MINT__)
+#define _GNU_SOURCE /* getsubopt(), strcasestr(), strptime() */
+#endif
+
+__HEREDOC__
+
+[ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
+ ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
+ && echo "#include <sys/types.h>"
+[ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
+
echo
echo "#define VERSION \"${VERSION}\""
-runtest dirent-namlen DIRENT_NAMLEN
-runtest fgetln FGETLN
-runtest fts FTS
-runtest getsubopt GETSUBOPT
-runtest mmap MMAP
-runtest ohash OHASH "${DBLIB}"
-runtest reallocarray REALLOCARRAY
-runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}"
-runtest strcasestr STRCASESTR
-runtest strlcat STRLCAT
-runtest strlcpy STRLCPY
-runtest strptime STRPTIME
-runtest strsep STRSEP
+[ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
+
+cat << __HEREDOC__
+#define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
+#define HAVE_FGETLN ${HAVE_FGETLN}
+#define HAVE_FTS ${HAVE_FTS}
+#define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
+#define HAVE_MMAP ${HAVE_MMAP}
+#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
+#define HAVE_STRCASESTR ${HAVE_STRCASESTR}
+#define HAVE_STRLCAT ${HAVE_STRLCAT}
+#define HAVE_STRLCPY ${HAVE_STRLCPY}
+#define HAVE_STRPTIME ${HAVE_STRPTIME}
+#define HAVE_STRSEP ${HAVE_STRSEP}
+#define HAVE_WCHAR ${HAVE_WCHAR}
+#define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
+#define HAVE_OHASH ${HAVE_OHASH}
+#define HAVE_MANPATH ${HAVE_MANPATH}
+
+#if !defined(__BEGIN_DECLS)
+# ifdef __cplusplus
+# define __BEGIN_DECLS extern "C" {
+# else
+# define __BEGIN_DECLS
+# endif
+#endif
+#if !defined(__END_DECLS)
+# ifdef __cplusplus
+# define __END_DECLS }
+# else
+# define __END_DECLS
+# endif
+#endif
+
+__HEREDOC__
+
+[ ${HAVE_FGETLN} -eq 0 ] && \
+ echo "extern char *fgetln(FILE *, size_t *);"
+
+if [ ${HAVE_GETSUBOPT} -eq 0 ]; then
+ echo "extern int getsubopt(char **, char * const *, char **);"
+ echo "extern char *suboptarg;"
+fi
+
+[ ${HAVE_REALLOCARRAY} -eq 0 ] && \
+ echo "extern void *reallocarray(void *, size_t, size_t);"
+
+[ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
+ echo "extern const char *sqlite3_errstr(int);"
+
+[ ${HAVE_STRCASESTR} -eq 0 ] && \
+ echo "extern char *strcasestr(const char *, const char *);"
+
+[ ${HAVE_STRLCAT} -eq 0 ] && \
+ echo "extern size_t strlcat(char *, const char *, size_t);"
+
+[ ${HAVE_STRLCPY} -eq 0 ] && \
+ echo "extern size_t strlcpy(char *, const char *, size_t);"
+
+[ ${HAVE_STRSEP} -eq 0 ] && \
+ echo "extern char *strsep(char **, const char *);"
+
echo
-cat config.h.post
+echo "#endif /* MANDOC_CONFIG_H */"
+
+echo "config.h: written" 1>&2
+echo "config.h: written" 1>&3
+
+# --- tests for Makefile.local -----------------------------------------
+
+exec > Makefile.local
+
+[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
+[ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
+[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc"
+[ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib/mandoc"
+[ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
+[ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR="${PREFIX}/share/examples/mandoc"
+
+[ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs"
+[ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
+
+[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
+[ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
+[ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
+[ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
+
+if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
+ echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
+ echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
+ BUILD_CGI=0
+fi
+
+BUILD_TARGETS="base-build"
+[ ${BUILD_DB} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} db-build"
+[ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build"
+
+cat << __HEREDOC__
+VERSION = ${VERSION}
+BUILD_TARGETS = ${BUILD_TARGETS}
+CFLAGS = ${CFLAGS}
+DBLIB = ${DBLIB}
+STATIC = ${STATIC}
+PREFIX = ${PREFIX}
+BINDIR = ${BINDIR}
+SBINDIR = ${SBINDIR}
+INCLUDEDIR = ${INCLUDEDIR}
+LIBDIR = ${LIBDIR}
+MANDIR = ${MANDIR}
+EXAMPLEDIR = ${EXAMPLEDIR}
+WWWPREFIX = ${WWWPREFIX}
+HTDOCDIR = ${HTDOCDIR}
+CGIBINDIR = ${CGIBINDIR}
+INSTALL = ${INSTALL}
+INSTALL_PROGRAM = ${INSTALL_PROGRAM}
+INSTALL_LIB = ${INSTALL_LIB}
+INSTALL_MAN = ${INSTALL_MAN}
+INSTALL_DATA = ${INSTALL_DATA}
+__HEREDOC__
+
+echo "Makefile.local: written" 1>&2
+echo "Makefile.local: written" 1>&3
exit 0