diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-15 02:15:52 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-15 02:15:52 +0000 |
commit | 72b08051834f48e51407e7cebe8719cc5b6555a3 (patch) | |
tree | e68b559eae1648423af5c990f0c5ed0467ac2880 | |
parent | 239614951577ba74078ca14afdba3508fb622fcb (diff) | |
download | mandoc-72b08051834f48e51407e7cebe8719cc5b6555a3.tar.gz mandoc-72b08051834f48e51407e7cebe8719cc5b6555a3.tar.zst mandoc-72b08051834f48e51407e7cebe8719cc5b6555a3.zip |
Autodetect whether _GNU_SOURCE or _OPENBSD_SOURCE are needed; the
latter is a NetBSD idiosyncrasy reported by wiz@. Also take into
account that NetBSD declares getsubopt(3) in the wrong header.
-rwxr-xr-x | configure | 102 | ||||
-rw-r--r-- | test-getsubopt.c | 13 | ||||
-rw-r--r-- | test-strcasestr.c | 4 | ||||
-rw-r--r-- | test-strptime.c | 4 | ||||
-rw-r--r-- | test-vasprintf.c | 6 | ||||
-rw-r--r-- | test-wchar.c | 6 |
6 files changed, 70 insertions, 65 deletions
@@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: configure,v 1.66 2018/07/31 15:34:00 schwarze Exp $ +# $Id: configure,v 1.67 2018/08/15 02:15:52 schwarze Exp $ # # Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org> # @@ -90,6 +90,9 @@ HAVE_SYS_ENDIAN= HAVE_VASPRINTF= HAVE_WCHAR= +NEED_GNU_SOURCE=0 +NEED_OPENBSD_SOURCE=0 + PREFIX="/usr/local" BINDIR= SBINDIR= @@ -154,31 +157,34 @@ ismanual() { # In case of failure, do not decide anything yet. # Arguments: test file name, test var name, additional CFLAGS singletest() { + n=${1}${3}${4} cat 1>&3 << __HEREDOC__ -testing ${1}${3} ... -${COMP} -o test-${1} test-${1}.c ${3} +testing ${n} ... +${COMP} -o test-${1} test-${1}.c ${3} ${4} __HEREDOC__ - if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3 + if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} ${4} 1>&3 2>&3 then - echo "partial result of ${1}${3}: ${CC} succeeded" 1>&3 + echo "partial result of ${n}: ${CC} succeeded" 1>&3 else - echo "result of ${1}${3}: ${CC} failed with exit status $?" 1>&3 - echo "result of compiling ${1}${3}: no" 1>&3 + echo "result of ${n}: ${CC} failed with exit status $?" 1>&3 + echo "result of compiling ${n}: no" 1>&3 echo 1>&3 return 1 fi if ./test-${1} 1>&3 2>&3; then - echo "tested ${1}${3}: yes" 1>&2 - echo "result of running ${1}${3}: yes" 1>&3 + echo "tested ${n}: yes" 1>&2 + 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 rm "test-${1}" return 0 else - echo "result of ${1}${3}: execution failed with exit status $?" 1>&3 - echo "result of running ${1}${3}: no" 1>&3 + echo "result of ${n}: execution failed with exit status $?" 1>&3 + echo "result of running ${n}: no" 1>&3 echo 1>&3 rm "test-${1}" return 1 @@ -191,8 +197,8 @@ __HEREDOC__ runtest() { eval _manual=\${HAVE_${2}} ismanual "${1}" "${2}" "${_manual}" && return 0 - singletest "${1}" "${2}" "${3}" && return 0 - echo "tested ${1}${3}: no" 1>&2 + singletest "${1}" "${2}" "${3}" "${4}" && return 0 + echo "tested ${1}${3}${4}: no" 1>&2 eval HAVE_${2}=0 return 1 } @@ -215,26 +221,30 @@ get_locale() { # --- compiler options ------------------------------------------------- +DEFCFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter" + if [ -n "${CFLAGS}" ]; then - COMP="${CC} ${CFLAGS}" - echo "selected CFLAGS=\"${CFLAGS}\" (manual)" 1>&2 - echo "selected CFLAGS=\"${CFLAGS}\" (manual)" 1>&3 - echo 1>&3 -else - CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes" - CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter" COMP="${CC} ${CFLAGS} -Wno-unused -Werror" - echo -n "tested ${CC} -W: " 1>&2 - echo -n "testing ${CC} -W: " 1>&3 - runtest noop WFLAG || true - if [ "${HAVE_WFLAG}" -eq 0 ]; then - CFLAGS="-g" - COMP="${CC} ${CFLAGS}" - fi - echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2 - echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3 - echo 1>&3 +else + COMP="${CC} ${DEFCFLAGS} -Wno-unused -Werror" +fi +echo -n "tested ${CC} -W: " 1>&2 +echo -n "testing ${CC} -W: " 1>&3 +runtest noop WFLAG || true + +if [ -n "${CFLAGS}" ]; then + echo "CFLAGS specified manually:" 1>&3 +elif [ ${HAVE_WFLAG} -eq 0 ]; then + CFLAGS="-g" +else + CFLAGS="${DEFCFLAGS}" fi +echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2 +echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3 +echo 1>&3 + +COMP="${CC} ${CFLAGS}" +[ ${HAVE_WFLAG} -eq 0 ] || COMP="${COMP} -Wno-unused -Werror" if [ -n "${STATIC}" ]; then echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2 @@ -257,7 +267,8 @@ runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true runtest EFTYPE EFTYPE || true runtest err ERR || true runtest getline GETLINE || true -runtest getsubopt GETSUBOPT || true +singletest getsubopt GETSUBOPT || \ + runtest getsubopt GETSUBOPT -D_GNU_SOURCE || true runtest isblank ISBLANK || true runtest mkdtemp MKDTEMP || true runtest ntohl NTOHL || true @@ -266,19 +277,25 @@ runtest PATH_MAX PATH_MAX || true runtest pledge PLEDGE || true runtest sandbox_init SANDBOX_INIT || true runtest progname PROGNAME || true -runtest reallocarray REALLOCARRAY || true -runtest recallocarray RECALLOCARRAY || true +singletest reallocarray REALLOCARRAY || \ + runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true +singletest recallocarray RECALLOCARRAY || \ + runtest recallocarray RECALLOCARRAY -D_OPENBSD_SOURCE || true runtest rewb-bsd REWB_BSD || true runtest rewb-sysv REWB_SYSV || true -runtest strcasestr STRCASESTR || true +singletest strcasestr STRCASESTR || \ + runtest strcasestr STRCASESTR -D_GNU_SOURCE || true runtest stringlist STRINGLIST || true runtest strlcat STRLCAT || true runtest strlcpy STRLCPY || true runtest strndup STRNDUP || true -runtest strptime STRPTIME || true +singletest strptime STRPTIME || \ + runtest strptime STRPTIME -D_GNU_SOURCE || true runtest strsep STRSEP || true -runtest strtonum STRTONUM || true -runtest vasprintf VASPRINTF || true +singletest strtonum STRTONUM || \ + runtest strtonum STRTONUM -D_OPENBSD_SOURCE || true +singletest vasprintf VASPRINTF || \ + runtest vasprintf VASPRINTF -D_GNU_SOURCE || true if [ ${HAVE_ENDIAN} -eq 0 -a \ ${HAVE_SYS_ENDIAN} -eq 0 -a \ @@ -298,7 +315,9 @@ fi # --- wide character and locale support --- if get_locale; then - runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true + singletest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || \ + runtest wchar WCHAR -D_GNU_SOURCE \ + -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true else HAVE_WCHAR=0 echo "tested wchar: no (no UTF8_LOCALE)" 1>&2 @@ -383,12 +402,11 @@ cat << __HEREDOC__ #define __attribute__(x) #endif -#if defined(__linux__) || defined(__MINT__) -#define _GNU_SOURCE /* See test-*.c what needs this. */ -#endif - __HEREDOC__ +[ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE" +[ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE" + [ ${HAVE_GETLINE} -eq 0 -o \ ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \ ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \ diff --git a/test-getsubopt.c b/test-getsubopt.c index afcc5599..752c1cde 100644 --- a/test-getsubopt.c +++ b/test-getsubopt.c @@ -1,4 +1,4 @@ -/* $Id: test-getsubopt.c,v 1.4 2015/10/06 18:32:20 schwarze Exp $ */ +/* $Id: test-getsubopt.c,v 1.5 2018/08/15 02:15:52 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -15,12 +15,15 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#if defined(__linux__) || defined(__MINT__) -#define _GNU_SOURCE /* getsubopt() */ -#endif - #include <stdlib.h> +/* + * NetBSD declares this function in the wrong header. + * No harm is done by allowing that, too: + * The only file using it, main.c, also includes unistd.h, anyway. + */ +#include <unistd.h> + int main(void) { diff --git a/test-strcasestr.c b/test-strcasestr.c index c3a87de8..0b1a576b 100644 --- a/test-strcasestr.c +++ b/test-strcasestr.c @@ -1,7 +1,3 @@ -#if defined(__linux__) || defined(__MINT__) -# define _GNU_SOURCE /* strcasestr() */ -#endif - #include <string.h> int diff --git a/test-strptime.c b/test-strptime.c index d8799e94..a34cbd77 100644 --- a/test-strptime.c +++ b/test-strptime.c @@ -1,7 +1,3 @@ -#if defined(__linux__) || defined(__MINT__) -# define _GNU_SOURCE /* strptime() */ -#endif - #include <time.h> int diff --git a/test-vasprintf.c b/test-vasprintf.c index ee6980a2..1e762697 100644 --- a/test-vasprintf.c +++ b/test-vasprintf.c @@ -1,4 +1,4 @@ -/* $Id: test-vasprintf.c,v 1.4 2016/07/18 18:35:05 schwarze Exp $ */ +/* $Id: test-vasprintf.c,v 1.5 2018/08/15 02:15:52 schwarze Exp $ */ /* * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org> * @@ -15,10 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#if defined(__linux__) || defined(__MINT__) -#define _GNU_SOURCE /* vasprintf() */ -#endif - #include <stdarg.h> #include <stdio.h> #include <string.h> diff --git a/test-wchar.c b/test-wchar.c index 32962d9f..7095d8ba 100644 --- a/test-wchar.c +++ b/test-wchar.c @@ -1,4 +1,4 @@ -/* $Id: test-wchar.c,v 1.4 2016/07/31 09:29:13 schwarze Exp $ */ +/* $Id: test-wchar.c,v 1.5 2018/08/15 02:15:52 schwarze Exp $ */ /* * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> * @@ -15,10 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#if defined(__linux__) || defined(__MINT__) -#define _GNU_SOURCE /* wcwidth() */ -#endif - #include <locale.h> #include <stdio.h> #include <wchar.h> |