3 # $Id: configure,v 1.70 2019/03/06 16:04:31 schwarze Exp $
5 # Copyright (c) 2014-2019 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 "file 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_BASE
="/usr/share/man:/usr/X11R6/man"
39 MANPATH_DEFAULT
="/usr/share/man:/usr/X11R6/man:/usr/local/man"
44 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
64 HAVE_FTS_COMPARE_CONST
=
111 BINM_APROPOS
="apropos"
113 BINM_MAKEWHATIS
="makewhatis"
118 MANM_MANCONF
="man.conf"
131 # --- manual settings from configure.local -----------------------------
133 if [ -r .
/configure.
local ]; then
134 echo "file configure.local: reading..." 1>&2
135 echo "file configure.local: reading..." 1>&3
136 cat .
/configure.
local 1>&3
139 echo "file configure.local: no (fully automatic configuration)" 1>&2
140 echo "file configure.local: no (fully automatic configuration)" 1>&3
144 # --- tests functions --------------------------------------------------
146 # Check whether this HAVE_ setting is manually overridden.
147 # If yes, use the override, if no, do not decide anything yet.
148 # Arguments: test file name, test var name, manual value
150 [ -z "${3}" ] && return 1
151 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&2
152 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&3
157 # Run a single autoconfiguration test.
158 # In case of success, enable the feature.
159 # In case of failure, do not decide anything yet.
160 # Arguments: test file name, test var name, additional CFLAGS
163 cat 1>&3 << __HEREDOC__
165 ${COMP} -o test-${1} test-${1}.c ${3} ${4}
168 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} ${4} 1>&3 2>&3
170 echo "partial result of ${n}: ${CC} succeeded" 1>&3
172 echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
173 echo "result of compiling ${n}: no" 1>&3
178 if .
/test-${1} 1>&3 2>&3; then
179 echo "tested ${n}: yes" 1>&2
180 echo "result of running ${n}: yes" 1>&3
183 [ "X$3" = "X-D_GNU_SOURCE" ] && NEED_GNU_SOURCE
=1
184 [ "X$3" = "X-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE
=1
188 echo "result of ${n}: execution failed with exit status $?" 1>&3
189 echo "result of running ${n}: no" 1>&3
196 # Run a complete autoconfiguration test, including the check for
197 # a manual override and disabling the feature on failure.
198 # Arguments: test file name, test var name, additional CFLAGS
200 eval _manual
=\
${HAVE_${2}}
201 ismanual
"${1}" "${2}" "${_manual}" && return 0
202 singletest
"${1}" "${2}" "${3}" "${4}" && return 0
203 echo "tested ${1}${3}${4}: no" 1>&2
208 # Select a UTF-8 locale.
210 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
211 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
212 echo "testing UTF8_LOCALE ..." 1>&3
213 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
214 if [ -z "${UTF8_LOCALE}" ]; then
215 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
216 [ -n "${UTF8_LOCALE}" ] || return 1
218 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
219 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
224 # --- operating system -------------------------------------------------
226 if [ -n "${OSENUM}" ]; then
227 echo "OSENUM specified manually: ${OSENUM}" 1>&2
228 echo "OSENUM specified manually: ${OSENUM}" 1>&3
231 if [ "X${OSDETECT}" = "XNetBSD" ]; then
232 OSENUM
=MANDOC_OS_NETBSD
233 elif [ "X${OSDETECT}" = "XOpenBSD" ]; then
234 OSENUM
=MANDOC_OS_OPENBSD
236 OSENUM
=MANDOC_OS_OTHER
238 echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&2
239 echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&3
244 # --- compiler options -------------------------------------------------
246 DEFCFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter"
248 if [ -n "${CFLAGS}" ]; then
249 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
251 COMP
="${CC} ${DEFCFLAGS} -Wno-unused -Werror"
253 echo -n "tested ${CC} -W: " 1>&2
254 echo -n "testing ${CC} -W: " 1>&3
255 runtest noop WFLAG
|| true
257 if [ -n "${CFLAGS}" ]; then
258 echo "CFLAGS specified manually:" 1>&3
259 elif [ ${HAVE_WFLAG} -eq 0 ]; then
262 CFLAGS
="${DEFCFLAGS}"
264 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2
265 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3
268 COMP
="${CC} ${CFLAGS}"
269 [ ${HAVE_WFLAG} -eq 0 ] || COMP
="${COMP} -Wno-unused -Werror"
271 if [ -n "${STATIC}" ]; then
272 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2
273 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&3
276 runtest noop STATIC
-static || true
277 [ ${HAVE_STATIC} -eq 0 ] || STATIC
="-static"
278 echo "selected STATIC=\"${STATIC}\"" 1>&2
279 echo "selected STATIC=\"${STATIC}\"" 1>&3
283 # --- tests for config.h ----------------------------------------------
285 # --- library functions ---
286 runtest dirent
-namlen DIRENT_NAMLEN
|| true
287 runtest be32toh ENDIAN
|| true
288 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
289 runtest EFTYPE EFTYPE
|| true
290 runtest err ERR
|| true
291 runtest getline GETLINE
|| true
292 singletest getsubopt GETSUBOPT
|| \
293 runtest getsubopt GETSUBOPT
-D_GNU_SOURCE || true
294 runtest isblank ISBLANK
|| true
295 runtest mkdtemp MKDTEMP
|| true
296 runtest ntohl NTOHL
|| true
297 runtest O_DIRECTORY O_DIRECTORY
|| true
298 runtest PATH_MAX PATH_MAX
|| true
299 runtest pledge PLEDGE
|| true
300 runtest sandbox_init SANDBOX_INIT
|| true
301 runtest progname PROGNAME
|| true
302 singletest reallocarray REALLOCARRAY
|| \
303 runtest reallocarray REALLOCARRAY
-D_OPENBSD_SOURCE || true
304 singletest recallocarray RECALLOCARRAY
|| \
305 runtest recallocarray RECALLOCARRAY
-D_OPENBSD_SOURCE || true
306 runtest rewb
-bsd REWB_BSD
|| true
307 runtest rewb
-sysv REWB_SYSV
|| true
308 singletest strcasestr STRCASESTR
|| \
309 runtest strcasestr STRCASESTR
-D_GNU_SOURCE || true
310 runtest stringlist STRINGLIST
|| true
311 runtest strlcat STRLCAT
|| true
312 runtest strlcpy STRLCPY
|| true
313 runtest strndup STRNDUP
|| true
314 singletest strptime STRPTIME
|| \
315 runtest strptime STRPTIME
-D_GNU_SOURCE || true
316 runtest strsep STRSEP
|| true
317 singletest strtonum STRTONUM
|| \
318 runtest strtonum STRTONUM
-D_OPENBSD_SOURCE || true
319 singletest vasprintf VASPRINTF
|| \
320 runtest vasprintf VASPRINTF
-D_GNU_SOURCE || true
322 if [ ${HAVE_ENDIAN} -eq 0 -a \
323 ${HAVE_SYS_ENDIAN} -eq 0 -a \
324 ${HAVE_NTOHL} -eq 0 ]; then
325 echo "FATAL: no endian conversion functions found" 1>&2
326 echo "FATAL: no endian conversion functions found" 1>&3
330 if ismanual fts FTS
${HAVE_FTS}; then
331 HAVE_FTS_COMPARE_CONST
=0
332 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
335 runtest fts FTS
|| true
338 if ismanual
"less -T" LESS_T
${HAVE_LESS_T}; then
340 elif less -ET /dev
/null
test-noop.c
1>/dev
/null
2>&3; then
342 echo "tested less -T: yes" 1>&2
343 echo "tested less -T: yes" 1>&3
347 echo "tested less -T: no" 1>&2
348 echo "tested less -T: no" 1>&3
352 # --- wide character and locale support ---
354 singletest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || \
355 runtest wchar WCHAR
-D_GNU_SOURCE \
356 -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
359 echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
360 echo "tested wchar: no (no UTF8_LOCALE)" 1>&3
365 if [ -n "${LD_NANOSLEEP}" ]; then
366 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
367 elif singletest nanosleep NANOSLEEP
; then
369 elif runtest nanosleep NANOSLEEP
"-lrt"; then
372 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
373 echo "FATAL: nanosleep: no" 1>&2
374 echo "FATAL: nanosleep: no" 1>&3
378 if [ ${BUILD_CATMAN} -gt 0 ]; then
380 if [ -n "${LD_RECVMSG}" ]; then
381 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
382 elif singletest recvmsg RECVMSG
; then
384 elif runtest recvmsg RECVMSG
"-lsocket"; then
385 LD_RECVMSG
="-lsocket"
387 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
388 echo "FATAL: recvmsg: no" 1>&2
389 echo "FATAL: recvmsg: no" 1>&3
390 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
395 if singletest cmsg CMSG
; then
397 elif runtest cmsg CMSG
"-D_XPG4_2"; then
400 if [ "${HAVE_CMSG}" -eq 0 ]; then
401 echo "FATAL: cmsg: no" 1>&2
402 echo "FATAL: cmsg: no" 1>&3
403 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
409 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
411 elif [ -n "${LD_OHASH}" ]; then
412 runtest ohash OHASH
"${LD_OHASH}" || true
413 elif singletest ohash OHASH
; then
415 elif runtest ohash OHASH
"-lutil"; then
418 if [ "${HAVE_OHASH}" -eq 0 ]; then
423 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
424 echo "selected LDADD=\"${LDADD}\"" 1>&2
425 echo "selected LDADD=\"${LDADD}\"" 1>&3
428 # --- write config.h ---
434 #error "Do not use C++. See the INSTALL file."
437 #if !defined(__GNUC__) || (__GNUC__ < 4)
438 #define __attribute__(x)
443 [ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE"
444 [ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE"
446 [ ${HAVE_GETLINE} -eq 0 -o \
447 ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
448 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
449 ${HAVE_STRNDUP} -eq 0 ] \
450 && echo "#include <sys/types.h>"
451 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
452 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
455 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
456 echo "#define MANPATH_BASE \"${MANPATH_BASE}\""
457 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
458 echo "#define OSENUM ${OSENUM}"
459 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
460 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
461 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
462 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
463 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
464 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
465 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
466 echo "#define be32toh ntohl"
467 echo "#define htobe32 htonl"
471 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
472 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
473 #define HAVE_ENDIAN ${HAVE_ENDIAN}
474 #define HAVE_ERR ${HAVE_ERR}
475 #define HAVE_FTS ${HAVE_FTS}
476 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
477 #define HAVE_GETLINE ${HAVE_GETLINE}
478 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
479 #define HAVE_ISBLANK ${HAVE_ISBLANK}
480 #define HAVE_LESS_T ${HAVE_LESS_T}
481 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
482 #define HAVE_NTOHL ${HAVE_NTOHL}
483 #define HAVE_PLEDGE ${HAVE_PLEDGE}
484 #define HAVE_PROGNAME ${HAVE_PROGNAME}
485 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
486 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
487 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
488 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
489 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
490 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
491 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
492 #define HAVE_STRLCAT ${HAVE_STRLCAT}
493 #define HAVE_STRLCPY ${HAVE_STRLCPY}
494 #define HAVE_STRNDUP ${HAVE_STRNDUP}
495 #define HAVE_STRPTIME ${HAVE_STRPTIME}
496 #define HAVE_STRSEP ${HAVE_STRSEP}
497 #define HAVE_STRTONUM ${HAVE_STRTONUM}
498 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
499 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
500 #define HAVE_WCHAR ${HAVE_WCHAR}
501 #define HAVE_OHASH ${HAVE_OHASH}
503 #define BINM_APROPOS "${BINM_APROPOS}"
504 #define BINM_CATMAN "${BINM_CATMAN}"
505 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
506 #define BINM_MAN "${BINM_MAN}"
507 #define BINM_SOELIM "${BINM_SOELIM}"
508 #define BINM_WHATIS "${BINM_WHATIS}"
512 if [ ${HAVE_ERR} -eq 0 ]; then
513 echo "extern void err(int, const char *, ...);"
514 echo "extern void errx(int, const char *, ...);"
515 echo "extern void warn(const char *, ...);"
516 echo "extern void warnx(const char *, ...);"
519 [ ${HAVE_GETLINE} -eq 0 ] && \
520 echo "extern ssize_t getline(char **, size_t *, FILE *);"
522 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
523 echo "extern int getsubopt(char **, char * const *, char **);"
525 [ ${HAVE_ISBLANK} -eq 0 ] && \
526 echo "extern int isblank(int);"
528 [ ${HAVE_MKDTEMP} -eq 0 ] && \
529 echo "extern char *mkdtemp(char *);"
531 if [ ${HAVE_PROGNAME} -eq 0 ]; then
532 echo "extern const char *getprogname(void);"
533 echo "extern void setprogname(const char *);"
536 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
537 echo "extern void *reallocarray(void *, size_t, size_t);"
539 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
540 echo "extern void *recallocarray(void *, size_t, size_t, size_t);"
542 [ ${HAVE_STRCASESTR} -eq 0 ] && \
543 echo "extern char *strcasestr(const char *, const char *);"
545 [ ${HAVE_STRLCAT} -eq 0 ] && \
546 echo "extern size_t strlcat(char *, const char *, size_t);"
548 [ ${HAVE_STRLCPY} -eq 0 ] && \
549 echo "extern size_t strlcpy(char *, const char *, size_t);"
551 [ ${HAVE_STRNDUP} -eq 0 ] && \
552 echo "extern char *strndup(const char *, size_t);"
554 [ ${HAVE_STRSEP} -eq 0 ] && \
555 echo "extern char *strsep(char **, const char *);"
557 [ ${HAVE_STRTONUM} -eq 0 ] && \
558 echo "extern long long strtonum(const char *, long long, long long, const char **);"
560 [ ${HAVE_VASPRINTF} -eq 0 ] && \
561 echo "extern int vasprintf(char **, const char *, va_list);"
563 echo "file config.h: written" 1>&2
564 echo "file config.h: written" 1>&3
566 # --- tests for Makefile.local -----------------------------------------
568 exec > Makefile.
local
570 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
571 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
572 [ -z "${BIN_FROM_SBIN}" ] && BIN_FROM_SBIN
="../bin"
573 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
574 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
575 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
577 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
578 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
580 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
581 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
582 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
583 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
586 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
587 [ ${BUILD_CATMAN} -gt 0 ] && \
588 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
590 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
591 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
592 [ ${BUILD_CATMAN} -gt 0 ] && \
593 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
596 BUILD_TARGETS = ${BUILD_TARGETS}
597 INSTALL_TARGETS = ${INSTALL_TARGETS}
606 BIN_FROM_SBIN = ${BIN_FROM_SBIN}
607 INCLUDEDIR = ${INCLUDEDIR}
610 WWWPREFIX = ${WWWPREFIX}
611 HTDOCDIR = ${HTDOCDIR}
612 CGIBINDIR = ${CGIBINDIR}
613 BINM_APROPOS = ${BINM_APROPOS}
614 BINM_CATMAN = ${BINM_CATMAN}
615 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
616 BINM_MAN = ${BINM_MAN}
617 BINM_SOELIM = ${BINM_SOELIM}
618 BINM_WHATIS = ${BINM_WHATIS}
619 MANM_MAN = ${MANM_MAN}
620 MANM_MANCONF = ${MANM_MANCONF}
621 MANM_MDOC = ${MANM_MDOC}
622 MANM_ROFF = ${MANM_ROFF}
623 MANM_EQN = ${MANM_EQN}
624 MANM_TBL = ${MANM_TBL}
626 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
627 INSTALL_LIB = ${INSTALL_LIB}
628 INSTALL_MAN = ${INSTALL_MAN}
629 INSTALL_DATA = ${INSTALL_DATA}
633 echo "file Makefile.local: written" 1>&2
634 echo "file Makefile.local: written" 1>&3