aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-06-14 23:40:31 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-06-14 23:40:31 +0000
commit30da7aa93492bbe72c27b4bfca4a30fcf9a11f79 (patch)
tree6c9ff831b6b4b16a2a36e629a01f9bec82566b4f
parentbd0a544f0b4a0b27cceb27491da4eb567414c8ce (diff)
downloadmandoc-30da7aa93492bbe72c27b4bfca4a30fcf9a11f79.tar.gz
mandoc-30da7aa93492bbe72c27b4bfca4a30fcf9a11f79.tar.zst
mandoc-30da7aa93492bbe72c27b4bfca4a30fcf9a11f79.zip
Make the ./configure script simpler, more robust, and 23 lines shorter:
* three rather than four arguments for singletest() * let runtest() support testing two variants of compiler flags * always report a failed test, even when another test follows * run all tests before detecting fatal conditions * rename HAVE_CMSG_XPG42 to NEED_XPG4_2 for consistency * consistently use braces for shell variable interpolation * drop archaic "X${" syntax and unusual "==" in string comparisons
-rw-r--r--catman.c4
-rwxr-xr-xconfigure162
-rw-r--r--mandocd.c4
3 files changed, 72 insertions, 98 deletions
diff --git a/catman.c b/catman.c
index 7d62c0e7..b1bab0f6 100644
--- a/catman.c
+++ b/catman.c
@@ -1,4 +1,4 @@
-/* $Id: catman.c,v 1.21 2017/02/18 12:24:24 schwarze Exp $ */
+/* $Id: catman.c,v 1.22 2020/06/14 23:40:31 schwarze Exp $ */
/*
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -17,7 +17,7 @@
*/
#include "config.h"
-#if HAVE_CMSG_XPG42
+#if NEED_XPG4_2
#define _XPG4_2
#endif
diff --git a/configure b/configure
index ddec471c..083d2d3f 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $Id: configure,v 1.73 2020/03/13 17:31:44 schwarze Exp $
+# $Id: configure,v 1.74 2020/06/14 23:40:31 schwarze Exp $
#
# Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
#
@@ -33,7 +33,7 @@ echo "file config.log: writing..."
# Initialize all variables here,
# such that nothing can leak in from the environment.
-SOURCEDIR=`dirname "$0"`
+SOURCEDIR=`dirname "${0}"`
MANPATH_BASE="/usr/share/man:/usr/X11R6/man"
MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
@@ -43,6 +43,7 @@ UTF8_LOCALE=
CC=cc
CFLAGS=
+FATAL=0
LDADD=
LDFLAGS=
LD_NANOSLEEP=
@@ -55,7 +56,6 @@ BUILD_CATMAN=0
INSTALL_LIBMANDOC=0
HAVE_CMSG=
-HAVE_CMSG_XPG42=0
HAVE_DIRENT_NAMLEN=
HAVE_EFTYPE=
HAVE_ENDIAN=
@@ -94,6 +94,7 @@ HAVE_WCHAR=
NEED_GNU_SOURCE=0
NEED_OPENBSD_SOURCE=0
+NEED_XPG4_2=0
PREFIX="/usr/local"
BINDIR=
@@ -159,16 +160,17 @@ ismanual() {
# In case of failure, do not decide anything yet.
# Arguments: test file name, test var name, additional CFLAGS
singletest() {
- n=${1}${3}${4}
+ n=${1}${3}
cat 1>&3 << __HEREDOC__
testing ${n} ...
-${COMP} -o test-${1} test-${1}.c ${3} ${4}
+${COMP} -o test-${1} test-${1}.c ${3}
__HEREDOC__
- if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} ${4} 1>&3 2>&3
+ if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
then
echo "partial result of ${n}: ${CC} succeeded" 1>&3
else
+ echo "tested ${n}: no (compilation failed)" 1>&2
echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
echo "result of compiling ${n}: no" 1>&3
echo 1>&3
@@ -180,11 +182,16 @@ __HEREDOC__
echo "result of running ${n}: yes" 1>&3
echo 1>&3
eval HAVE_${2}=1
- [ "X$3" = "X-D_GNU_SOURCE" ] && NEED_GNU_SOURCE=1
- [ "X$3" = "X-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE=1
+ [ "${3}" = "-D_GNU_SOURCE" ] && NEED_GNU_SOURCE=1
+ [ "${3}" = "-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE=1
+ [ "${3}" = "-D_XPG4_2" ] && NEED_XPG4_2=1
+ [ "${3}" = "-lrt" ] && LD_NANOSLEEP="-lrt"
+ [ "${3}" = "-lsocket" ] && LD_RECVMSG="-lsocket"
+ [ "${3}" = "-lutil" ] && LD_OHASH="-lutil"
rm "test-${1}"
return 0
else
+ echo "tested ${n}: no (execution failed)" 1>&2
echo "result of ${n}: execution failed with exit status $?" 1>&3
echo "result of running ${n}: no" 1>&3
echo 1>&3
@@ -196,11 +203,12 @@ __HEREDOC__
# Run a complete autoconfiguration test, including the check for
# a manual override and disabling the feature on failure.
# Arguments: test file name, test var name, additional CFLAGS
+# The final argument can optionally be repeated a second time.
runtest() {
eval _manual=\${HAVE_${2}}
ismanual "${1}" "${2}" "${_manual}" && return 0
- singletest "${1}" "${2}" "${3}" "${4}" && return 0
- echo "tested ${1}${3}${4}: no" 1>&2
+ singletest "${1}" "${2}" "${3}" && return 0
+ [ -n "${4}" ] && singletest "${1}" "${2}" "${4}" && return 0
eval HAVE_${2}=0
return 1
}
@@ -208,7 +216,7 @@ runtest() {
# Select a UTF-8 locale.
get_locale() {
[ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
- ismanual UTF8_LOCALE UTF8_LOCALE "$UTF8_LOCALE" && return 0
+ ismanual UTF8_LOCALE UTF8_LOCALE "${UTF8_LOCALE}" && return 0
echo "testing UTF8_LOCALE ..." 1>&3
UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
if [ -z "${UTF8_LOCALE}" ]; then
@@ -228,9 +236,9 @@ if [ -n "${OSENUM}" ]; then
echo "OSENUM specified manually: ${OSENUM}" 1>&3
else
OSDETECT=`uname`
- if [ "X${OSDETECT}" = "XNetBSD" ]; then
+ if [ "${OSDETECT}" = "NetBSD" ]; then
OSENUM=MANDOC_OS_NETBSD
- elif [ "X${OSDETECT}" = "XOpenBSD" ]; then
+ elif [ "${OSDETECT}" = "OpenBSD" ]; then
OSENUM=MANDOC_OS_OPENBSD
else
OSENUM=MANDOC_OS_OTHER
@@ -283,51 +291,40 @@ fi
# --- tests for config.h ----------------------------------------------
# --- library functions ---
+runtest cmsg CMSG "" "-D_XPG4_2" || true
runtest dirent-namlen DIRENT_NAMLEN || true
runtest be32toh ENDIAN || true
runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true
runtest EFTYPE EFTYPE || true
runtest err ERR || true
runtest getline GETLINE || true
-singletest getsubopt GETSUBOPT || \
- runtest getsubopt GETSUBOPT -D_GNU_SOURCE || true
+runtest getsubopt GETSUBOPT "" -D_GNU_SOURCE || true
runtest isblank ISBLANK || true
runtest mkdtemp MKDTEMP || true
+runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" "-lrt" || true
runtest ntohl NTOHL || true
runtest O_DIRECTORY O_DIRECTORY || true
runtest PATH_MAX PATH_MAX || true
runtest pledge PLEDGE || true
runtest sandbox_init SANDBOX_INIT || true
runtest progname PROGNAME || true
-singletest reallocarray REALLOCARRAY || \
- runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
-singletest recallocarray RECALLOCARRAY || \
- runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true
+runtest reallocarray REALLOCARRAY "" -D_OPENBSD_SOURCE || true
+runtest recallocarray RECALLOCARRAY "" -D_OPENBSD_SOURCE || true
+runtest recvmsg RECVMSG "${LD_RECVMSG}" "-lsocket" || true
runtest rewb-bsd REWB_BSD || true
runtest rewb-sysv REWB_SYSV || true
-singletest strcasestr STRCASESTR || \
- runtest strcasestr STRCASESTR -D_GNU_SOURCE || true
+runtest strcasestr STRCASESTR "" -D_GNU_SOURCE || true
runtest stringlist STRINGLIST || true
runtest strlcat STRLCAT || true
runtest strlcpy STRLCPY || true
runtest strndup STRNDUP || true
-singletest strptime STRPTIME || \
- runtest strptime STRPTIME -D_GNU_SOURCE || true
+runtest strptime STRPTIME "" -D_GNU_SOURCE || true
runtest strsep STRSEP || true
-singletest strtonum STRTONUM || \
- runtest strtonum STRTONUM -D_OPENBSD_SOURCE || true
-singletest vasprintf VASPRINTF || \
- runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
+runtest strtonum STRTONUM "" -D_OPENBSD_SOURCE || true
+runtest vasprintf VASPRINTF "" -D_GNU_SOURCE || true
-if [ ${HAVE_ENDIAN} -eq 0 -a \
- ${HAVE_SYS_ENDIAN} -eq 0 -a \
- ${HAVE_NTOHL} -eq 0 ]; then
- echo "FATAL: no endian conversion functions found" 1>&2
- echo "FATAL: no endian conversion functions found" 1>&3
- exit 1
-fi
-
-if [ "$1" == "-depend" ]; then
+# --- fts ---
+if [ "${1}" = "-depend" ]; then
HAVE_FTS=0
HAVE_FTS_COMPARE_CONST=0
echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&2
@@ -341,6 +338,7 @@ else
runtest fts FTS || true
fi
+# --- tagging support in the pager ---
if ismanual "less -T" LESS_T ${HAVE_LESS_T}; then
:
elif less -ET /dev/null test-noop.c 1>/dev/null 2>&3; then
@@ -357,9 +355,8 @@ fi
# --- wide character and locale support ---
if get_locale; then
- singletest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || \
- runtest wchar WCHAR -D_GNU_SOURCE \
- -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
+ runtest wchar WCHAR "-DUTF8_LOCALE=\"${UTF8_LOCALE}\"" \
+ "-D_GNU_SOURCE -DUTF8_LOCALE=\"${UTF8_LOCALE}\"" || true
else
HAVE_WCHAR=0
echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
@@ -367,69 +364,46 @@ else
echo 1>&3
fi
-# --- nanosleep ---
-if [ -n "${LD_NANOSLEEP}" ]; then
- runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true
-elif singletest nanosleep NANOSLEEP; then
- :
-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
-
-if [ ${BUILD_CATMAN} -gt 0 ]; then
- # --- recvmsg ---
- if [ -n "${LD_RECVMSG}" ]; then
- runtest recvmsg RECVMSG "${LD_RECVMSG}" || true
- elif singletest recvmsg RECVMSG; then
- :
- elif runtest recvmsg RECVMSG "-lsocket"; then
- LD_RECVMSG="-lsocket"
- fi
- if [ "${HAVE_RECVMSG}" -eq 0 ]; then
- echo "FATAL: recvmsg: no" 1>&2
- echo "FATAL: recvmsg: no" 1>&3
- echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
- exit 1
- fi
-
- # --- cmsg ---
- if singletest cmsg CMSG; then
- :
- elif runtest cmsg CMSG "-D_XPG4_2"; then
- HAVE_CMSG_XPG42=1
- fi
- if [ "${HAVE_CMSG}" -eq 0 ]; then
- echo "FATAL: cmsg: no" 1>&2
- echo "FATAL: cmsg: no" 1>&3
- echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
- exit 1
- fi
-fi
-
# --- ohash ---
-if [ "$1" == "-depend" ]; then
+if [ "${1}" = "-depend" ]; then
HAVE_OHASH=0
echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&2
echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&3
echo 1>&3
-elif ismanual ohash OHASH "${HAVE_OHASH}"; then
- :
-elif [ -n "${LD_OHASH}" ]; then
- runtest ohash OHASH "${LD_OHASH}" || true
-elif singletest ohash OHASH; then
- :
-elif runtest ohash OHASH "-lutil"; then
- LD_OHASH="-lutil"
+else
+ runtest ohash OHASH "${LD_OHASH}" "-lutil" || true
fi
if [ "${HAVE_OHASH}" -eq 0 ]; then
LD_OHASH=
fi
+# --- required functions ---
+if [ ${HAVE_ENDIAN} -eq 0 -a \
+ ${HAVE_SYS_ENDIAN} -eq 0 -a \
+ ${HAVE_NTOHL} -eq 0 ]; then
+ echo "FATAL: no endian conversion functions found" 1>&2
+ echo "FATAL: no endian conversion functions found" 1>&3
+ FATAL=1
+fi
+if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
+ echo "FATAL: nanosleep: no" 1>&2
+ echo "FATAL: nanosleep: no" 1>&3
+ FATAL=1
+fi
+if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_RECVMSG}" -eq 0 ]; then
+ echo "FATAL: recvmsg: no" 1>&2
+ echo "FATAL: recvmsg: no" 1>&3
+ echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
+ FATAL=1
+fi
+if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_CMSG}" -eq 0 ]; then
+ echo "FATAL: cmsg: no" 1>&2
+ echo "FATAL: cmsg: no" 1>&3
+ echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
+ FATAL=1
+fi
+[ "${FATAL}" -eq 0 ] || exit 1
+
# --- LDADD ---
LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
echo "selected LDADD=\"${LDADD}\"" 1>&2
@@ -477,9 +451,8 @@ if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
echo "#define be32toh ntohl"
echo "#define htobe32 htonl"
fi
-
cat << __HEREDOC__
-#define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
+
#define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
#define HAVE_ENDIAN ${HAVE_ENDIAN}
#define HAVE_ERR ${HAVE_ERR}
@@ -510,6 +483,7 @@ cat << __HEREDOC__
#define HAVE_VASPRINTF ${HAVE_VASPRINTF}
#define HAVE_WCHAR ${HAVE_WCHAR}
#define HAVE_OHASH ${HAVE_OHASH}
+#define NEED_XPG4_2 ${NEED_XPG4_2}
#define BINM_APROPOS "${BINM_APROPOS}"
#define BINM_CATMAN "${BINM_CATMAN}"
diff --git a/mandocd.c b/mandocd.c
index 1a597b38..60e40fed 100644
--- a/mandocd.c
+++ b/mandocd.c
@@ -1,4 +1,4 @@
-/* $Id: mandocd.c,v 1.11 2019/03/03 13:02:11 schwarze Exp $ */
+/* $Id: mandocd.c,v 1.12 2020/06/14 23:40:31 schwarze Exp $ */
/*
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
* Copyright (c) 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -17,7 +17,7 @@
*/
#include "config.h"
-#if HAVE_CMSG_XPG42
+#if NEED_XPG4_2
#define _XPG4_2
#endif