3 # $Id: configure,v 1.61 2017/02/18 12:24:24 schwarze Exp $
5 # Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 [ -w config.log
] && mv config.log config.log.old
22 [ -w config.h
] && mv config.h config.h.old
24 # Output file descriptor usage:
25 # 1 (stdout): config.h, Makefile.local
26 # 2 (stderr): original stderr, usually to the console
30 echo "config.log: writing..."
32 # --- default settings -------------------------------------------------
33 # Initialize all variables here,
34 # such that nothing can leak in from the environment.
36 SOURCEDIR
=`dirname "$0"`
38 MANPATH_DEFAULT
="/usr/share/man:/usr/X11R6/man:/usr/local/man"
42 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
43 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
44 CFLAGS
="${CFLAGS} -Wno-unused-parameter"
63 HAVE_FTS_COMPARE_CONST
=
103 BINM_APROPOS
="apropos"
105 BINM_MAKEWHATIS
="makewhatis"
110 MANM_MANCONF
="man.conf"
123 # --- manual settings from configure.local -----------------------------
125 if [ -r .
/configure.
local ]; then
126 echo "configure.local: reading..." 1>&2
127 echo "configure.local: reading..." 1>&3
128 cat .
/configure.
local 1>&3
131 echo "configure.local: no (fully automatic configuration)" 1>&2
132 echo "configure.local: no (fully automatic configuration)" 1>&3
136 # --- tests for config.h ----------------------------------------------
138 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
140 # Check whether this HAVE_ setting is manually overridden.
141 # If yes, use the override, if no, do not decide anything yet.
142 # Arguments: lower-case test name, manual value
144 [ -z "${3}" ] && return 1
145 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
146 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
151 # Run a single autoconfiguration test.
152 # In case of success, enable the feature.
153 # In case of failure, do not decide anything yet.
154 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
156 cat 1>&3 << __HEREDOC__
158 ${COMP} -o test-${1} test-${1}.c ${3}
161 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
163 echo "${1}${3}: ${CC} succeeded" 1>&3
165 echo "${1}${3}: ${CC} failed with $?" 1>&3
170 if .
/test-${1} 1>&3 2>&3; then
171 echo "${1}${3}: yes" 1>&2
172 echo "${1}${3}: yes" 1>&3
178 echo "${1}${3}: execution failed with $?" 1>&3
185 # Run a complete autoconfiguration test, including the check for
186 # a manual override and disabling the feature on failure.
187 # Arguments: lower case name, upper case name, additional CFLAGS
189 eval _manual
=\
${HAVE_${2}}
190 ismanual
"${1}" "${2}" "${_manual}" && return 0
191 singletest
"${1}" "${2}" "${3}" && return 0
192 echo "${1}${3}: no" 1>&2
197 # Select a UTF-8 locale.
199 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
200 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
201 echo "UTF8_LOCALE: testing..." 1>&3
202 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
203 if [ -z "${UTF8_LOCALE}" ]; then
204 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
205 [ -n "${UTF8_LOCALE}" ] || return 1
207 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
208 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
214 # --- library functions ---
215 runtest dirent
-namlen DIRENT_NAMLEN
|| true
216 runtest be32toh ENDIAN
|| true
217 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
218 runtest EFTYPE EFTYPE
|| true
219 runtest err ERR
|| true
220 runtest getline GETLINE
|| true
221 runtest getsubopt GETSUBOPT
|| true
222 runtest isblank ISBLANK
|| true
223 runtest mkdtemp MKDTEMP
|| true
224 runtest ntohl NTOHL
|| true
225 runtest O_DIRECTORY O_DIRECTORY
|| true
226 runtest PATH_MAX PATH_MAX
|| true
227 runtest pledge PLEDGE
|| true
228 runtest sandbox_init SANDBOX_INIT
|| true
229 runtest progname PROGNAME
|| true
230 runtest reallocarray REALLOCARRAY
|| true
231 runtest rewb
-bsd REWB_BSD
|| true
232 runtest rewb
-sysv REWB_SYSV
|| true
233 runtest strcasestr STRCASESTR
|| true
234 runtest stringlist STRINGLIST
|| true
235 runtest strlcat STRLCAT
|| true
236 runtest strlcpy STRLCPY
|| true
237 runtest strptime STRPTIME
|| true
238 runtest strsep STRSEP
|| true
239 runtest strtonum STRTONUM
|| true
240 runtest vasprintf VASPRINTF
|| true
242 if [ ${HAVE_ENDIAN} -eq 0 -a \
243 ${HAVE_SYS_ENDIAN} -eq 0 -a \
244 ${HAVE_NTOHL} -eq 0 ]; then
245 echo "FATAL: no endian conversion functions found" 1>&2
246 echo "FATAL: no endian conversion functions found" 1>&3
250 if ismanual fts FTS
${HAVE_FTS}; then
251 HAVE_FTS_COMPARE_CONST
=0
252 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
255 runtest fts FTS
|| true
258 # --- wide character and locale support ---
260 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
263 echo "wchar: no (no UTF8_LOCALE)" 1>&2
264 echo "wchar: no (no UTF8_LOCALE)" 1>&3
268 if [ -n "${LD_NANOSLEEP}" ]; then
269 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
270 elif singletest nanosleep NANOSLEEP
; then
272 elif runtest nanosleep NANOSLEEP
"-lrt"; then
275 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
276 echo "FATAL: nanosleep: no" 1>&2
277 echo "FATAL: nanosleep: no" 1>&3
281 if [ ${BUILD_CATMAN} -gt 0 ]; then
283 if [ -n "${LD_RECVMSG}" ]; then
284 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
285 elif singletest recvmsg RECVMSG
; then
287 elif runtest recvmsg RECVMSG
"-lsocket"; then
288 LD_RECVMSG
="-lsocket"
290 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
291 echo "FATAL: recvmsg: no" 1>&2
292 echo "FATAL: recvmsg: no" 1>&3
293 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
298 if singletest cmsg CMSG
; then
300 elif runtest cmsg CMSG
"-D_XPG4_2"; then
303 if [ "${HAVE_CMSG}" -eq 0 ]; then
304 echo "FATAL: cmsg: no" 1>&2
305 echo "FATAL: cmsg: no" 1>&3
306 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
312 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
314 elif [ -n "${LD_OHASH}" ]; then
315 runtest ohash OHASH
"${LD_OHASH}" || true
316 elif singletest ohash OHASH
; then
318 elif runtest ohash OHASH
"-lutil"; then
321 if [ "${HAVE_OHASH}" -eq 0 ]; then
326 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
327 echo "LDADD=\"${LDADD}\"" 1>&2
328 echo "LDADD=\"${LDADD}\"" 1>&3
331 # --- write config.h ---
337 #error "Do not use C++. See the INSTALL file."
340 #if !defined(__GNUC__) || (__GNUC__ < 4)
341 #define __attribute__(x)
344 #if defined(__linux__) || defined(__MINT__)
345 #define _GNU_SOURCE /* See test-*.c what needs this. */
350 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
351 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
352 && echo "#include <sys/types.h>"
353 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
354 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
357 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
358 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
359 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
360 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
361 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
362 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
363 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
364 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
365 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
366 echo "#define be32toh ntohl"
367 echo "#define htobe32 htonl"
371 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
372 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
373 #define HAVE_ENDIAN ${HAVE_ENDIAN}
374 #define HAVE_ERR ${HAVE_ERR}
375 #define HAVE_FTS ${HAVE_FTS}
376 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
377 #define HAVE_GETLINE ${HAVE_GETLINE}
378 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
379 #define HAVE_ISBLANK ${HAVE_ISBLANK}
380 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
381 #define HAVE_NTOHL ${HAVE_NTOHL}
382 #define HAVE_PLEDGE ${HAVE_PLEDGE}
383 #define HAVE_PROGNAME ${HAVE_PROGNAME}
384 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
385 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
386 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
387 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
388 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
389 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
390 #define HAVE_STRLCAT ${HAVE_STRLCAT}
391 #define HAVE_STRLCPY ${HAVE_STRLCPY}
392 #define HAVE_STRPTIME ${HAVE_STRPTIME}
393 #define HAVE_STRSEP ${HAVE_STRSEP}
394 #define HAVE_STRTONUM ${HAVE_STRTONUM}
395 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
396 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
397 #define HAVE_WCHAR ${HAVE_WCHAR}
398 #define HAVE_OHASH ${HAVE_OHASH}
400 #define BINM_APROPOS "${BINM_APROPOS}"
401 #define BINM_CATMAN "${BINM_CATMAN}"
402 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
403 #define BINM_MAN "${BINM_MAN}"
404 #define BINM_SOELIM "${BINM_SOELIM}"
405 #define BINM_WHATIS "${BINM_WHATIS}"
409 if [ ${HAVE_ERR} -eq 0 ]; then
410 echo "extern void err(int, const char *, ...);"
411 echo "extern void errx(int, const char *, ...);"
412 echo "extern void warn(const char *, ...);"
413 echo "extern void warnx(const char *, ...);"
416 [ ${HAVE_GETLINE} -eq 0 ] && \
417 echo "extern ssize_t getline(char **, size_t *, FILE *);"
419 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
420 echo "extern int getsubopt(char **, char * const *, char **);"
422 [ ${HAVE_ISBLANK} -eq 0 ] && \
423 echo "extern int isblank(int);"
425 [ ${HAVE_MKDTEMP} -eq 0 ] && \
426 echo "extern char *mkdtemp(char *);"
428 if [ ${HAVE_PROGNAME} -eq 0 ]; then
429 echo "extern const char *getprogname(void);"
430 echo "extern void setprogname(const char *);"
433 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
434 echo "extern void *reallocarray(void *, size_t, size_t);"
436 [ ${HAVE_STRCASESTR} -eq 0 ] && \
437 echo "extern char *strcasestr(const char *, const char *);"
439 [ ${HAVE_STRLCAT} -eq 0 ] && \
440 echo "extern size_t strlcat(char *, const char *, size_t);"
442 [ ${HAVE_STRLCPY} -eq 0 ] && \
443 echo "extern size_t strlcpy(char *, const char *, size_t);"
445 [ ${HAVE_STRSEP} -eq 0 ] && \
446 echo "extern char *strsep(char **, const char *);"
448 [ ${HAVE_STRTONUM} -eq 0 ] && \
449 echo "extern long long strtonum(const char *, long long, long long, const char **);"
451 [ ${HAVE_VASPRINTF} -eq 0 ] && \
452 echo "extern int vasprintf(char **, const char *, va_list);"
454 echo "config.h: written" 1>&2
455 echo "config.h: written" 1>&3
457 # --- tests for Makefile.local -----------------------------------------
459 exec > Makefile.
local
461 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
462 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
463 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
464 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
465 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
467 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
468 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
470 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
471 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
472 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
473 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
476 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
477 [ ${BUILD_CATMAN} -gt 0 ] && \
478 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
480 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
481 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
482 [ ${BUILD_CATMAN} -gt 0 ] && \
483 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
486 BUILD_TARGETS = ${BUILD_TARGETS}
487 INSTALL_TARGETS = ${INSTALL_TARGETS}
496 INCLUDEDIR = ${INCLUDEDIR}
499 WWWPREFIX = ${WWWPREFIX}
500 HTDOCDIR = ${HTDOCDIR}
501 CGIBINDIR = ${CGIBINDIR}
502 BINM_APROPOS = ${BINM_APROPOS}
503 BINM_CATMAN = ${BINM_CATMAN}
504 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
505 BINM_MAN = ${BINM_MAN}
506 BINM_SOELIM = ${BINM_SOELIM}
507 BINM_WHATIS = ${BINM_WHATIS}
508 MANM_MAN = ${MANM_MAN}
509 MANM_MANCONF = ${MANM_MANCONF}
510 MANM_MDOC = ${MANM_MDOC}
511 MANM_ROFF = ${MANM_ROFF}
512 MANM_EQN = ${MANM_EQN}
513 MANM_TBL = ${MANM_TBL}
515 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
516 INSTALL_LIB = ${INSTALL_LIB}
517 INSTALL_MAN = ${INSTALL_MAN}
518 INSTALL_DATA = ${INSTALL_DATA}
522 echo "Makefile.local: written" 1>&2
523 echo "Makefile.local: written" 1>&3