3 # $Id: configure,v 1.62 2017/03/04 16:36:29 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
=
104 BINM_APROPOS
="apropos"
106 BINM_MAKEWHATIS
="makewhatis"
111 MANM_MANCONF
="man.conf"
124 # --- manual settings from configure.local -----------------------------
126 if [ -r .
/configure.
local ]; then
127 echo "configure.local: reading..." 1>&2
128 echo "configure.local: reading..." 1>&3
129 cat .
/configure.
local 1>&3
132 echo "configure.local: no (fully automatic configuration)" 1>&2
133 echo "configure.local: no (fully automatic configuration)" 1>&3
137 # --- tests for config.h ----------------------------------------------
139 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
141 # Check whether this HAVE_ setting is manually overridden.
142 # If yes, use the override, if no, do not decide anything yet.
143 # Arguments: lower-case test name, manual value
145 [ -z "${3}" ] && return 1
146 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
147 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
152 # Run a single autoconfiguration test.
153 # In case of success, enable the feature.
154 # In case of failure, do not decide anything yet.
155 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
157 cat 1>&3 << __HEREDOC__
159 ${COMP} -o test-${1} test-${1}.c ${3}
162 if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
164 echo "${1}${3}: ${CC} succeeded" 1>&3
166 echo "${1}${3}: ${CC} failed with $?" 1>&3
171 if .
/test-${1} 1>&3 2>&3; then
172 echo "${1}${3}: yes" 1>&2
173 echo "${1}${3}: yes" 1>&3
179 echo "${1}${3}: execution failed with $?" 1>&3
186 # Run a complete autoconfiguration test, including the check for
187 # a manual override and disabling the feature on failure.
188 # Arguments: lower case name, upper case name, additional CFLAGS
190 eval _manual
=\
${HAVE_${2}}
191 ismanual
"${1}" "${2}" "${_manual}" && return 0
192 singletest
"${1}" "${2}" "${3}" && return 0
193 echo "${1}${3}: no" 1>&2
198 # Select a UTF-8 locale.
200 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
201 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
202 echo "UTF8_LOCALE: testing..." 1>&3
203 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
204 if [ -z "${UTF8_LOCALE}" ]; then
205 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
206 [ -n "${UTF8_LOCALE}" ] || return 1
208 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
209 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
215 # --- library functions ---
216 runtest dirent
-namlen DIRENT_NAMLEN
|| true
217 runtest be32toh ENDIAN
|| true
218 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
219 runtest EFTYPE EFTYPE
|| true
220 runtest err ERR
|| true
221 runtest getline GETLINE
|| true
222 runtest getsubopt GETSUBOPT
|| true
223 runtest isblank ISBLANK
|| true
224 runtest mkdtemp MKDTEMP
|| true
225 runtest ntohl NTOHL
|| true
226 runtest O_DIRECTORY O_DIRECTORY
|| true
227 runtest PATH_MAX PATH_MAX
|| true
228 runtest pledge PLEDGE
|| true
229 runtest sandbox_init SANDBOX_INIT
|| true
230 runtest progname PROGNAME
|| true
231 runtest reallocarray REALLOCARRAY
|| true
232 runtest rewb
-bsd REWB_BSD
|| true
233 runtest rewb
-sysv REWB_SYSV
|| true
234 runtest strcasestr STRCASESTR
|| true
235 runtest stringlist STRINGLIST
|| true
236 runtest strlcat STRLCAT
|| true
237 runtest strlcpy STRLCPY
|| true
238 runtest strptime STRPTIME
|| true
239 runtest strsep STRSEP
|| true
240 runtest strtonum STRTONUM
|| true
241 runtest vasprintf VASPRINTF
|| true
243 if [ ${HAVE_ENDIAN} -eq 0 -a \
244 ${HAVE_SYS_ENDIAN} -eq 0 -a \
245 ${HAVE_NTOHL} -eq 0 ]; then
246 echo "FATAL: no endian conversion functions found" 1>&2
247 echo "FATAL: no endian conversion functions found" 1>&3
251 if ismanual fts FTS
${HAVE_FTS}; then
252 HAVE_FTS_COMPARE_CONST
=0
253 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
256 runtest fts FTS
|| true
259 # --- wide character and locale support ---
261 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
264 echo "wchar: no (no UTF8_LOCALE)" 1>&2
265 echo "wchar: no (no UTF8_LOCALE)" 1>&3
269 if [ -n "${LD_NANOSLEEP}" ]; then
270 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
271 elif singletest nanosleep NANOSLEEP
; then
273 elif runtest nanosleep NANOSLEEP
"-lrt"; then
276 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
277 echo "FATAL: nanosleep: no" 1>&2
278 echo "FATAL: nanosleep: no" 1>&3
282 if [ ${BUILD_CATMAN} -gt 0 ]; then
284 if [ -n "${LD_RECVMSG}" ]; then
285 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
286 elif singletest recvmsg RECVMSG
; then
288 elif runtest recvmsg RECVMSG
"-lsocket"; then
289 LD_RECVMSG
="-lsocket"
291 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
292 echo "FATAL: recvmsg: no" 1>&2
293 echo "FATAL: recvmsg: no" 1>&3
294 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
299 if singletest cmsg CMSG
; then
301 elif runtest cmsg CMSG
"-D_XPG4_2"; then
304 if [ "${HAVE_CMSG}" -eq 0 ]; then
305 echo "FATAL: cmsg: no" 1>&2
306 echo "FATAL: cmsg: no" 1>&3
307 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
313 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
315 elif [ -n "${LD_OHASH}" ]; then
316 runtest ohash OHASH
"${LD_OHASH}" || true
317 elif singletest ohash OHASH
; then
319 elif runtest ohash OHASH
"-lutil"; then
322 if [ "${HAVE_OHASH}" -eq 0 ]; then
327 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
328 echo "LDADD=\"${LDADD}\"" 1>&2
329 echo "LDADD=\"${LDADD}\"" 1>&3
332 # --- write config.h ---
338 #error "Do not use C++. See the INSTALL file."
341 #if !defined(__GNUC__) || (__GNUC__ < 4)
342 #define __attribute__(x)
345 #if defined(__linux__) || defined(__MINT__)
346 #define _GNU_SOURCE /* See test-*.c what needs this. */
351 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
352 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
353 && echo "#include <sys/types.h>"
354 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
355 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
358 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
359 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
360 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
361 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
362 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
363 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
364 [ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
365 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
366 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
367 echo "#define be32toh ntohl"
368 echo "#define htobe32 htonl"
372 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
373 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
374 #define HAVE_ENDIAN ${HAVE_ENDIAN}
375 #define HAVE_ERR ${HAVE_ERR}
376 #define HAVE_FTS ${HAVE_FTS}
377 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
378 #define HAVE_GETLINE ${HAVE_GETLINE}
379 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
380 #define HAVE_ISBLANK ${HAVE_ISBLANK}
381 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
382 #define HAVE_NTOHL ${HAVE_NTOHL}
383 #define HAVE_PLEDGE ${HAVE_PLEDGE}
384 #define HAVE_PROGNAME ${HAVE_PROGNAME}
385 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
386 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
387 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
388 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
389 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
390 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
391 #define HAVE_STRLCAT ${HAVE_STRLCAT}
392 #define HAVE_STRLCPY ${HAVE_STRLCPY}
393 #define HAVE_STRPTIME ${HAVE_STRPTIME}
394 #define HAVE_STRSEP ${HAVE_STRSEP}
395 #define HAVE_STRTONUM ${HAVE_STRTONUM}
396 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
397 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
398 #define HAVE_WCHAR ${HAVE_WCHAR}
399 #define HAVE_OHASH ${HAVE_OHASH}
401 #define BINM_APROPOS "${BINM_APROPOS}"
402 #define BINM_CATMAN "${BINM_CATMAN}"
403 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
404 #define BINM_MAN "${BINM_MAN}"
405 #define BINM_SOELIM "${BINM_SOELIM}"
406 #define BINM_WHATIS "${BINM_WHATIS}"
410 if [ ${HAVE_ERR} -eq 0 ]; then
411 echo "extern void err(int, const char *, ...);"
412 echo "extern void errx(int, const char *, ...);"
413 echo "extern void warn(const char *, ...);"
414 echo "extern void warnx(const char *, ...);"
417 [ ${HAVE_GETLINE} -eq 0 ] && \
418 echo "extern ssize_t getline(char **, size_t *, FILE *);"
420 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
421 echo "extern int getsubopt(char **, char * const *, char **);"
423 [ ${HAVE_ISBLANK} -eq 0 ] && \
424 echo "extern int isblank(int);"
426 [ ${HAVE_MKDTEMP} -eq 0 ] && \
427 echo "extern char *mkdtemp(char *);"
429 if [ ${HAVE_PROGNAME} -eq 0 ]; then
430 echo "extern const char *getprogname(void);"
431 echo "extern void setprogname(const char *);"
434 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
435 echo "extern void *reallocarray(void *, size_t, size_t);"
437 [ ${HAVE_STRCASESTR} -eq 0 ] && \
438 echo "extern char *strcasestr(const char *, const char *);"
440 [ ${HAVE_STRLCAT} -eq 0 ] && \
441 echo "extern size_t strlcat(char *, const char *, size_t);"
443 [ ${HAVE_STRLCPY} -eq 0 ] && \
444 echo "extern size_t strlcpy(char *, const char *, size_t);"
446 [ ${HAVE_STRSEP} -eq 0 ] && \
447 echo "extern char *strsep(char **, const char *);"
449 [ ${HAVE_STRTONUM} -eq 0 ] && \
450 echo "extern long long strtonum(const char *, long long, long long, const char **);"
452 [ ${HAVE_VASPRINTF} -eq 0 ] && \
453 echo "extern int vasprintf(char **, const char *, va_list);"
455 echo "config.h: written" 1>&2
456 echo "config.h: written" 1>&3
458 # --- tests for Makefile.local -----------------------------------------
460 exec > Makefile.
local
462 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
463 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
464 [ -z "${BIN_FROM_SBIN}" ] && BIN_FROM_SBIN
="../bin"
465 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
466 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
467 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
469 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
470 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
472 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
473 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
474 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
475 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
478 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
479 [ ${BUILD_CATMAN} -gt 0 ] && \
480 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
482 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
483 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
484 [ ${BUILD_CATMAN} -gt 0 ] && \
485 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
488 BUILD_TARGETS = ${BUILD_TARGETS}
489 INSTALL_TARGETS = ${INSTALL_TARGETS}
498 BIN_FROM_SBIN = ${BIN_FROM_SBIN}
499 INCLUDEDIR = ${INCLUDEDIR}
502 WWWPREFIX = ${WWWPREFIX}
503 HTDOCDIR = ${HTDOCDIR}
504 CGIBINDIR = ${CGIBINDIR}
505 BINM_APROPOS = ${BINM_APROPOS}
506 BINM_CATMAN = ${BINM_CATMAN}
507 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
508 BINM_MAN = ${BINM_MAN}
509 BINM_SOELIM = ${BINM_SOELIM}
510 BINM_WHATIS = ${BINM_WHATIS}
511 MANM_MAN = ${MANM_MAN}
512 MANM_MANCONF = ${MANM_MANCONF}
513 MANM_MDOC = ${MANM_MDOC}
514 MANM_ROFF = ${MANM_ROFF}
515 MANM_EQN = ${MANM_EQN}
516 MANM_TBL = ${MANM_TBL}
518 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
519 INSTALL_LIB = ${INSTALL_LIB}
520 INSTALL_MAN = ${INSTALL_MAN}
521 INSTALL_DATA = ${INSTALL_DATA}
525 echo "Makefile.local: written" 1>&2
526 echo "Makefile.local: written" 1>&3