3 # $Id: configure,v 1.63 2017/06/12 19:05:47 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
=
105 BINM_APROPOS
="apropos"
107 BINM_MAKEWHATIS
="makewhatis"
112 MANM_MANCONF
="man.conf"
125 # --- manual settings from configure.local -----------------------------
127 if [ -r .
/configure.
local ]; then
128 echo "configure.local: reading..." 1>&2
129 echo "configure.local: reading..." 1>&3
130 cat .
/configure.
local 1>&3
133 echo "configure.local: no (fully automatic configuration)" 1>&2
134 echo "configure.local: no (fully automatic configuration)" 1>&3
138 # --- tests for config.h ----------------------------------------------
140 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
142 # Check whether this HAVE_ setting is manually overridden.
143 # If yes, use the override, if no, do not decide anything yet.
144 # Arguments: lower-case test name, manual value
146 [ -z "${3}" ] && return 1
147 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
148 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
153 # Run a single autoconfiguration test.
154 # In case of success, enable the feature.
155 # In case of failure, do not decide anything yet.
156 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
158 cat 1>&3 << __HEREDOC__
160 ${COMP} -o test-${1} test-${1}.c ${3}
163 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
165 echo "${1}${3}: ${CC} succeeded" 1>&3
167 echo "${1}${3}: ${CC} failed with $?" 1>&3
172 if .
/test-${1} 1>&3 2>&3; then
173 echo "${1}${3}: yes" 1>&2
174 echo "${1}${3}: yes" 1>&3
180 echo "${1}${3}: execution failed with $?" 1>&3
187 # Run a complete autoconfiguration test, including the check for
188 # a manual override and disabling the feature on failure.
189 # Arguments: lower case name, upper case name, additional CFLAGS
191 eval _manual
=\
${HAVE_${2}}
192 ismanual
"${1}" "${2}" "${_manual}" && return 0
193 singletest
"${1}" "${2}" "${3}" && return 0
194 echo "${1}${3}: no" 1>&2
199 # Select a UTF-8 locale.
201 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
202 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
203 echo "UTF8_LOCALE: testing..." 1>&3
204 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
205 if [ -z "${UTF8_LOCALE}" ]; then
206 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
207 [ -n "${UTF8_LOCALE}" ] || return 1
209 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
210 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
216 # --- library functions ---
217 runtest dirent
-namlen DIRENT_NAMLEN
|| true
218 runtest be32toh ENDIAN
|| true
219 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
220 runtest EFTYPE EFTYPE
|| true
221 runtest err ERR
|| true
222 runtest getline GETLINE
|| true
223 runtest getsubopt GETSUBOPT
|| true
224 runtest isblank ISBLANK
|| true
225 runtest mkdtemp MKDTEMP
|| true
226 runtest ntohl NTOHL
|| true
227 runtest O_DIRECTORY O_DIRECTORY
|| true
228 runtest PATH_MAX PATH_MAX
|| true
229 runtest pledge PLEDGE
|| true
230 runtest sandbox_init SANDBOX_INIT
|| true
231 runtest progname PROGNAME
|| true
232 runtest reallocarray REALLOCARRAY
|| true
233 runtest recallocarray RECALLOCARRAY
|| true
234 runtest rewb
-bsd REWB_BSD
|| true
235 runtest rewb
-sysv REWB_SYSV
|| true
236 runtest strcasestr STRCASESTR
|| true
237 runtest stringlist STRINGLIST
|| true
238 runtest strlcat STRLCAT
|| true
239 runtest strlcpy STRLCPY
|| true
240 runtest strptime STRPTIME
|| true
241 runtest strsep STRSEP
|| true
242 runtest strtonum STRTONUM
|| true
243 runtest vasprintf VASPRINTF
|| true
245 if [ ${HAVE_ENDIAN} -eq 0 -a \
246 ${HAVE_SYS_ENDIAN} -eq 0 -a \
247 ${HAVE_NTOHL} -eq 0 ]; then
248 echo "FATAL: no endian conversion functions found" 1>&2
249 echo "FATAL: no endian conversion functions found" 1>&3
253 if ismanual fts FTS
${HAVE_FTS}; then
254 HAVE_FTS_COMPARE_CONST
=0
255 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
258 runtest fts FTS
|| true
261 # --- wide character and locale support ---
263 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
266 echo "wchar: no (no UTF8_LOCALE)" 1>&2
267 echo "wchar: no (no UTF8_LOCALE)" 1>&3
271 if [ -n "${LD_NANOSLEEP}" ]; then
272 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
273 elif singletest nanosleep NANOSLEEP
; then
275 elif runtest nanosleep NANOSLEEP
"-lrt"; then
278 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
279 echo "FATAL: nanosleep: no" 1>&2
280 echo "FATAL: nanosleep: no" 1>&3
284 if [ ${BUILD_CATMAN} -gt 0 ]; then
286 if [ -n "${LD_RECVMSG}" ]; then
287 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
288 elif singletest recvmsg RECVMSG
; then
290 elif runtest recvmsg RECVMSG
"-lsocket"; then
291 LD_RECVMSG
="-lsocket"
293 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
294 echo "FATAL: recvmsg: no" 1>&2
295 echo "FATAL: recvmsg: no" 1>&3
296 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
301 if singletest cmsg CMSG
; then
303 elif runtest cmsg CMSG
"-D_XPG4_2"; then
306 if [ "${HAVE_CMSG}" -eq 0 ]; then
307 echo "FATAL: cmsg: no" 1>&2
308 echo "FATAL: cmsg: no" 1>&3
309 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
315 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
317 elif [ -n "${LD_OHASH}" ]; then
318 runtest ohash OHASH
"${LD_OHASH}" || true
319 elif singletest ohash OHASH
; then
321 elif runtest ohash OHASH
"-lutil"; then
324 if [ "${HAVE_OHASH}" -eq 0 ]; then
329 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
330 echo "LDADD=\"${LDADD}\"" 1>&2
331 echo "LDADD=\"${LDADD}\"" 1>&3
334 # --- write config.h ---
340 #error "Do not use C++. See the INSTALL file."
343 #if !defined(__GNUC__) || (__GNUC__ < 4)
344 #define __attribute__(x)
347 #if defined(__linux__) || defined(__MINT__)
348 #define _GNU_SOURCE /* See test-*.c what needs this. */
353 [ ${HAVE_GETLINE} -eq 0 -o \
354 ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
355 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
356 && echo "#include <sys/types.h>"
357 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
358 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
361 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
362 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
363 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
364 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
365 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
366 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
367 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
368 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
369 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
370 echo "#define be32toh ntohl"
371 echo "#define htobe32 htonl"
375 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
376 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
377 #define HAVE_ENDIAN ${HAVE_ENDIAN}
378 #define HAVE_ERR ${HAVE_ERR}
379 #define HAVE_FTS ${HAVE_FTS}
380 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
381 #define HAVE_GETLINE ${HAVE_GETLINE}
382 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
383 #define HAVE_ISBLANK ${HAVE_ISBLANK}
384 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
385 #define HAVE_NTOHL ${HAVE_NTOHL}
386 #define HAVE_PLEDGE ${HAVE_PLEDGE}
387 #define HAVE_PROGNAME ${HAVE_PROGNAME}
388 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
389 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
390 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
391 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
392 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
393 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
394 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
395 #define HAVE_STRLCAT ${HAVE_STRLCAT}
396 #define HAVE_STRLCPY ${HAVE_STRLCPY}
397 #define HAVE_STRPTIME ${HAVE_STRPTIME}
398 #define HAVE_STRSEP ${HAVE_STRSEP}
399 #define HAVE_STRTONUM ${HAVE_STRTONUM}
400 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
401 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
402 #define HAVE_WCHAR ${HAVE_WCHAR}
403 #define HAVE_OHASH ${HAVE_OHASH}
405 #define BINM_APROPOS "${BINM_APROPOS}"
406 #define BINM_CATMAN "${BINM_CATMAN}"
407 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
408 #define BINM_MAN "${BINM_MAN}"
409 #define BINM_SOELIM "${BINM_SOELIM}"
410 #define BINM_WHATIS "${BINM_WHATIS}"
414 if [ ${HAVE_ERR} -eq 0 ]; then
415 echo "extern void err(int, const char *, ...);"
416 echo "extern void errx(int, const char *, ...);"
417 echo "extern void warn(const char *, ...);"
418 echo "extern void warnx(const char *, ...);"
421 [ ${HAVE_GETLINE} -eq 0 ] && \
422 echo "extern ssize_t getline(char **, size_t *, FILE *);"
424 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
425 echo "extern int getsubopt(char **, char * const *, char **);"
427 [ ${HAVE_ISBLANK} -eq 0 ] && \
428 echo "extern int isblank(int);"
430 [ ${HAVE_MKDTEMP} -eq 0 ] && \
431 echo "extern char *mkdtemp(char *);"
433 if [ ${HAVE_PROGNAME} -eq 0 ]; then
434 echo "extern const char *getprogname(void);"
435 echo "extern void setprogname(const char *);"
438 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
439 echo "extern void *reallocarray(void *, size_t, size_t);"
441 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
442 echo "extern void *recallocarray(void *, size_t, size_t, size_t);"
444 [ ${HAVE_STRCASESTR} -eq 0 ] && \
445 echo "extern char *strcasestr(const char *, const char *);"
447 [ ${HAVE_STRLCAT} -eq 0 ] && \
448 echo "extern size_t strlcat(char *, const char *, size_t);"
450 [ ${HAVE_STRLCPY} -eq 0 ] && \
451 echo "extern size_t strlcpy(char *, const char *, size_t);"
453 [ ${HAVE_STRSEP} -eq 0 ] && \
454 echo "extern char *strsep(char **, const char *);"
456 [ ${HAVE_STRTONUM} -eq 0 ] && \
457 echo "extern long long strtonum(const char *, long long, long long, const char **);"
459 [ ${HAVE_VASPRINTF} -eq 0 ] && \
460 echo "extern int vasprintf(char **, const char *, va_list);"
462 echo "config.h: written" 1>&2
463 echo "config.h: written" 1>&3
465 # --- tests for Makefile.local -----------------------------------------
467 exec > Makefile.
local
469 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
470 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
471 [ -z "${BIN_FROM_SBIN}" ] && BIN_FROM_SBIN
="../bin"
472 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
473 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
474 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
476 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
477 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
479 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
480 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
481 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
482 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
485 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
486 [ ${BUILD_CATMAN} -gt 0 ] && \
487 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
489 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
490 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
491 [ ${BUILD_CATMAN} -gt 0 ] && \
492 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
495 BUILD_TARGETS = ${BUILD_TARGETS}
496 INSTALL_TARGETS = ${INSTALL_TARGETS}
505 BIN_FROM_SBIN = ${BIN_FROM_SBIN}
506 INCLUDEDIR = ${INCLUDEDIR}
509 WWWPREFIX = ${WWWPREFIX}
510 HTDOCDIR = ${HTDOCDIR}
511 CGIBINDIR = ${CGIBINDIR}
512 BINM_APROPOS = ${BINM_APROPOS}
513 BINM_CATMAN = ${BINM_CATMAN}
514 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
515 BINM_MAN = ${BINM_MAN}
516 BINM_SOELIM = ${BINM_SOELIM}
517 BINM_WHATIS = ${BINM_WHATIS}
518 MANM_MAN = ${MANM_MAN}
519 MANM_MANCONF = ${MANM_MANCONF}
520 MANM_MDOC = ${MANM_MDOC}
521 MANM_ROFF = ${MANM_ROFF}
522 MANM_EQN = ${MANM_EQN}
523 MANM_TBL = ${MANM_TBL}
525 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
526 INSTALL_LIB = ${INSTALL_LIB}
527 INSTALL_MAN = ${INSTALL_MAN}
528 INSTALL_DATA = ${INSTALL_DATA}
532 echo "Makefile.local: written" 1>&2
533 echo "Makefile.local: written" 1>&3