Home | History | Annotate | Line # | Download | only in dist
      1   1.1     joerg #!/bin/sh
      2   1.1     joerg #
      3  1.15       wiz # Id: configure,v 1.81 2021/09/20 10:19:51 schwarze Exp 
      4   1.7  christos #
      5  1.15       wiz # Copyright (c) 2014-2021 Ingo Schwarze <schwarze (at] openbsd.org>
      6   1.1     joerg #
      7   1.1     joerg # Permission to use, copy, modify, and distribute this software for any
      8   1.1     joerg # purpose with or without fee is hereby granted, provided that the above
      9   1.1     joerg # copyright notice and this permission notice appear in all copies.
     10   1.1     joerg #
     11   1.1     joerg # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12   1.1     joerg # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13   1.1     joerg # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14   1.1     joerg # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15   1.1     joerg # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16   1.1     joerg # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17   1.1     joerg # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18   1.1     joerg 
     19   1.1     joerg set -e
     20   1.1     joerg 
     21   1.5  christos [ -w config.log ] && mv config.log config.log.old
     22   1.5  christos [ -w config.h   ] && mv config.h config.h.old
     23   1.1     joerg 
     24   1.2  christos # Output file descriptor usage:
     25   1.2  christos # 1 (stdout): config.h, Makefile.local
     26   1.2  christos # 2 (stderr): original stderr, usually to the console
     27   1.2  christos # 3: config.log
     28   1.1     joerg 
     29   1.2  christos exec 3> config.log
     30  1.11  christos echo "file config.log: writing..."
     31   1.2  christos 
     32   1.2  christos # --- default settings -------------------------------------------------
     33   1.2  christos # Initialize all variables here,
     34   1.2  christos # such that nothing can leak in from the environment.
     35   1.2  christos 
     36  1.15       wiz SOURCEDIR=`dirname "${0}"`
     37   1.7  christos 
     38  1.11  christos MANPATH_BASE="/usr/share/man:/usr/X11R6/man"
     39   1.5  christos MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
     40  1.14  christos OSENUM=
     41   1.2  christos OSNAME=
     42   1.4  christos MAKEFLAGS=
     43   1.7  christos UTF8_LOCALE=
     44   1.2  christos 
     45  1.15       wiz AR=ar
     46  1.16     palle : "${CC:=cc}"
     47  1.15       wiz CFLAGS=
     48  1.15       wiz FATAL=0
     49   1.5  christos LDADD=
     50   1.5  christos LDFLAGS=
     51   1.7  christos LD_NANOSLEEP=
     52   1.5  christos LD_OHASH=
     53   1.7  christos LD_RECVMSG=
     54  1.11  christos STATIC=
     55   1.2  christos 
     56   1.2  christos BUILD_CGI=0
     57   1.7  christos BUILD_CATMAN=0
     58   1.7  christos INSTALL_LIBMANDOC=0
     59   1.2  christos 
     60  1.15       wiz HAVE_ATTRIBUTE=
     61   1.7  christos HAVE_CMSG=
     62   1.2  christos HAVE_DIRENT_NAMLEN=
     63   1.7  christos HAVE_EFTYPE=
     64   1.7  christos HAVE_ENDIAN=
     65   1.5  christos HAVE_ERR=
     66   1.2  christos HAVE_FTS=
     67   1.7  christos HAVE_FTS_COMPARE_CONST=
     68   1.5  christos HAVE_GETLINE=
     69   1.2  christos HAVE_GETSUBOPT=
     70   1.5  christos HAVE_ISBLANK=
     71  1.14  christos HAVE_LESS_T=
     72   1.5  christos HAVE_MKDTEMP=
     73  1.15       wiz HAVE_MKSTEMPS=
     74   1.7  christos HAVE_NANOSLEEP=
     75   1.7  christos HAVE_NTOHL=
     76   1.7  christos HAVE_O_DIRECTORY=
     77   1.7  christos HAVE_OHASH=
     78   1.7  christos HAVE_PATH_MAX=
     79   1.5  christos HAVE_PLEDGE=
     80   1.5  christos HAVE_PROGNAME=
     81   1.2  christos HAVE_REALLOCARRAY=
     82  1.11  christos HAVE_RECALLOCARRAY=
     83   1.7  christos HAVE_RECVMSG=
     84   1.5  christos HAVE_REWB_BSD=
     85   1.5  christos HAVE_REWB_SYSV=
     86   1.5  christos HAVE_SANDBOX_INIT=
     87   1.2  christos HAVE_STRCASESTR=
     88   1.5  christos HAVE_STRINGLIST=
     89   1.2  christos HAVE_STRLCAT=
     90   1.2  christos HAVE_STRLCPY=
     91  1.11  christos HAVE_STRNDUP=
     92   1.2  christos HAVE_STRPTIME=
     93   1.2  christos HAVE_STRSEP=
     94   1.2  christos HAVE_STRTONUM=
     95   1.7  christos HAVE_SYS_ENDIAN=
     96   1.5  christos HAVE_VASPRINTF=
     97   1.2  christos HAVE_WCHAR=
     98   1.2  christos 
     99  1.14  christos NEED_GNU_SOURCE=0
    100  1.14  christos NEED_OPENBSD_SOURCE=0
    101  1.15       wiz NEED_XPG4_2=0
    102  1.15       wiz 
    103  1.15       wiz MANDOC_COBJS=
    104  1.15       wiz SOELIM_COBJS=
    105  1.14  christos 
    106   1.2  christos PREFIX="/usr/local"
    107   1.2  christos BINDIR=
    108   1.2  christos SBINDIR=
    109  1.11  christos BIN_FROM_SBIN=
    110   1.2  christos INCLUDEDIR=
    111   1.2  christos LIBDIR=
    112   1.2  christos MANDIR=
    113  1.15       wiz READ_ALLOWED_PATH=
    114   1.2  christos 
    115   1.2  christos WWWPREFIX="/var/www"
    116   1.2  christos HTDOCDIR=
    117   1.2  christos CGIBINDIR=
    118   1.2  christos 
    119   1.2  christos BINM_APROPOS="apropos"
    120   1.7  christos BINM_CATMAN="catman"
    121   1.5  christos BINM_MAKEWHATIS="makewhatis"
    122   1.2  christos BINM_MAN="man"
    123   1.5  christos BINM_SOELIM="soelim"
    124   1.2  christos BINM_WHATIS="whatis"
    125  1.15       wiz BINM_PAGER=
    126   1.2  christos MANM_MAN="man"
    127   1.5  christos MANM_MANCONF="man.conf"
    128   1.2  christos MANM_MDOC="mdoc"
    129   1.2  christos MANM_ROFF="roff"
    130   1.2  christos MANM_EQN="eqn"
    131   1.2  christos MANM_TBL="tbl"
    132   1.2  christos 
    133   1.2  christos INSTALL="install"
    134   1.2  christos INSTALL_PROGRAM=
    135   1.2  christos INSTALL_LIB=
    136   1.2  christos INSTALL_MAN=
    137   1.2  christos INSTALL_DATA=
    138   1.7  christos LN="ln -f"
    139   1.2  christos 
    140   1.2  christos # --- manual settings from configure.local -----------------------------
    141   1.2  christos 
    142   1.5  christos if [ -r ./configure.local ]; then
    143  1.11  christos 	echo "file configure.local: reading..." 1>&2
    144  1.11  christos 	echo "file configure.local: reading..." 1>&3
    145   1.2  christos 	cat ./configure.local 1>&3
    146   1.2  christos 	. ./configure.local
    147   1.2  christos else
    148  1.11  christos 	echo "file configure.local: no (fully automatic configuration)" 1>&2
    149  1.11  christos 	echo "file configure.local: no (fully automatic configuration)" 1>&3
    150   1.2  christos fi
    151   1.2  christos echo 1>&3
    152   1.2  christos 
    153  1.11  christos # --- tests functions --------------------------------------------------
    154   1.2  christos 
    155   1.2  christos # Check whether this HAVE_ setting is manually overridden.
    156   1.2  christos # If yes, use the override, if no, do not decide anything yet.
    157  1.11  christos # Arguments: test file name, test var name, manual value
    158   1.2  christos ismanual() {
    159   1.7  christos 	[ -z "${3}" ] && return 1
    160  1.11  christos 	echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&2
    161  1.11  christos 	echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&3
    162   1.2  christos 	echo 1>&3
    163   1.2  christos 	return 0
    164   1.2  christos }
    165   1.2  christos 
    166   1.2  christos # Run a single autoconfiguration test.
    167   1.2  christos # In case of success, enable the feature.
    168   1.2  christos # In case of failure, do not decide anything yet.
    169  1.11  christos # Arguments: test file name, test var name, additional CFLAGS
    170   1.2  christos singletest() {
    171  1.15       wiz 	n=${1}${3}
    172   1.2  christos 	cat 1>&3 << __HEREDOC__
    173  1.14  christos testing ${n} ...
    174  1.15       wiz ${COMP} -o test-${1} test-${1}.c ${3}
    175   1.2  christos __HEREDOC__
    176   1.2  christos 
    177  1.15       wiz 	if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
    178   1.7  christos 	then
    179  1.14  christos 		echo "partial result of ${n}: ${CC} succeeded" 1>&3
    180   1.2  christos 	else
    181  1.15       wiz 		echo "tested ${n}: no (compilation failed)" 1>&2
    182  1.14  christos 		echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
    183  1.14  christos 		echo "result of compiling ${n}: no" 1>&3
    184   1.2  christos 		echo 1>&3
    185   1.2  christos 		return 1
    186   1.2  christos 	fi
    187   1.2  christos 
    188   1.2  christos 	if ./test-${1} 1>&3 2>&3; then
    189  1.14  christos 		echo "tested ${n}: yes" 1>&2
    190  1.14  christos 		echo "result of running ${n}: yes" 1>&3
    191   1.2  christos 		echo 1>&3
    192   1.2  christos 		eval HAVE_${2}=1
    193  1.15       wiz 		[ "${3}" = "-D_GNU_SOURCE" ] && NEED_GNU_SOURCE=1
    194  1.15       wiz 		[ "${3}" = "-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE=1
    195  1.15       wiz 		[ "${3}" = "-D_XPG4_2" ] && NEED_XPG4_2=1
    196  1.15       wiz 		[ "${3}" = "-lrt" ] && LD_NANOSLEEP="-lrt"
    197  1.15       wiz 		[ "${3}" = "-lsocket" ] && LD_RECVMSG="-lsocket"
    198  1.15       wiz 		[ "${3}" = "-lutil" ] && LD_OHASH="-lutil"
    199   1.2  christos 		rm "test-${1}"
    200   1.2  christos 		return 0
    201   1.2  christos 	else
    202  1.15       wiz 		echo "tested ${n}: no (execution failed)" 1>&2
    203  1.14  christos 		echo "result of ${n}: execution failed with exit status $?" 1>&3
    204  1.14  christos 		echo "result of running ${n}: no" 1>&3
    205   1.2  christos 		echo 1>&3
    206   1.2  christos 		rm "test-${1}"
    207   1.2  christos 		return 1
    208   1.2  christos 	fi
    209   1.2  christos }
    210   1.2  christos 
    211   1.2  christos # Run a complete autoconfiguration test, including the check for
    212   1.2  christos # a manual override and disabling the feature on failure.
    213  1.11  christos # Arguments: test file name, test var name, additional CFLAGS
    214  1.15       wiz # The final argument can optionally be repeated a second time.
    215   1.1     joerg runtest() {
    216   1.2  christos 	eval _manual=\${HAVE_${2}}
    217   1.7  christos 	ismanual "${1}" "${2}" "${_manual}" && return 0
    218  1.15       wiz 	singletest "${1}" "${2}" "${3}" && return 0
    219  1.15       wiz 	[ -n "${4}" ] && singletest "${1}" "${2}" "${4}" && return 0
    220   1.2  christos 	eval HAVE_${2}=0
    221   1.2  christos 	return 1
    222   1.1     joerg }
    223   1.1     joerg 
    224   1.7  christos # Select a UTF-8 locale.
    225   1.7  christos get_locale() {
    226   1.7  christos 	[ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
    227  1.15       wiz 	ismanual UTF8_LOCALE UTF8_LOCALE "${UTF8_LOCALE}" && return 0
    228  1.11  christos 	echo "testing UTF8_LOCALE ..." 1>&3
    229   1.7  christos 	UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
    230   1.7  christos 	if [ -z "${UTF8_LOCALE}" ]; then
    231   1.7  christos 		UTF8_LOCALE=`locale -a | grep -i '\.UTF-*8' | head -n 1`
    232   1.7  christos 		[ -n "${UTF8_LOCALE}" ] || return 1
    233   1.7  christos 	fi
    234  1.11  christos 	echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
    235  1.11  christos 	echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
    236   1.7  christos 	echo 1>&3
    237   1.7  christos 	return 0;
    238   1.7  christos }
    239   1.7  christos 
    240  1.14  christos # --- operating system -------------------------------------------------
    241  1.14  christos 
    242  1.14  christos if [ -n "${OSENUM}" ]; then
    243  1.14  christos 	echo "OSENUM specified manually: ${OSENUM}" 1>&2
    244  1.14  christos 	echo "OSENUM specified manually: ${OSENUM}" 1>&3
    245  1.14  christos else
    246  1.14  christos 	OSDETECT=`uname`
    247  1.15       wiz 	if [ "${OSDETECT}" = "NetBSD" ]; then
    248  1.14  christos 		OSENUM=MANDOC_OS_NETBSD
    249  1.15       wiz 	elif [ "${OSDETECT}" = "OpenBSD" ]; then
    250  1.14  christos 		OSENUM=MANDOC_OS_OPENBSD
    251  1.14  christos 	else
    252  1.14  christos 		OSENUM=MANDOC_OS_OTHER
    253  1.14  christos 	fi
    254  1.14  christos 	echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&2
    255  1.14  christos 	echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&3
    256  1.14  christos 	unset OSDETECT
    257  1.14  christos fi
    258  1.14  christos echo 1>&3
    259  1.14  christos 
    260  1.11  christos # --- compiler options -------------------------------------------------
    261  1.11  christos 
    262  1.14  christos DEFCFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter"
    263  1.14  christos 
    264  1.14  christos if [ -n "${CFLAGS}" ]; then
    265  1.14  christos 	COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
    266  1.14  christos else
    267  1.14  christos 	COMP="${CC} ${DEFCFLAGS} -Wno-unused -Werror"
    268  1.14  christos fi
    269  1.15       wiz printf "%s" "tested ${CC} -W: " 1>&2
    270  1.15       wiz printf "%s" "testing ${CC} -W: " 1>&3
    271  1.14  christos runtest noop WFLAG || true
    272  1.14  christos 
    273  1.11  christos if [ -n "${CFLAGS}" ]; then
    274  1.14  christos 	echo "CFLAGS specified manually:" 1>&3
    275  1.14  christos elif [ ${HAVE_WFLAG} -eq 0 ]; then
    276  1.14  christos 	CFLAGS="-g"
    277  1.11  christos else
    278  1.14  christos 	CFLAGS="${DEFCFLAGS}"
    279  1.11  christos fi
    280  1.14  christos echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2
    281  1.14  christos echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3
    282  1.14  christos echo 1>&3
    283  1.14  christos 
    284  1.14  christos COMP="${CC} ${CFLAGS}"
    285  1.14  christos [ ${HAVE_WFLAG} -eq 0 ] || COMP="${COMP} -Wno-unused -Werror"
    286  1.11  christos 
    287  1.11  christos if [ -n "${STATIC}" ]; then
    288  1.11  christos 	echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2
    289  1.11  christos 	echo "selected STATIC=\"${STATIC}\" (manual)" 1>&3
    290  1.11  christos 	echo 1>&3
    291  1.11  christos else
    292  1.11  christos 	runtest noop STATIC -static || true
    293  1.11  christos 	[ ${HAVE_STATIC} -eq 0 ] || STATIC="-static"
    294  1.11  christos 	echo "selected STATIC=\"${STATIC}\"" 1>&2
    295  1.11  christos 	echo "selected STATIC=\"${STATIC}\"" 1>&3
    296  1.11  christos 	echo 1>&3
    297  1.11  christos fi
    298  1.11  christos 
    299  1.11  christos # --- tests for config.h  ----------------------------------------------
    300   1.7  christos 
    301   1.2  christos # --- library functions ---
    302  1.15       wiz runtest attribute	ATTRIBUTE	|| true
    303  1.15       wiz runtest cmsg		CMSG		"" "-D_XPG4_2" || true
    304   1.2  christos runtest dirent-namlen	DIRENT_NAMLEN	|| true
    305   1.7  christos runtest be32toh		ENDIAN		|| true
    306   1.7  christos runtest be32toh		SYS_ENDIAN	-DSYS_ENDIAN || true
    307   1.7  christos runtest EFTYPE		EFTYPE		|| true
    308   1.5  christos runtest err		ERR		|| true
    309   1.5  christos runtest getline		GETLINE		|| true
    310  1.15       wiz runtest getsubopt	GETSUBOPT	"" -D_GNU_SOURCE || true
    311   1.5  christos runtest isblank		ISBLANK		|| true
    312   1.5  christos runtest mkdtemp		MKDTEMP		|| true
    313  1.15       wiz runtest mkstemps	MKSTEMPS	|| true
    314  1.15       wiz runtest nanosleep	NANOSLEEP	"${LD_NANOSLEEP}" "-lrt" || true
    315   1.7  christos runtest ntohl		NTOHL		|| true
    316   1.7  christos runtest O_DIRECTORY	O_DIRECTORY	|| true
    317   1.7  christos runtest PATH_MAX	PATH_MAX	|| true
    318   1.5  christos runtest pledge		PLEDGE		|| true
    319   1.5  christos runtest sandbox_init	SANDBOX_INIT	|| true
    320   1.5  christos runtest progname	PROGNAME	|| true
    321  1.15       wiz runtest reallocarray	REALLOCARRAY	"" -D_OPENBSD_SOURCE || true
    322  1.15       wiz runtest recallocarray	RECALLOCARRAY	"" -D_OPENBSD_SOURCE || true
    323  1.15       wiz runtest recvmsg		RECVMSG		"${LD_RECVMSG}" "-lsocket" || true
    324   1.5  christos runtest rewb-bsd	REWB_BSD	|| true
    325   1.5  christos runtest rewb-sysv	REWB_SYSV	|| true
    326  1.15       wiz runtest strcasestr	STRCASESTR	"" -D_GNU_SOURCE || true
    327   1.5  christos runtest stringlist	STRINGLIST	|| true
    328   1.2  christos runtest strlcat		STRLCAT		|| true
    329   1.2  christos runtest strlcpy		STRLCPY		|| true
    330  1.11  christos runtest strndup		STRNDUP		|| true
    331  1.15       wiz runtest strptime	STRPTIME	"" -D_GNU_SOURCE || true
    332   1.2  christos runtest strsep		STRSEP		|| true
    333  1.15       wiz runtest strtonum	STRTONUM	"" -D_OPENBSD_SOURCE || true
    334  1.15       wiz runtest vasprintf	VASPRINTF	"" -D_GNU_SOURCE || true
    335   1.2  christos 
    336  1.15       wiz # --- fts ---
    337  1.15       wiz if [ "${1}" = "-depend" ]; then
    338  1.15       wiz 	HAVE_FTS=0
    339  1.15       wiz 	HAVE_FTS_COMPARE_CONST=0
    340  1.15       wiz 	echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&2
    341  1.15       wiz 	echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&3
    342  1.15       wiz 	echo 1>&3
    343  1.15       wiz elif ismanual fts FTS ${HAVE_FTS}; then
    344   1.7  christos 	HAVE_FTS_COMPARE_CONST=0
    345   1.7  christos elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then
    346   1.7  christos 	HAVE_FTS=1
    347   1.7  christos else
    348   1.7  christos 	runtest fts FTS || true
    349   1.7  christos fi
    350   1.7  christos 
    351  1.15       wiz # --- pager ---
    352  1.15       wiz manual=
    353  1.15       wiz if [ -n "${BINM_PAGER}" ]; then
    354  1.15       wiz 	manual=" (manual)"
    355  1.15       wiz elif less test-noop.c 1>/dev/null 2>&3; then
    356  1.15       wiz 	BINM_PAGER=less
    357  1.15       wiz 	echo "tested less: yes" 1>&2
    358  1.15       wiz 	echo "tested less: yes" 1>&3
    359  1.15       wiz else
    360  1.15       wiz 	BINM_PAGER=more
    361  1.15       wiz 	echo "tested less: no" 1>&2
    362  1.15       wiz 	echo "tested less: no" 1>&3
    363  1.15       wiz fi
    364  1.15       wiz echo "selected BINM_PAGER=${BINM_PAGER}${manual}" 1>&2
    365  1.15       wiz echo "selected BINM_PAGER=${BINM_PAGER}${manual}" 1>&3
    366  1.15       wiz 
    367  1.15       wiz # --- tagging support in the pager ---
    368  1.15       wiz if ismanual "${BINM_PAGER} -T" LESS_T ${HAVE_LESS_T}; then
    369  1.14  christos 	:
    370  1.15       wiz elif ${BINM_PAGER} -T /dev/null test-noop.c 1>/dev/null 2>&3; then
    371  1.14  christos 	HAVE_LESS_T=1
    372  1.15       wiz 	echo "tested ${BINM_PAGER} -T: yes" 1>&2
    373  1.15       wiz 	echo "tested ${BINM_PAGER} -T: yes" 1>&3
    374  1.14  christos 	echo 1>&3
    375  1.14  christos else
    376  1.14  christos 	HAVE_LESS_T=0
    377  1.15       wiz 	echo "tested ${BINM_PAGER} -T: no" 1>&2
    378  1.15       wiz 	echo "tested ${BINM_PAGER} -T: no" 1>&3
    379  1.14  christos 	echo 1>&3
    380  1.14  christos fi
    381  1.14  christos 
    382   1.7  christos # --- wide character and locale support ---
    383   1.7  christos if get_locale; then
    384  1.15       wiz 	runtest wchar WCHAR "-DUTF8_LOCALE=\"${UTF8_LOCALE}\"" \
    385  1.15       wiz 	    "-D_GNU_SOURCE -DUTF8_LOCALE=\"${UTF8_LOCALE}\"" || true
    386   1.7  christos else
    387   1.7  christos 	HAVE_WCHAR=0
    388  1.11  christos 	echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
    389  1.11  christos 	echo "tested wchar: no (no UTF8_LOCALE)" 1>&3
    390  1.11  christos 	echo 1>&3
    391   1.7  christos fi
    392   1.7  christos 
    393  1.15       wiz # --- ohash ---
    394  1.15       wiz if [ "${1}" = "-depend" ]; then
    395  1.15       wiz 	HAVE_OHASH=0
    396  1.15       wiz 	echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&2
    397  1.15       wiz 	echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&3
    398  1.15       wiz 	echo 1>&3
    399  1.15       wiz else
    400  1.15       wiz 	runtest ohash OHASH "${LD_OHASH}" "-lutil" || true
    401  1.15       wiz fi
    402  1.15       wiz if [ "${HAVE_OHASH}" -eq 0 ]; then
    403  1.15       wiz 	LD_OHASH=
    404  1.15       wiz fi
    405  1.15       wiz 
    406  1.15       wiz # --- required functions ---
    407  1.15       wiz if [ ${HAVE_ENDIAN} -eq 0 -a \
    408  1.15       wiz      ${HAVE_SYS_ENDIAN} -eq 0 -a \
    409  1.15       wiz      ${HAVE_NTOHL} -eq 0 ]; then
    410  1.15       wiz 	echo "FATAL: no endian conversion functions found" 1>&2
    411  1.15       wiz 	echo "FATAL: no endian conversion functions found" 1>&3
    412  1.15       wiz 	FATAL=1
    413   1.7  christos fi
    414   1.7  christos if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
    415   1.7  christos 	echo "FATAL: nanosleep: no" 1>&2
    416   1.7  christos 	echo "FATAL: nanosleep: no" 1>&3
    417  1.15       wiz 	FATAL=1
    418   1.5  christos fi
    419  1.15       wiz if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_RECVMSG}" -eq 0 ]; then
    420  1.15       wiz 	echo "FATAL: recvmsg: no" 1>&2
    421  1.15       wiz 	echo "FATAL: recvmsg: no" 1>&3
    422  1.15       wiz 	echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
    423  1.15       wiz 	FATAL=1
    424  1.15       wiz fi
    425  1.15       wiz if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_CMSG}" -eq 0 ]; then
    426  1.15       wiz 	echo "FATAL: cmsg: no" 1>&2
    427  1.15       wiz 	echo "FATAL: cmsg: no" 1>&3
    428  1.15       wiz 	echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
    429  1.15       wiz 	FATAL=1
    430   1.2  christos fi
    431  1.15       wiz [ "${FATAL}" -eq 0 ] || exit 1
    432   1.2  christos 
    433   1.5  christos # --- LDADD ---
    434   1.7  christos LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
    435  1.11  christos echo "selected LDADD=\"${LDADD}\"" 1>&2
    436  1.11  christos echo "selected LDADD=\"${LDADD}\"" 1>&3
    437   1.5  christos echo 1>&3
    438   1.2  christos 
    439   1.2  christos # --- write config.h ---
    440   1.2  christos 
    441   1.2  christos exec > config.h
    442   1.2  christos 
    443   1.2  christos cat << __HEREDOC__
    444   1.5  christos #ifdef __cplusplus
    445   1.5  christos #error "Do not use C++.  See the INSTALL file."
    446   1.5  christos #endif
    447   1.5  christos 
    448   1.2  christos #ifdef HAVE_NBTOOL_CONFIG_H
    449   1.2  christos #include "nbtool_config.h"
    450   1.2  christos #endif
    451   1.2  christos 
    452   1.2  christos __HEREDOC__
    453  1.14  christos [ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE"
    454  1.14  christos [ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE"
    455   1.2  christos 
    456  1.11  christos [ ${HAVE_GETLINE} -eq 0 -o \
    457  1.11  christos   ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
    458  1.11  christos   ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
    459  1.11  christos   ${HAVE_STRNDUP} -eq 0 ] \
    460   1.2  christos 	&& echo "#include <sys/types.h>"
    461   1.5  christos [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
    462   1.5  christos [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
    463   1.2  christos 
    464   1.1     joerg echo
    465   1.5  christos echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
    466  1.11  christos echo "#define MANPATH_BASE \"${MANPATH_BASE}\""
    467   1.5  christos echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
    468  1.14  christos echo "#define OSENUM ${OSENUM}"
    469   1.2  christos [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
    470   1.7  christos [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
    471  1.15       wiz [ -n "${READ_ALLOWED_PATH}" ] \
    472  1.15       wiz 	&& echo "#define READ_ALLOWED_PATH \"${READ_ALLOWED_PATH}\""
    473  1.15       wiz [ ${HAVE_ATTRIBUTE} -eq 0 ] && echo "#define __attribute__(x)"
    474   1.8  christos [ ${HAVE_EFTYPE} -eq 0 ] && echo "#ifndef EFTYPE" && \
    475   1.8  christos     echo "#define EFTYPE EINVAL" && echo "#endif"
    476   1.7  christos [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
    477   1.7  christos [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
    478   1.7  christos if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
    479   1.7  christos 	echo "#define be32toh ntohl"
    480   1.7  christos 	echo "#define htobe32 htonl"
    481   1.7  christos fi
    482   1.2  christos cat << __HEREDOC__
    483   1.2  christos #ifndef HAVE_NBTOOL_CONFIG_H
    484   1.2  christos #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
    485   1.7  christos #define HAVE_ENDIAN ${HAVE_ENDIAN}
    486   1.5  christos #define HAVE_ERR ${HAVE_ERR}
    487   1.2  christos #define HAVE_FTS ${HAVE_FTS}
    488   1.7  christos #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
    489   1.5  christos #define HAVE_GETLINE ${HAVE_GETLINE}
    490   1.2  christos #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
    491   1.5  christos #define HAVE_ISBLANK ${HAVE_ISBLANK}
    492  1.14  christos #define HAVE_LESS_T ${HAVE_LESS_T}
    493   1.5  christos #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
    494  1.15       wiz #define HAVE_MKSTEMPS ${HAVE_MKSTEMPS}
    495   1.7  christos #define HAVE_NTOHL ${HAVE_NTOHL}
    496   1.5  christos #define HAVE_PLEDGE ${HAVE_PLEDGE}
    497   1.5  christos #define HAVE_PROGNAME ${HAVE_PROGNAME}
    498   1.2  christos #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
    499  1.11  christos #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
    500   1.5  christos #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
    501   1.5  christos #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
    502   1.5  christos #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
    503   1.2  christos #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
    504   1.5  christos #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
    505   1.2  christos #define HAVE_STRLCAT ${HAVE_STRLCAT}
    506   1.2  christos #define HAVE_STRLCPY ${HAVE_STRLCPY}
    507  1.11  christos #define HAVE_STRNDUP ${HAVE_STRNDUP}
    508   1.2  christos #define HAVE_STRPTIME ${HAVE_STRPTIME}
    509   1.2  christos #define HAVE_STRSEP ${HAVE_STRSEP}
    510   1.2  christos #define HAVE_STRTONUM ${HAVE_STRTONUM}
    511   1.7  christos #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
    512   1.5  christos #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
    513   1.2  christos #define HAVE_WCHAR ${HAVE_WCHAR}
    514   1.2  christos #define HAVE_OHASH ${HAVE_OHASH}
    515  1.15       wiz #define NEED_XPG4_2 ${NEED_XPG4_2}
    516   1.2  christos #endif
    517   1.2  christos 
    518   1.2  christos #define BINM_APROPOS "${BINM_APROPOS}"
    519   1.7  christos #define BINM_CATMAN "${BINM_CATMAN}"
    520   1.5  christos #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
    521   1.2  christos #define BINM_MAN "${BINM_MAN}"
    522   1.5  christos #define BINM_SOELIM "${BINM_SOELIM}"
    523   1.2  christos #define BINM_WHATIS "${BINM_WHATIS}"
    524  1.15       wiz #define BINM_PAGER "${BINM_PAGER}"
    525   1.2  christos 
    526   1.5  christos __HEREDOC__
    527   1.2  christos 
    528   1.5  christos if [ ${HAVE_ERR} -eq 0 ]; then
    529   1.5  christos 	echo "extern	void	  err(int, const char *, ...);"
    530   1.5  christos 	echo "extern	void	  errx(int, const char *, ...);"
    531   1.5  christos 	echo "extern	void	  warn(const char *, ...);"
    532   1.5  christos 	echo "extern	void	  warnx(const char *, ...);"
    533  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_err.o"
    534  1.15       wiz 	SOELIM_COBJS="${SOELIM_COBJS} compat_err.o"
    535  1.15       wiz fi
    536  1.15       wiz if [ ${HAVE_FTS} -eq 0 ]; then
    537  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_fts.o"
    538   1.5  christos fi
    539  1.15       wiz if [ ${HAVE_GETLINE} -eq 0 ]; then
    540   1.5  christos 	echo "extern	ssize_t	  getline(char **, size_t *, FILE *);"
    541  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_getline.o"
    542  1.15       wiz 	SOELIM_COBJS="${SOELIM_COBJS} compat_getline.o"
    543  1.15       wiz fi
    544  1.15       wiz if [ ${HAVE_GETSUBOPT} -eq 0 ]; then
    545   1.2  christos 	echo "extern	int	  getsubopt(char **, char * const *, char **);"
    546  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_getsubopt.o"
    547  1.15       wiz fi
    548   1.6     joerg if [ ${HAVE_ISBLANK} -eq 0 ]; then
    549   1.6     joerg 	echo "#undef isblank"
    550   1.5  christos 	echo "extern	int	  isblank(int);"
    551  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_isblank.o"
    552   1.6     joerg fi
    553  1.15       wiz if [ ${HAVE_MKDTEMP} -eq 0 ]; then
    554   1.5  christos 	echo "extern	char	 *mkdtemp(char *);"
    555  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_mkdtemp.o"
    556  1.15       wiz fi
    557  1.15       wiz if [ ${HAVE_MKSTEMPS} -eq 0 ]; then
    558  1.15       wiz 	echo "extern	int	  mkstemps(char *, int);"
    559  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_mkstemps.o"
    560  1.15       wiz fi
    561  1.15       wiz if [ ${HAVE_OHASH} -eq 0 ]; then
    562  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_ohash.o"
    563  1.15       wiz fi
    564   1.5  christos if [ ${HAVE_PROGNAME} -eq 0 ]; then
    565  1.15       wiz 	echo "extern	const char *getprogname(void);"
    566   1.5  christos 	echo "extern	void	  setprogname(const char *);"
    567  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_progname.o"
    568  1.15       wiz 	SOELIM_COBJS="${SOELIM_COBJS} compat_progname.o"
    569   1.5  christos fi
    570  1.15       wiz if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then
    571   1.2  christos 	echo "extern	void	 *reallocarray(void *, size_t, size_t);"
    572  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_reallocarray.o"
    573  1.15       wiz 	SOELIM_COBJS="${SOELIM_COBJS} compat_reallocarray.o"
    574  1.15       wiz fi
    575  1.15       wiz if [ ${HAVE_RECALLOCARRAY} -eq 0 ]; then
    576  1.11  christos 	echo "extern	void	 *recallocarray(void *, size_t, size_t, size_t);"
    577  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_recallocarray.o"
    578  1.15       wiz fi
    579  1.15       wiz if [ ${HAVE_STRCASESTR} -eq 0 ]; then
    580   1.2  christos 	echo "extern	char	 *strcasestr(const char *, const char *);"
    581  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strcasestr.o"
    582  1.15       wiz fi
    583  1.15       wiz if [ ${HAVE_STRINGLIST} -eq 0 ]; then
    584  1.15       wiz 	SOELIM_COBJS="${SOELIM_COBJS} compat_stringlist.o"
    585  1.15       wiz fi
    586  1.15       wiz if [ ${HAVE_STRLCAT} -eq 0 ]; then
    587   1.2  christos 	echo "extern	size_t	  strlcat(char *, const char *, size_t);"
    588  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strlcat.o"
    589  1.15       wiz fi
    590  1.15       wiz if [ ${HAVE_STRLCPY} -eq 0 ]; then
    591   1.2  christos 	echo "extern	size_t	  strlcpy(char *, const char *, size_t);"
    592  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strlcpy.o"
    593  1.15       wiz fi
    594  1.15       wiz if [ ${HAVE_STRNDUP} -eq 0 ]; then
    595  1.11  christos 	echo "extern	char	 *strndup(const char *, size_t);"
    596  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strndup.o"
    597  1.15       wiz fi
    598  1.15       wiz if [ ${HAVE_STRSEP} -eq 0 ]; then
    599   1.2  christos 	echo "extern	char	 *strsep(char **, const char *);"
    600  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strsep.o"
    601  1.15       wiz fi
    602  1.15       wiz if [ ${HAVE_STRTONUM} -eq 0 ]; then
    603   1.2  christos 	echo "extern	long long strtonum(const char *, long long, long long, const char **);"
    604  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_strtonum.o"
    605  1.15       wiz fi
    606  1.15       wiz if [ ${HAVE_VASPRINTF} -eq 0 ]; then
    607   1.5  christos 	echo "extern	int	  vasprintf(char **, const char *, va_list);"
    608  1.15       wiz 	MANDOC_COBJS="${MANDOC_COBJS} compat_vasprintf.o"
    609  1.15       wiz fi
    610  1.11  christos echo "file config.h: written" 1>&2
    611  1.11  christos echo "file config.h: written" 1>&3
    612   1.2  christos 
    613   1.2  christos # --- tests for Makefile.local -----------------------------------------
    614   1.2  christos 
    615   1.2  christos exec > Makefile.local
    616   1.2  christos 
    617  1.11  christos [ -z "${BINDIR}"          ] && BINDIR="${PREFIX}/bin"
    618  1.11  christos [ -z "${SBINDIR}"         ] && SBINDIR="${PREFIX}/sbin"
    619  1.11  christos [ -z "${BIN_FROM_SBIN}"   ] && BIN_FROM_SBIN="../bin"
    620  1.11  christos [ -z "${INCLUDEDIR}"      ] && INCLUDEDIR="${PREFIX}/include/mandoc"
    621  1.11  christos [ -z "${LIBDIR}"          ] && LIBDIR="${PREFIX}/lib/mandoc"
    622  1.11  christos [ -z "${MANDIR}"          ] && MANDIR="${PREFIX}/man"
    623   1.2  christos 
    624  1.11  christos [ -z "${HTDOCDIR}"        ] && HTDOCDIR="${WWWPREFIX}/htdocs"
    625  1.11  christos [ -z "${CGIBINDIR}"       ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
    626   1.2  christos 
    627   1.2  christos [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
    628   1.2  christos [ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0444"
    629   1.2  christos [ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0444"
    630   1.2  christos [ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0444"
    631   1.2  christos 
    632   1.7  christos BUILD_TARGETS=
    633   1.7  christos [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="man.cgi"
    634   1.7  christos [ ${BUILD_CATMAN} -gt 0 ] && \
    635   1.7  christos 	BUILD_TARGETS="${BUILD_TARGETS} mandocd catman"
    636   1.7  christos INSTALL_TARGETS=
    637   1.7  christos [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS="lib-install"
    638   1.2  christos [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
    639   1.7  christos [ ${BUILD_CATMAN} -gt 0 ] && \
    640   1.7  christos 	INSTALL_TARGETS="${INSTALL_TARGETS} catman-install"
    641   1.2  christos 
    642   1.2  christos cat << __HEREDOC__
    643   1.2  christos BUILD_TARGETS	= ${BUILD_TARGETS}
    644   1.2  christos INSTALL_TARGETS	= ${INSTALL_TARGETS}
    645  1.15       wiz AR		= ${AR}
    646   1.5  christos CC		= ${CC}
    647   1.2  christos CFLAGS		= ${CFLAGS}
    648   1.5  christos LDADD		= ${LDADD}
    649   1.5  christos LDFLAGS		= ${LDFLAGS}
    650  1.15       wiz MANDOC_COBJS	= ${MANDOC_COBJS}
    651  1.15       wiz SOELIM_COBJS	= ${SOELIM_COBJS}
    652   1.2  christos STATIC		= ${STATIC}
    653   1.2  christos PREFIX		= ${PREFIX}
    654   1.2  christos BINDIR		= ${BINDIR}
    655   1.2  christos SBINDIR		= ${SBINDIR}
    656  1.11  christos BIN_FROM_SBIN	= ${BIN_FROM_SBIN}
    657   1.2  christos INCLUDEDIR	= ${INCLUDEDIR}
    658   1.2  christos LIBDIR		= ${LIBDIR}
    659   1.2  christos MANDIR		= ${MANDIR}
    660   1.2  christos WWWPREFIX	= ${WWWPREFIX}
    661   1.2  christos HTDOCDIR	= ${HTDOCDIR}
    662   1.2  christos CGIBINDIR	= ${CGIBINDIR}
    663   1.2  christos BINM_APROPOS	= ${BINM_APROPOS}
    664   1.7  christos BINM_CATMAN	= ${BINM_CATMAN}
    665   1.5  christos BINM_MAKEWHATIS	= ${BINM_MAKEWHATIS}
    666   1.2  christos BINM_MAN	= ${BINM_MAN}
    667   1.5  christos BINM_SOELIM	= ${BINM_SOELIM}
    668   1.2  christos BINM_WHATIS	= ${BINM_WHATIS}
    669   1.2  christos MANM_MAN	= ${MANM_MAN}
    670   1.5  christos MANM_MANCONF	= ${MANM_MANCONF}
    671   1.2  christos MANM_MDOC	= ${MANM_MDOC}
    672   1.2  christos MANM_ROFF	= ${MANM_ROFF}
    673   1.2  christos MANM_EQN	= ${MANM_EQN}
    674   1.2  christos MANM_TBL	= ${MANM_TBL}
    675   1.2  christos INSTALL		= ${INSTALL}
    676   1.2  christos INSTALL_PROGRAM	= ${INSTALL_PROGRAM}
    677   1.2  christos INSTALL_LIB	= ${INSTALL_LIB}
    678   1.2  christos INSTALL_MAN	= ${INSTALL_MAN}
    679   1.2  christos INSTALL_DATA	= ${INSTALL_DATA}
    680   1.7  christos LN		= ${LN}
    681   1.2  christos __HEREDOC__
    682   1.2  christos 
    683  1.11  christos echo "file Makefile.local: written" 1>&2
    684  1.11  christos echo "file Makefile.local: written" 1>&3
    685   1.1     joerg 
    686   1.1     joerg exit 0
    687