#!/bin/sh # # Copyright (c) 2014, 2015, 2016 Ingo Schwarze # Copyright (c) 2017, 2018 Kristaps Dzonsons # Copyright (c) 2022 Omar Polo # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. set -e if command -v yacc 2>/dev/null >&2; then YACC=yacc elif command -v bison 2>/dev/null >&2; then YACC=bison else YACC= fi while [ $# -gt 0 ]; do key="${1%%=*}" val="${1#*=}" if [ "$1" = "$key" ]; then echo "$0: invalid key-value: $1" >&2 exit 1 fi case "$key" in CC) CC="$val" ;; CFLAGS) CFLAGS="$val" ;; YACC) YACC="$val" ;; esac shift done if [ -z "$YACC" ]; then echo "fatal: can't find yacc or bison." >&2 exit 1 fi [ -w config.log ] && mv config.log config.log.old exec 3> config.log echo "config.log: writing..." CC="${CC:-cc}" CFLAGS="${CFLAGS:--O2 -pipe} -I." LIBS="${LIBS:-}" LDFLAGS="${LDFLAGS:-}" COMPATS= HAVE_ERR= HAVE_FREEZERO= HAVE_GETEXECNAME= HAVE_GETPROGNAME= HAVE_PLEDGE= HAVE_REALLOCARRAY= HAVE_STRLCAT= HAVE_STRLCPY= HAVE_STRTONUM= HAVE_SYS_QUEUE= HAVE_UNVEIL= HAVE_VASPRINTF= HAVE___PROGNAME= # singletest message var extra-cflags extra-libs singletest() { cat >&3 <&3 2>&3; then rm -f test-${1} test-${1}.d if [ -n "$3" ]; then echo "${1}: $CC $3 succeeded" >&3 echo "${1} ($3): yes" elif [ -n "${4}" ]; then echo "${1}: $CC $4 succeeded" >&3 echo "${1} ($4): yes" else echo "${1}: $CC succeeded" >&3 echo "${1}: yes" fi echo >&3 return 0 fi if [ -n "$3" ]; then echo "${1}: $CC $3 failed with $?" >&3 echo "${1} ($3): no" elif [ -n "${4}" ]; then echo "${1}: $CC $4 failed with $?" >&3 echo "${1} ($4): no" else echo "${1}: $CC failed with $?" >&3 echo "${1}: no" fi echo >&3 return 1 } # runtest message var extra-cflags extra-libs pkgconfig-name runtest() { if singletest "$1" "$2" "" ""; then eval HAVE_${2}=1 return 0 fi if [ -n "$3" -o -n "$4" ]; then echo "retrying with ${3+$3 }$4" >&3 if singletest "$1" "$2" "$3" "$4"; then if [ -n "$3" ]; then CFLAGS="$CFLAGS $3" fi if [ -n "${4}" ]; then LIBS="$LIBS $4" fi eval HAVE_${2}=1 return 0 fi fi if [ -f ./../compat/${1}.c ]; then COMPATS="${1}.o $COMPATS" fi eval HAVE_${2}=0 return 1 } if runtest MMD _MMD -MMD >/dev/null; then echo "adding -MMD to CFLAGS" >&2 echo "adding -MMD to CFLAGS" >&3 fi runtest err ERR || true runtest freezero FREEZERO || true runtest getexecname GETEXECNAME || true runtest getprogname GETPROGNAME || true runtest pledge PLEDGE || true runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true runtest strlcat STRLCAT || true runtest strlcpy STRLCPY || true runtest strtonum STRTONUM || true runtest sys_queue SYS_QUEUE || true runtest unveil UNVEIL || true runtest vasprintf VASPRINTF -D_GNU_SOURCE || true runtest __progname __PROGNAME || true if [ "${HAVE_SYS_QUEUE}" -eq 0 ]; then CFLAGS="-I ./../compat/sys ${CFLAGS}" fi if [ -n "${COMPATS}" ]; then CFLAGS="-I ./../compat/ ${CFLAGS}" fi exec > config.h echo "config.h: writing..." >&2 cat < config.mk echo "config.mk: writing..." >&2 cat <&2 echo >&2