3 # $Id: configure,v 1.74 2020/06/14 23:40:31 schwarze Exp $
5 # Copyright (c) 2014-2020 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"
64 HAVE_FTS_COMPARE_CONST
=
112 BINM_APROPOS
="apropos"
114 BINM_MAKEWHATIS
="makewhatis"
119 MANM_MANCONF
="man.conf"
132 # --- manual settings from configure.local -----------------------------
134 if [ -r .
/configure.
local ]; then
135 echo "file configure.local: reading..." 1>&2
136 echo "file configure.local: reading..." 1>&3
137 cat .
/configure.
local 1>&3
140 echo "file configure.local: no (fully automatic configuration)" 1>&2
141 echo "file configure.local: no (fully automatic configuration)" 1>&3
145 # --- tests functions --------------------------------------------------
147 # Check whether this HAVE_ setting is manually overridden.
148 # If yes, use the override, if no, do not decide anything yet.
149 # Arguments: test file name, test var name, manual value
151 [ -z "${3}" ] && return 1
152 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&2
153 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&3
158 # Run a single autoconfiguration test.
159 # In case of success, enable the feature.
160 # In case of failure, do not decide anything yet.
161 # Arguments: test file name, test var name, additional CFLAGS
164 cat 1>&3 << __HEREDOC__
166 ${COMP} -o test-${1} test-${1}.c ${3}
169 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
171 echo "partial result of ${n}: ${CC} succeeded" 1>&3
173 echo "tested ${n}: no (compilation failed)" 1>&2
174 echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
175 echo "result of compiling ${n}: no" 1>&3
180 if .
/test-${1} 1>&3 2>&3; then
181 echo "tested ${n}: yes" 1>&2
182 echo "result of running ${n}: yes" 1>&3
185 [ "${3}" = "-D_GNU_SOURCE" ] && NEED_GNU_SOURCE
=1
186 [ "${3}" = "-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE
=1
187 [ "${3}" = "-D_XPG4_2" ] && NEED_XPG4_2
=1
188 [ "${3}" = "-lrt" ] && LD_NANOSLEEP
="-lrt"
189 [ "${3}" = "-lsocket" ] && LD_RECVMSG
="-lsocket"
190 [ "${3}" = "-lutil" ] && LD_OHASH
="-lutil"
194 echo "tested ${n}: no (execution failed)" 1>&2
195 echo "result of ${n}: execution failed with exit status $?" 1>&3
196 echo "result of running ${n}: no" 1>&3
203 # Run a complete autoconfiguration test, including the check for
204 # a manual override and disabling the feature on failure.
205 # Arguments: test file name, test var name, additional CFLAGS
206 # The final argument can optionally be repeated a second time.
208 eval _manual
=\
${HAVE_${2}}
209 ismanual
"${1}" "${2}" "${_manual}" && return 0
210 singletest
"${1}" "${2}" "${3}" && return 0
211 [ -n "${4}" ] && singletest
"${1}" "${2}" "${4}" && return 0
216 # Select a UTF-8 locale.
218 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
219 ismanual UTF8_LOCALE UTF8_LOCALE
"${UTF8_LOCALE}" && return 0
220 echo "testing UTF8_LOCALE ..." 1>&3
221 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
222 if [ -z "${UTF8_LOCALE}" ]; then
223 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
224 [ -n "${UTF8_LOCALE}" ] || return 1
226 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
227 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
232 # --- operating system -------------------------------------------------
234 if [ -n "${OSENUM}" ]; then
235 echo "OSENUM specified manually: ${OSENUM}" 1>&2
236 echo "OSENUM specified manually: ${OSENUM}" 1>&3
239 if [ "${OSDETECT}" = "NetBSD" ]; then
240 OSENUM
=MANDOC_OS_NETBSD
241 elif [ "${OSDETECT}" = "OpenBSD" ]; then
242 OSENUM
=MANDOC_OS_OPENBSD
244 OSENUM
=MANDOC_OS_OTHER
246 echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&2
247 echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&3
252 # --- compiler options -------------------------------------------------
254 DEFCFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter"
256 if [ -n "${CFLAGS}" ]; then
257 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
259 COMP
="${CC} ${DEFCFLAGS} -Wno-unused -Werror"
261 echo -n "tested ${CC} -W: " 1>&2
262 echo -n "testing ${CC} -W: " 1>&3
263 runtest noop WFLAG
|| true
265 if [ -n "${CFLAGS}" ]; then
266 echo "CFLAGS specified manually:" 1>&3
267 elif [ ${HAVE_WFLAG} -eq 0 ]; then
270 CFLAGS
="${DEFCFLAGS}"
272 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2
273 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3
276 COMP
="${CC} ${CFLAGS}"
277 [ ${HAVE_WFLAG} -eq 0 ] || COMP
="${COMP} -Wno-unused -Werror"
279 if [ -n "${STATIC}" ]; then
280 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2
281 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&3
284 runtest noop STATIC
-static || true
285 [ ${HAVE_STATIC} -eq 0 ] || STATIC
="-static"
286 echo "selected STATIC=\"${STATIC}\"" 1>&2
287 echo "selected STATIC=\"${STATIC}\"" 1>&3
291 # --- tests for config.h ----------------------------------------------
293 # --- library functions ---
294 runtest cmsg CMSG
"" "-D_XPG4_2" || true
295 runtest dirent
-namlen DIRENT_NAMLEN
|| true
296 runtest be32toh ENDIAN
|| true
297 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
298 runtest EFTYPE EFTYPE
|| true
299 runtest err ERR
|| true
300 runtest getline GETLINE
|| true
301 runtest getsubopt GETSUBOPT
"" -D_GNU_SOURCE || true
302 runtest isblank ISBLANK
|| true
303 runtest mkdtemp MKDTEMP
|| true
304 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" "-lrt" || true
305 runtest ntohl NTOHL
|| true
306 runtest O_DIRECTORY O_DIRECTORY
|| true
307 runtest PATH_MAX PATH_MAX
|| true
308 runtest pledge PLEDGE
|| true
309 runtest sandbox_init SANDBOX_INIT
|| true
310 runtest progname PROGNAME
|| true
311 runtest reallocarray REALLOCARRAY
"" -D_OPENBSD_SOURCE || true
312 runtest recallocarray RECALLOCARRAY
"" -D_OPENBSD_SOURCE || true
313 runtest recvmsg RECVMSG
"${LD_RECVMSG}" "-lsocket" || true
314 runtest rewb
-bsd REWB_BSD
|| true
315 runtest rewb
-sysv REWB_SYSV
|| true
316 runtest strcasestr STRCASESTR
"" -D_GNU_SOURCE || true
317 runtest stringlist STRINGLIST
|| true
318 runtest strlcat STRLCAT
|| true
319 runtest strlcpy STRLCPY
|| true
320 runtest strndup STRNDUP
|| true
321 runtest strptime STRPTIME
"" -D_GNU_SOURCE || true
322 runtest strsep STRSEP
|| true
323 runtest strtonum STRTONUM
"" -D_OPENBSD_SOURCE || true
324 runtest vasprintf VASPRINTF
"" -D_GNU_SOURCE || true
327 if [ "${1}" = "-depend" ]; then
329 HAVE_FTS_COMPARE_CONST
=0
330 echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&2
331 echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&3
333 elif ismanual fts FTS
${HAVE_FTS}; then
334 HAVE_FTS_COMPARE_CONST
=0
335 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
338 runtest fts FTS
|| true
341 # --- tagging support in the pager ---
342 if ismanual
"less -T" LESS_T
${HAVE_LESS_T}; then
344 elif less -ET /dev
/null
test-noop.c
1>/dev
/null
2>&3; then
346 echo "tested less -T: yes" 1>&2
347 echo "tested less -T: yes" 1>&3
351 echo "tested less -T: no" 1>&2
352 echo "tested less -T: no" 1>&3
356 # --- wide character and locale support ---
358 runtest wchar WCHAR
"-DUTF8_LOCALE=\"${UTF8_LOCALE}\"" \
359 "-D_GNU_SOURCE -DUTF8_LOCALE=\"${UTF8_LOCALE}\"" || true
362 echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
363 echo "tested wchar: no (no UTF8_LOCALE)" 1>&3
368 if [ "${1}" = "-depend" ]; then
370 echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&2
371 echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&3
374 runtest ohash OHASH
"${LD_OHASH}" "-lutil" || true
376 if [ "${HAVE_OHASH}" -eq 0 ]; then
380 # --- required functions ---
381 if [ ${HAVE_ENDIAN} -eq 0 -a \
382 ${HAVE_SYS_ENDIAN} -eq 0 -a \
383 ${HAVE_NTOHL} -eq 0 ]; then
384 echo "FATAL: no endian conversion functions found" 1>&2
385 echo "FATAL: no endian conversion functions found" 1>&3
388 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
389 echo "FATAL: nanosleep: no" 1>&2
390 echo "FATAL: nanosleep: no" 1>&3
393 if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_RECVMSG}" -eq 0 ]; then
394 echo "FATAL: recvmsg: no" 1>&2
395 echo "FATAL: recvmsg: no" 1>&3
396 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
399 if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_CMSG}" -eq 0 ]; then
400 echo "FATAL: cmsg: no" 1>&2
401 echo "FATAL: cmsg: no" 1>&3
402 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
405 [ "${FATAL}" -eq 0 ] || exit 1
408 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
409 echo "selected LDADD=\"${LDADD}\"" 1>&2
410 echo "selected LDADD=\"${LDADD}\"" 1>&3
413 # --- write config.h ---
419 #error "Do not use C++. See the INSTALL file."
422 #if !defined(__GNUC__) || (__GNUC__ < 4)
423 #define __attribute__(x)
428 [ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE"
429 [ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE"
431 [ ${HAVE_GETLINE} -eq 0 -o \
432 ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
433 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
434 ${HAVE_STRNDUP} -eq 0 ] \
435 && echo "#include <sys/types.h>"
436 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
437 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
440 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
441 echo "#define MANPATH_BASE \"${MANPATH_BASE}\""
442 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
443 echo "#define OSENUM ${OSENUM}"
444 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
445 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
446 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
447 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
448 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
449 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
450 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
451 echo "#define be32toh ntohl"
452 echo "#define htobe32 htonl"
456 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
457 #define HAVE_ENDIAN ${HAVE_ENDIAN}
458 #define HAVE_ERR ${HAVE_ERR}
459 #define HAVE_FTS ${HAVE_FTS}
460 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
461 #define HAVE_GETLINE ${HAVE_GETLINE}
462 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
463 #define HAVE_ISBLANK ${HAVE_ISBLANK}
464 #define HAVE_LESS_T ${HAVE_LESS_T}
465 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
466 #define HAVE_NTOHL ${HAVE_NTOHL}
467 #define HAVE_PLEDGE ${HAVE_PLEDGE}
468 #define HAVE_PROGNAME ${HAVE_PROGNAME}
469 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
470 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
471 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
472 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
473 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
474 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
475 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
476 #define HAVE_STRLCAT ${HAVE_STRLCAT}
477 #define HAVE_STRLCPY ${HAVE_STRLCPY}
478 #define HAVE_STRNDUP ${HAVE_STRNDUP}
479 #define HAVE_STRPTIME ${HAVE_STRPTIME}
480 #define HAVE_STRSEP ${HAVE_STRSEP}
481 #define HAVE_STRTONUM ${HAVE_STRTONUM}
482 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
483 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
484 #define HAVE_WCHAR ${HAVE_WCHAR}
485 #define HAVE_OHASH ${HAVE_OHASH}
486 #define NEED_XPG4_2 ${NEED_XPG4_2}
488 #define BINM_APROPOS "${BINM_APROPOS}"
489 #define BINM_CATMAN "${BINM_CATMAN}"
490 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
491 #define BINM_MAN "${BINM_MAN}"
492 #define BINM_SOELIM "${BINM_SOELIM}"
493 #define BINM_WHATIS "${BINM_WHATIS}"
497 if [ ${HAVE_ERR} -eq 0 ]; then
498 echo "extern void err(int, const char *, ...);"
499 echo "extern void errx(int, const char *, ...);"
500 echo "extern void warn(const char *, ...);"
501 echo "extern void warnx(const char *, ...);"
504 [ ${HAVE_GETLINE} -eq 0 ] && \
505 echo "extern ssize_t getline(char **, size_t *, FILE *);"
507 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
508 echo "extern int getsubopt(char **, char * const *, char **);"
510 [ ${HAVE_ISBLANK} -eq 0 ] && \
511 echo "extern int isblank(int);"
513 [ ${HAVE_MKDTEMP} -eq 0 ] && \
514 echo "extern char *mkdtemp(char *);"
516 if [ ${HAVE_PROGNAME} -eq 0 ]; then
517 echo "extern const char *getprogname(void);"
518 echo "extern void setprogname(const char *);"
521 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
522 echo "extern void *reallocarray(void *, size_t, size_t);"
524 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
525 echo "extern void *recallocarray(void *, size_t, size_t, size_t);"
527 [ ${HAVE_STRCASESTR} -eq 0 ] && \
528 echo "extern char *strcasestr(const char *, const char *);"
530 [ ${HAVE_STRLCAT} -eq 0 ] && \
531 echo "extern size_t strlcat(char *, const char *, size_t);"
533 [ ${HAVE_STRLCPY} -eq 0 ] && \
534 echo "extern size_t strlcpy(char *, const char *, size_t);"
536 [ ${HAVE_STRNDUP} -eq 0 ] && \
537 echo "extern char *strndup(const char *, size_t);"
539 [ ${HAVE_STRSEP} -eq 0 ] && \
540 echo "extern char *strsep(char **, const char *);"
542 [ ${HAVE_STRTONUM} -eq 0 ] && \
543 echo "extern long long strtonum(const char *, long long, long long, const char **);"
545 [ ${HAVE_VASPRINTF} -eq 0 ] && \
546 echo "extern int vasprintf(char **, const char *, va_list);"
548 echo "file config.h: written" 1>&2
549 echo "file config.h: written" 1>&3
551 # --- tests for Makefile.local -----------------------------------------
553 exec > Makefile.
local
555 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
556 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
557 [ -z "${BIN_FROM_SBIN}" ] && BIN_FROM_SBIN
="../bin"
558 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
559 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
560 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
562 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
563 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
565 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
566 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
567 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
568 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
571 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
572 [ ${BUILD_CATMAN} -gt 0 ] && \
573 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
575 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
576 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
577 [ ${BUILD_CATMAN} -gt 0 ] && \
578 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
581 BUILD_TARGETS = ${BUILD_TARGETS}
582 INSTALL_TARGETS = ${INSTALL_TARGETS}
591 BIN_FROM_SBIN = ${BIN_FROM_SBIN}
592 INCLUDEDIR = ${INCLUDEDIR}
595 WWWPREFIX = ${WWWPREFIX}
596 HTDOCDIR = ${HTDOCDIR}
597 CGIBINDIR = ${CGIBINDIR}
598 BINM_APROPOS = ${BINM_APROPOS}
599 BINM_CATMAN = ${BINM_CATMAN}
600 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
601 BINM_MAN = ${BINM_MAN}
602 BINM_SOELIM = ${BINM_SOELIM}
603 BINM_WHATIS = ${BINM_WHATIS}
604 MANM_MAN = ${MANM_MAN}
605 MANM_MANCONF = ${MANM_MANCONF}
606 MANM_MDOC = ${MANM_MDOC}
607 MANM_ROFF = ${MANM_ROFF}
608 MANM_EQN = ${MANM_EQN}
609 MANM_TBL = ${MANM_TBL}
611 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
612 INSTALL_LIB = ${INSTALL_LIB}
613 INSTALL_MAN = ${INSTALL_MAN}
614 INSTALL_DATA = ${INSTALL_DATA}
618 echo "file Makefile.local: written" 1>&2
619 echo "file Makefile.local: written" 1>&3