#!/bin/sh
#
-# Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+# $Id: configure,v 1.48 2016/07/31 09:29:13 schwarze Exp $
+#
+# Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
set -e
-[ -e config.log ] && mv config.log config.log.old
-[ -e config.h ] && mv config.h config.h.old
+[ -w config.log ] && mv config.log config.log.old
+[ -w config.h ] && mv config.h config.h.old
# Output file descriptor usage:
# 1 (stdout): config.h, Makefile.local
MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
OSNAME=
-
-CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
-CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
-DBLIB=
+UTF8_LOCALE=
+
+CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -f -`
+CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
+CFLAGS="${CFLAGS} -Wno-unused-parameter"
+LDADD=
+LDFLAGS=
+LD_NANOSLEEP=
+LD_OHASH=
STATIC="-static"
-BUILD_DB=1
BUILD_CGI=0
HAVE_DIRENT_NAMLEN=
+HAVE_EFTYPE=
HAVE_ERR=
-HAVE_FGETLN=
HAVE_FTS=
+HAVE_GETLINE=
HAVE_GETSUBOPT=
HAVE_ISBLANK=
HAVE_MKDTEMP=
-HAVE_MMAP=
+HAVE_NANOSLEEP=
+HAVE_OHASH=
+HAVE_PLEDGE=
HAVE_PROGNAME=
HAVE_REALLOCARRAY=
+HAVE_REWB_BSD=
+HAVE_REWB_SYSV=
+HAVE_SANDBOX_INIT=
HAVE_STRCASESTR=
HAVE_STRINGLIST=
HAVE_STRLCAT=
HAVE_VASPRINTF=
HAVE_WCHAR=
-HAVE_SQLITE3=
-HAVE_SQLITE3_ERRSTR=
-HAVE_OHASH=
-HAVE_MANPATH=
-
PREFIX="/usr/local"
BINDIR=
SBINDIR=
INCLUDEDIR=
LIBDIR=
MANDIR=
-EXAMPLEDIR=
HOMEBREWDIR=
WWWPREFIX="/var/www"
# --- manual settings from configure.local -----------------------------
-if [ -e ./configure.local ]; then
+if [ -r ./configure.local ]; then
echo "configure.local: reading..." 1>&2
echo "configure.local: reading..." 1>&3
cat ./configure.local 1>&3
return 1
}
+# Select a UTF-8 locale.
+get_locale() {
+ [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
+ ismanual UTF8_LOCALE "$UTF8_LOCALE" && return 0
+ echo "UTF8_LOCALE: testing..." 1>&3
+ UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
+ if [ -z "${UTF8_LOCALE}" ]; then
+ UTF8_LOCALE=`locale -a | grep -i '\.UTF-*8' | head -n 1`
+ [ -n "${UTF8_LOCALE}" ] || return 1
+ fi
+ echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
+ echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
+ echo 1>&3
+ return 0;
+}
+
+
# --- library functions ---
runtest dirent-namlen DIRENT_NAMLEN || true
+runtest EFTYPE EFTYPE || true
runtest err ERR || true
-runtest fgetln FGETLN || true
runtest fts FTS || true
+runtest getline GETLINE || true
runtest getsubopt GETSUBOPT || true
runtest isblank ISBLANK || true
runtest mkdtemp MKDTEMP || true
-runtest mmap MMAP || true
+runtest pledge PLEDGE || true
+runtest sandbox_init SANDBOX_INIT || true
runtest progname PROGNAME || true
runtest reallocarray REALLOCARRAY || true
+runtest rewb-bsd REWB_BSD || true
+runtest rewb-sysv REWB_SYSV || true
runtest strcasestr STRCASESTR || true
runtest stringlist STRINGLIST || true
runtest strlcat STRLCAT || true
runtest strsep STRSEP || true
runtest strtonum STRTONUM || true
runtest vasprintf VASPRINTF || 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
+# --- wide character and locale support ---
+if get_locale; then
+ runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
+else
+ HAVE_WCHAR=0
+ echo "wchar: no (no UTF8_LOCALE)" 1>&2
+ echo "wchar: no (no UTF8_LOCALE)" 1>&3
fi
-# --- sqlite3_errstr ---
-if [ ${BUILD_DB} -eq 0 ]; then
- HAVE_SQLITE3_ERRSTR=1
-elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then
+# --- nanosleep ---
+if [ -n "${LD_NANOSLEEP}" ]; then
+ runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true
+elif singletest nanosleep NANOSLEEP; then
:
-elif [ -n "${DBLIB}" ]; then
- runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" || true
-else
- runtest sqlite3_errstr SQLITE3_ERRSTR "${DETECTLIB}" || true
+elif runtest nanosleep NANOSLEEP "-lrt"; then
+ LD_NANOSLEEP="-lrt"
+fi
+if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
+ echo "FATAL: nanosleep: no" 1>&2
+ echo "FATAL: nanosleep: no" 1>&3
+ exit 1
fi
# --- ohash ---
-if [ ${BUILD_DB} -eq 0 ]; then
- HAVE_OHASH=1
-elif ismanual ohash "${HAVE_OHASH}"; then
+if ismanual ohash "${HAVE_OHASH}"; then
:
-elif [ -n "${DBLIB}" ]; then
- runtest ohash OHASH "${DBLIB}" || true
+elif [ -n "${LD_OHASH}" ]; then
+ runtest ohash OHASH "${LD_OHASH}" || true
elif singletest ohash OHASH; then
:
elif runtest ohash OHASH "-lutil"; then
- DETECTLIB="${DETECTLIB} -lutil"
+ LD_OHASH="-lutil"
fi
-
-# --- DBLIB ---
-if [ ${BUILD_DB} -eq 0 ]; then
- DBLIB="-lz"
-elif [ -z "${DBLIB}" ]; then
- DBLIB="${DETECTLIB} -lz"
- echo "DBLIB=\"${DBLIB}\"" 1>&2
- echo "DBLIB=\"${DBLIB}\"" 1>&3
- echo 1>&3
+if [ "${HAVE_OHASH}" -eq 0 ]; then
+ LD_OHASH=
fi
-# --- manpath ---
-if 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
+# --- LDADD ---
+LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
+echo "LDADD=\"${LDADD}\"" 1>&2
+echo "LDADD=\"${LDADD}\"" 1>&3
+echo 1>&3
# --- write config.h ---
exec > config.h
cat << __HEREDOC__
-#ifndef MANDOC_CONFIG_H
-#define MANDOC_CONFIG_H
+#ifdef __cplusplus
+#error "Do not use C++. See the INSTALL file."
+#endif
+
+#if !defined(__GNUC__) || (__GNUC__ < 4)
+#define __attribute__(x)
+#endif
#if defined(__linux__) || defined(__MINT__)
#define _GNU_SOURCE /* See test-*.c what needs this. */
__HEREDOC__
-[ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
+[ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
&& echo "#include <sys/types.h>"
[ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
-[ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
+[ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
echo
echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
[ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
-[ ${HAVE_PROGNAME} -eq 0 ] && echo "#define __progname mandoc_progname"
+[ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
[ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
+[ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
cat << __HEREDOC__
#define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
#define HAVE_ERR ${HAVE_ERR}
-#define HAVE_FGETLN ${HAVE_FGETLN}
#define HAVE_FTS ${HAVE_FTS}
+#define HAVE_GETLINE ${HAVE_GETLINE}
#define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
#define HAVE_ISBLANK ${HAVE_ISBLANK}
#define HAVE_MKDTEMP ${HAVE_MKDTEMP}
-#define HAVE_MMAP ${HAVE_MMAP}
+#define HAVE_PLEDGE ${HAVE_PLEDGE}
#define HAVE_PROGNAME ${HAVE_PROGNAME}
#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
+#define HAVE_REWB_BSD ${HAVE_REWB_BSD}
+#define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
+#define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
#define HAVE_STRCASESTR ${HAVE_STRCASESTR}
#define HAVE_STRINGLIST ${HAVE_STRINGLIST}
#define HAVE_STRLCAT ${HAVE_STRLCAT}
#define HAVE_STRTONUM ${HAVE_STRTONUM}
#define HAVE_VASPRINTF ${HAVE_VASPRINTF}
#define HAVE_WCHAR ${HAVE_WCHAR}
-#define HAVE_SQLITE3 ${HAVE_SQLITE3}
-#define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
#define HAVE_OHASH ${HAVE_OHASH}
-#define HAVE_MANPATH ${HAVE_MANPATH}
#define BINM_APROPOS "${BINM_APROPOS}"
#define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
#define BINM_SOELIM "${BINM_SOELIM}"
#define BINM_WHATIS "${BINM_WHATIS}"
-#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__
if [ ${HAVE_ERR} -eq 0 ]; then
echo "extern void err(int, const char *, ...);"
+ echo "extern void errx(int, const char *, ...);"
echo "extern void warn(const char *, ...);"
echo "extern void warnx(const char *, ...);"
fi
-[ ${HAVE_FGETLN} -eq 0 ] && \
- echo "extern char *fgetln(FILE *, size_t *);"
+[ ${HAVE_GETLINE} -eq 0 ] && \
+ echo "extern ssize_t getline(char **, size_t *, FILE *);"
[ ${HAVE_GETSUBOPT} -eq 0 ] && \
echo "extern int getsubopt(char **, char * const *, char **);"
[ ${HAVE_MKDTEMP} -eq 0 ] && \
echo "extern char *mkdtemp(char *);"
+if [ ${HAVE_PROGNAME} -eq 0 ]; then
+ echo "extern const char *getprogname(void);"
+ echo "extern void setprogname(const char *);"
+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_VASPRINTF} -eq 0 ] && \
echo "extern int vasprintf(char **, const char *, va_list);"
-echo
-echo "#endif /* MANDOC_CONFIG_H */"
-
echo "config.h: written" 1>&2
echo "config.h: written" 1>&3
[ -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_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_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build"
-INSTALL_TARGETS="base-install"
-[ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} db-install"
-[ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
+BUILD_TARGETS=
+[ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="cgi-build"
+INSTALL_TARGETS=
+[ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="cgi-install"
cat << __HEREDOC__
BUILD_TARGETS = ${BUILD_TARGETS}
INSTALL_TARGETS = ${INSTALL_TARGETS}
CC = ${CC}
CFLAGS = ${CFLAGS}
-DBLIB = ${DBLIB}
+LDADD = ${LDADD}
+LDFLAGS = ${LDFLAGS}
STATIC = ${STATIC}
PREFIX = ${PREFIX}
BINDIR = ${BINDIR}
INCLUDEDIR = ${INCLUDEDIR}
LIBDIR = ${LIBDIR}
MANDIR = ${MANDIR}
-EXAMPLEDIR = ${EXAMPLEDIR}
WWWPREFIX = ${WWWPREFIX}
HTDOCDIR = ${HTDOCDIR}
CGIBINDIR = ${CGIBINDIR}
INSTALL_DATA = ${INSTALL_DATA}
__HEREDOC__
-[ ${BUILD_DB} -gt 0 ] && \
- echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
-
echo "Makefile.local: written" 1>&2
echo "Makefile.local: written" 1>&3