3 # $Id: configure,v 1.67 2018/08/15 02:15:52 schwarze Exp $
5 # Copyright (c) 2014,2015,2016,2017,2018 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"
43 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
63 HAVE_FTS_COMPARE_CONST
=
109 BINM_APROPOS
="apropos"
111 BINM_MAKEWHATIS
="makewhatis"
116 MANM_MANCONF
="man.conf"
129 # --- manual settings from configure.local -----------------------------
131 if [ -r .
/configure.
local ]; then
132 echo "file configure.local: reading..." 1>&2
133 echo "file configure.local: reading..." 1>&3
134 cat .
/configure.
local 1>&3
137 echo "file configure.local: no (fully automatic configuration)" 1>&2
138 echo "file configure.local: no (fully automatic configuration)" 1>&3
142 # --- tests functions --------------------------------------------------
144 # Check whether this HAVE_ setting is manually overridden.
145 # If yes, use the override, if no, do not decide anything yet.
146 # Arguments: test file name, test var name, manual value
148 [ -z "${3}" ] && return 1
149 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&2
150 echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&3
155 # Run a single autoconfiguration test.
156 # In case of success, enable the feature.
157 # In case of failure, do not decide anything yet.
158 # Arguments: test file name, test var name, additional CFLAGS
161 cat 1>&3 << __HEREDOC__
163 ${COMP} -o test-${1} test-${1}.c ${3} ${4}
166 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} ${4} 1>&3 2>&3
168 echo "partial result of ${n}: ${CC} succeeded" 1>&3
170 echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
171 echo "result of compiling ${n}: no" 1>&3
176 if .
/test-${1} 1>&3 2>&3; then
177 echo "tested ${n}: yes" 1>&2
178 echo "result of running ${n}: yes" 1>&3
181 [ "X$3" = "X-D_GNU_SOURCE" ] && NEED_GNU_SOURCE
=1
182 [ "X$3" = "X-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE
=1
186 echo "result of ${n}: execution failed with exit status $?" 1>&3
187 echo "result of running ${n}: no" 1>&3
194 # Run a complete autoconfiguration test, including the check for
195 # a manual override and disabling the feature on failure.
196 # Arguments: test file name, test var name, additional CFLAGS
198 eval _manual
=\
${HAVE_${2}}
199 ismanual
"${1}" "${2}" "${_manual}" && return 0
200 singletest
"${1}" "${2}" "${3}" "${4}" && return 0
201 echo "tested ${1}${3}${4}: no" 1>&2
206 # Select a UTF-8 locale.
208 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
209 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
210 echo "testing UTF8_LOCALE ..." 1>&3
211 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
212 if [ -z "${UTF8_LOCALE}" ]; then
213 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
214 [ -n "${UTF8_LOCALE}" ] || return 1
216 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
217 echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
222 # --- compiler options -------------------------------------------------
224 DEFCFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter"
226 if [ -n "${CFLAGS}" ]; then
227 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
229 COMP
="${CC} ${DEFCFLAGS} -Wno-unused -Werror"
231 echo -n "tested ${CC} -W: " 1>&2
232 echo -n "testing ${CC} -W: " 1>&3
233 runtest noop WFLAG
|| true
235 if [ -n "${CFLAGS}" ]; then
236 echo "CFLAGS specified manually:" 1>&3
237 elif [ ${HAVE_WFLAG} -eq 0 ]; then
240 CFLAGS
="${DEFCFLAGS}"
242 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2
243 echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3
246 COMP
="${CC} ${CFLAGS}"
247 [ ${HAVE_WFLAG} -eq 0 ] || COMP
="${COMP} -Wno-unused -Werror"
249 if [ -n "${STATIC}" ]; then
250 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2
251 echo "selected STATIC=\"${STATIC}\" (manual)" 1>&3
254 runtest noop STATIC
-static || true
255 [ ${HAVE_STATIC} -eq 0 ] || STATIC
="-static"
256 echo "selected STATIC=\"${STATIC}\"" 1>&2
257 echo "selected STATIC=\"${STATIC}\"" 1>&3
261 # --- tests for config.h ----------------------------------------------
263 # --- library functions ---
264 runtest dirent
-namlen DIRENT_NAMLEN
|| true
265 runtest be32toh ENDIAN
|| true
266 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
267 runtest EFTYPE EFTYPE
|| true
268 runtest err ERR
|| true
269 runtest getline GETLINE
|| true
270 singletest getsubopt GETSUBOPT
|| \
271 runtest getsubopt GETSUBOPT
-D_GNU_SOURCE || true
272 runtest isblank ISBLANK
|| true
273 runtest mkdtemp MKDTEMP
|| true
274 runtest ntohl NTOHL
|| true
275 runtest O_DIRECTORY O_DIRECTORY
|| true
276 runtest PATH_MAX PATH_MAX
|| true
277 runtest pledge PLEDGE
|| true
278 runtest sandbox_init SANDBOX_INIT
|| true
279 runtest progname PROGNAME
|| true
280 singletest reallocarray REALLOCARRAY
|| \
281 runtest reallocarray REALLOCARRAY
-D_OPENBSD_SOURCE || true
282 singletest recallocarray RECALLOCARRAY
|| \
283 runtest recallocarray RECALLOCARRAY
-D_OPENBSD_SOURCE || true
284 runtest rewb
-bsd REWB_BSD
|| true
285 runtest rewb
-sysv REWB_SYSV
|| true
286 singletest strcasestr STRCASESTR
|| \
287 runtest strcasestr STRCASESTR
-D_GNU_SOURCE || true
288 runtest stringlist STRINGLIST
|| true
289 runtest strlcat STRLCAT
|| true
290 runtest strlcpy STRLCPY
|| true
291 runtest strndup STRNDUP
|| true
292 singletest strptime STRPTIME
|| \
293 runtest strptime STRPTIME
-D_GNU_SOURCE || true
294 runtest strsep STRSEP
|| true
295 singletest strtonum STRTONUM
|| \
296 runtest strtonum STRTONUM
-D_OPENBSD_SOURCE || true
297 singletest vasprintf VASPRINTF
|| \
298 runtest vasprintf VASPRINTF
-D_GNU_SOURCE || true
300 if [ ${HAVE_ENDIAN} -eq 0 -a \
301 ${HAVE_SYS_ENDIAN} -eq 0 -a \
302 ${HAVE_NTOHL} -eq 0 ]; then
303 echo "FATAL: no endian conversion functions found" 1>&2
304 echo "FATAL: no endian conversion functions found" 1>&3
308 if ismanual fts FTS
${HAVE_FTS}; then
309 HAVE_FTS_COMPARE_CONST
=0
310 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
313 runtest fts FTS
|| true
316 # --- wide character and locale support ---
318 singletest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || \
319 runtest wchar WCHAR
-D_GNU_SOURCE \
320 -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
323 echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
324 echo "tested wchar: no (no UTF8_LOCALE)" 1>&3
329 if [ -n "${LD_NANOSLEEP}" ]; then
330 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
331 elif singletest nanosleep NANOSLEEP
; then
333 elif runtest nanosleep NANOSLEEP
"-lrt"; then
336 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
337 echo "FATAL: nanosleep: no" 1>&2
338 echo "FATAL: nanosleep: no" 1>&3
342 if [ ${BUILD_CATMAN} -gt 0 ]; then
344 if [ -n "${LD_RECVMSG}" ]; then
345 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
346 elif singletest recvmsg RECVMSG
; then
348 elif runtest recvmsg RECVMSG
"-lsocket"; then
349 LD_RECVMSG
="-lsocket"
351 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
352 echo "FATAL: recvmsg: no" 1>&2
353 echo "FATAL: recvmsg: no" 1>&3
354 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
359 if singletest cmsg CMSG
; then
361 elif runtest cmsg CMSG
"-D_XPG4_2"; then
364 if [ "${HAVE_CMSG}" -eq 0 ]; then
365 echo "FATAL: cmsg: no" 1>&2
366 echo "FATAL: cmsg: no" 1>&3
367 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
373 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
375 elif [ -n "${LD_OHASH}" ]; then
376 runtest ohash OHASH
"${LD_OHASH}" || true
377 elif singletest ohash OHASH
; then
379 elif runtest ohash OHASH
"-lutil"; then
382 if [ "${HAVE_OHASH}" -eq 0 ]; then
387 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
388 echo "selected LDADD=\"${LDADD}\"" 1>&2
389 echo "selected LDADD=\"${LDADD}\"" 1>&3
392 # --- write config.h ---
398 #error "Do not use C++. See the INSTALL file."
401 #if !defined(__GNUC__) || (__GNUC__ < 4)
402 #define __attribute__(x)
407 [ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE"
408 [ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE"
410 [ ${HAVE_GETLINE} -eq 0 -o \
411 ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
412 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
413 ${HAVE_STRNDUP} -eq 0 ] \
414 && echo "#include <sys/types.h>"
415 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
416 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
419 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
420 echo "#define MANPATH_BASE \"${MANPATH_BASE}\""
421 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
422 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
423 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
424 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
425 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
426 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
427 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
428 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
429 echo "#define be32toh ntohl"
430 echo "#define htobe32 htonl"
434 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
435 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
436 #define HAVE_ENDIAN ${HAVE_ENDIAN}
437 #define HAVE_ERR ${HAVE_ERR}
438 #define HAVE_FTS ${HAVE_FTS}
439 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
440 #define HAVE_GETLINE ${HAVE_GETLINE}
441 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
442 #define HAVE_ISBLANK ${HAVE_ISBLANK}
443 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
444 #define HAVE_NTOHL ${HAVE_NTOHL}
445 #define HAVE_PLEDGE ${HAVE_PLEDGE}
446 #define HAVE_PROGNAME ${HAVE_PROGNAME}
447 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
448 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
449 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
450 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
451 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
452 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
453 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
454 #define HAVE_STRLCAT ${HAVE_STRLCAT}
455 #define HAVE_STRLCPY ${HAVE_STRLCPY}
456 #define HAVE_STRNDUP ${HAVE_STRNDUP}
457 #define HAVE_STRPTIME ${HAVE_STRPTIME}
458 #define HAVE_STRSEP ${HAVE_STRSEP}
459 #define HAVE_STRTONUM ${HAVE_STRTONUM}
460 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
461 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
462 #define HAVE_WCHAR ${HAVE_WCHAR}
463 #define HAVE_OHASH ${HAVE_OHASH}
465 #define BINM_APROPOS "${BINM_APROPOS}"
466 #define BINM_CATMAN "${BINM_CATMAN}"
467 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
468 #define BINM_MAN "${BINM_MAN}"
469 #define BINM_SOELIM "${BINM_SOELIM}"
470 #define BINM_WHATIS "${BINM_WHATIS}"
474 if [ ${HAVE_ERR} -eq 0 ]; then
475 echo "extern void err(int, const char *, ...);"
476 echo "extern void errx(int, const char *, ...);"
477 echo "extern void warn(const char *, ...);"
478 echo "extern void warnx(const char *, ...);"
481 [ ${HAVE_GETLINE} -eq 0 ] && \
482 echo "extern ssize_t getline(char **, size_t *, FILE *);"
484 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
485 echo "extern int getsubopt(char **, char * const *, char **);"
487 [ ${HAVE_ISBLANK} -eq 0 ] && \
488 echo "extern int isblank(int);"
490 [ ${HAVE_MKDTEMP} -eq 0 ] && \
491 echo "extern char *mkdtemp(char *);"
493 if [ ${HAVE_PROGNAME} -eq 0 ]; then
494 echo "extern const char *getprogname(void);"
495 echo "extern void setprogname(const char *);"
498 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
499 echo "extern void *reallocarray(void *, size_t, size_t);"
501 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
502 echo "extern void *recallocarray(void *, size_t, size_t, size_t);"
504 [ ${HAVE_STRCASESTR} -eq 0 ] && \
505 echo "extern char *strcasestr(const char *, const char *);"
507 [ ${HAVE_STRLCAT} -eq 0 ] && \
508 echo "extern size_t strlcat(char *, const char *, size_t);"
510 [ ${HAVE_STRLCPY} -eq 0 ] && \
511 echo "extern size_t strlcpy(char *, const char *, size_t);"
513 [ ${HAVE_STRNDUP} -eq 0 ] && \
514 echo "extern char *strndup(const char *, size_t);"
516 [ ${HAVE_STRSEP} -eq 0 ] && \
517 echo "extern char *strsep(char **, const char *);"
519 [ ${HAVE_STRTONUM} -eq 0 ] && \
520 echo "extern long long strtonum(const char *, long long, long long, const char **);"
522 [ ${HAVE_VASPRINTF} -eq 0 ] && \
523 echo "extern int vasprintf(char **, const char *, va_list);"
525 echo "file config.h: written" 1>&2
526 echo "file config.h: written" 1>&3
528 # --- tests for Makefile.local -----------------------------------------
530 exec > Makefile.
local
532 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
533 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
534 [ -z "${BIN_FROM_SBIN}" ] && BIN_FROM_SBIN
="../bin"
535 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
536 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
537 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
539 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
540 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
542 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
543 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
544 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
545 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
548 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
549 [ ${BUILD_CATMAN} -gt 0 ] && \
550 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
552 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
553 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
554 [ ${BUILD_CATMAN} -gt 0 ] && \
555 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
558 BUILD_TARGETS = ${BUILD_TARGETS}
559 INSTALL_TARGETS = ${INSTALL_TARGETS}
568 BIN_FROM_SBIN = ${BIN_FROM_SBIN}
569 INCLUDEDIR = ${INCLUDEDIR}
572 WWWPREFIX = ${WWWPREFIX}
573 HTDOCDIR = ${HTDOCDIR}
574 CGIBINDIR = ${CGIBINDIR}
575 BINM_APROPOS = ${BINM_APROPOS}
576 BINM_CATMAN = ${BINM_CATMAN}
577 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
578 BINM_MAN = ${BINM_MAN}
579 BINM_SOELIM = ${BINM_SOELIM}
580 BINM_WHATIS = ${BINM_WHATIS}
581 MANM_MAN = ${MANM_MAN}
582 MANM_MANCONF = ${MANM_MANCONF}
583 MANM_MDOC = ${MANM_MDOC}
584 MANM_ROFF = ${MANM_ROFF}
585 MANM_EQN = ${MANM_EQN}
586 MANM_TBL = ${MANM_TBL}
588 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
589 INSTALL_LIB = ${INSTALL_LIB}
590 INSTALL_MAN = ${INSTALL_MAN}
591 INSTALL_DATA = ${INSTALL_DATA}
595 echo "file Makefile.local: written" 1>&2
596 echo "file Makefile.local: written" 1>&3