3 # $Id: configure,v 1.57 2017/02/08 16:11:41 schwarze Exp $
5 # Copyright (c) 2014, 2015, 2016 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 MANPATH_DEFAULT
="/usr/share/man:/usr/X11R6/man:/usr/local/man"
40 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
41 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
42 CFLAGS
="${CFLAGS} -Wno-unused-parameter"
61 HAVE_FTS_COMPARE_CONST
=
100 BINM_APROPOS
="apropos"
101 BINM_MAKEWHATIS
="makewhatis"
106 MANM_MANCONF
="man.conf"
118 # --- manual settings from configure.local -----------------------------
120 if [ -r .
/configure.
local ]; then
121 echo "configure.local: reading..." 1>&2
122 echo "configure.local: reading..." 1>&3
123 cat .
/configure.
local 1>&3
126 echo "configure.local: no (fully automatic configuration)" 1>&2
127 echo "configure.local: no (fully automatic configuration)" 1>&3
131 # --- tests for config.h ----------------------------------------------
133 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
135 # Check whether this HAVE_ setting is manually overridden.
136 # If yes, use the override, if no, do not decide anything yet.
137 # Arguments: lower-case test name, manual value
139 [ -z "${3}" ] && return 1
140 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
141 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
146 # Run a single autoconfiguration test.
147 # In case of success, enable the feature.
148 # In case of failure, do not decide anything yet.
149 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
151 cat 1>&3 << __HEREDOC__
153 ${COMP} -o test-${1} test-${1}.c ${3}
156 if ${COMP} -o "test-${1}" "test-${1}.c" ${3} 1>&3 2>&3; then
157 echo "${1}${3}: ${CC} succeeded" 1>&3
159 echo "${1}${3}: ${CC} failed with $?" 1>&3
164 if .
/test-${1} 1>&3 2>&3; then
165 echo "${1}${3}: yes" 1>&2
166 echo "${1}${3}: yes" 1>&3
172 echo "${1}${3}: execution failed with $?" 1>&3
179 # Run a complete autoconfiguration test, including the check for
180 # a manual override and disabling the feature on failure.
181 # Arguments: lower case name, upper case name, additional CFLAGS
183 eval _manual
=\
${HAVE_${2}}
184 ismanual
"${1}" "${2}" "${_manual}" && return 0
185 singletest
"${1}" "${2}" "${3}" && return 0
186 echo "${1}${3}: no" 1>&2
191 # Select a UTF-8 locale.
193 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
194 ismanual UTF8_LOCALE UTF8_LOCALE
"$UTF8_LOCALE" && return 0
195 echo "UTF8_LOCALE: testing..." 1>&3
196 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
197 if [ -z "${UTF8_LOCALE}" ]; then
198 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
199 [ -n "${UTF8_LOCALE}" ] || return 1
201 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
202 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
208 # --- library functions ---
209 runtest dirent
-namlen DIRENT_NAMLEN
|| true
210 runtest be32toh ENDIAN
|| true
211 runtest be32toh SYS_ENDIAN
-DSYS_ENDIAN || true
212 runtest EFTYPE EFTYPE
|| true
213 runtest err ERR
|| true
214 runtest getline GETLINE
|| true
215 runtest getsubopt GETSUBOPT
|| true
216 runtest isblank ISBLANK
|| true
217 runtest mkdtemp MKDTEMP
|| true
218 runtest ntohl NTOHL
|| true
219 runtest PATH_MAX PATH_MAX
|| true
220 runtest pledge PLEDGE
|| true
221 runtest sandbox_init SANDBOX_INIT
|| true
222 runtest progname PROGNAME
|| true
223 runtest reallocarray REALLOCARRAY
|| true
224 runtest rewb
-bsd REWB_BSD
|| true
225 runtest rewb
-sysv REWB_SYSV
|| true
226 runtest strcasestr STRCASESTR
|| true
227 runtest stringlist STRINGLIST
|| true
228 runtest strlcat STRLCAT
|| true
229 runtest strlcpy STRLCPY
|| true
230 runtest strptime STRPTIME
|| true
231 runtest strsep STRSEP
|| true
232 runtest strtonum STRTONUM
|| true
233 runtest vasprintf VASPRINTF
|| true
235 if [ ${HAVE_ENDIAN} -eq 0 -a \
236 ${HAVE_SYS_ENDIAN} -eq 0 -a \
237 ${HAVE_NTOHL} -eq 0 ]; then
238 echo "FATAL: no endian conversion functions found" 1>&2
239 echo "FATAL: no endian conversion functions found" 1>&3
243 if ismanual fts FTS
${HAVE_FTS}; then
244 HAVE_FTS_COMPARE_CONST
=0
245 elif runtest fts FTS_COMPARE_CONST
-DFTS_COMPARE_CONST; then
248 runtest fts FTS
|| true
251 # --- wide character and locale support ---
253 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
256 echo "wchar: no (no UTF8_LOCALE)" 1>&2
257 echo "wchar: no (no UTF8_LOCALE)" 1>&3
261 if [ -n "${LD_NANOSLEEP}" ]; then
262 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
263 elif singletest nanosleep NANOSLEEP
; then
265 elif runtest nanosleep NANOSLEEP
"-lrt"; then
268 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
269 echo "FATAL: nanosleep: no" 1>&2
270 echo "FATAL: nanosleep: no" 1>&3
274 if [ ${BUILD_CATMAN} -gt 0 ]; then
276 if [ -n "${LD_RECVMSG}" ]; then
277 runtest recvmsg RECVMSG
"${LD_RECVMSG}" || true
278 elif singletest recvmsg RECVMSG
; then
280 elif runtest recvmsg RECVMSG
"-lsocket"; then
281 LD_RECVMSG
="-lsocket"
283 if [ "${HAVE_RECVMSG}" -eq 0 ]; then
284 echo "FATAL: recvmsg: no" 1>&2
285 echo "FATAL: recvmsg: no" 1>&3
286 echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
291 if singletest cmsg CMSG
; then
293 elif runtest cmsg CMSG
"-D_XPG4_2"; then
296 if [ "${HAVE_CMSG}" -eq 0 ]; then
297 echo "FATAL: cmsg: no" 1>&2
298 echo "FATAL: cmsg: no" 1>&3
299 echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
305 if ismanual ohash OHASH
"${HAVE_OHASH}"; then
307 elif [ -n "${LD_OHASH}" ]; then
308 runtest ohash OHASH
"${LD_OHASH}" || true
309 elif singletest ohash OHASH
; then
311 elif runtest ohash OHASH
"-lutil"; then
314 if [ "${HAVE_OHASH}" -eq 0 ]; then
319 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
320 echo "LDADD=\"${LDADD}\"" 1>&2
321 echo "LDADD=\"${LDADD}\"" 1>&3
324 # --- write config.h ---
330 #error "Do not use C++. See the INSTALL file."
333 #if !defined(__GNUC__) || (__GNUC__ < 4)
334 #define __attribute__(x)
337 #if defined(__linux__) || defined(__MINT__)
338 #define _GNU_SOURCE /* See test-*.c what needs this. */
343 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
344 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
345 && echo "#include <sys/types.h>"
346 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
347 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
350 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
351 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
352 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
353 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
354 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
355 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
356 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
357 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
358 echo "#define be32toh ntohl"
359 echo "#define htobe32 htonl"
363 #define HAVE_CMSG_XPG42 ${HAVE_CMSG_XPG42}
364 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
365 #define HAVE_ENDIAN ${HAVE_ENDIAN}
366 #define HAVE_ERR ${HAVE_ERR}
367 #define HAVE_FTS ${HAVE_FTS}
368 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
369 #define HAVE_GETLINE ${HAVE_GETLINE}
370 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
371 #define HAVE_ISBLANK ${HAVE_ISBLANK}
372 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
373 #define HAVE_NTOHL ${HAVE_NTOHL}
374 #define HAVE_PLEDGE ${HAVE_PLEDGE}
375 #define HAVE_PROGNAME ${HAVE_PROGNAME}
376 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
377 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
378 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
379 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
380 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
381 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
382 #define HAVE_STRLCAT ${HAVE_STRLCAT}
383 #define HAVE_STRLCPY ${HAVE_STRLCPY}
384 #define HAVE_STRPTIME ${HAVE_STRPTIME}
385 #define HAVE_STRSEP ${HAVE_STRSEP}
386 #define HAVE_STRTONUM ${HAVE_STRTONUM}
387 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
388 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
389 #define HAVE_WCHAR ${HAVE_WCHAR}
390 #define HAVE_OHASH ${HAVE_OHASH}
392 #define BINM_APROPOS "${BINM_APROPOS}"
393 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
394 #define BINM_MAN "${BINM_MAN}"
395 #define BINM_SOELIM "${BINM_SOELIM}"
396 #define BINM_WHATIS "${BINM_WHATIS}"
400 if [ ${HAVE_ERR} -eq 0 ]; then
401 echo "extern void err(int, const char *, ...);"
402 echo "extern void errx(int, const char *, ...);"
403 echo "extern void warn(const char *, ...);"
404 echo "extern void warnx(const char *, ...);"
407 [ ${HAVE_GETLINE} -eq 0 ] && \
408 echo "extern ssize_t getline(char **, size_t *, FILE *);"
410 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
411 echo "extern int getsubopt(char **, char * const *, char **);"
413 [ ${HAVE_ISBLANK} -eq 0 ] && \
414 echo "extern int isblank(int);"
416 [ ${HAVE_MKDTEMP} -eq 0 ] && \
417 echo "extern char *mkdtemp(char *);"
419 if [ ${HAVE_PROGNAME} -eq 0 ]; then
420 echo "extern const char *getprogname(void);"
421 echo "extern void setprogname(const char *);"
424 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
425 echo "extern void *reallocarray(void *, size_t, size_t);"
427 [ ${HAVE_STRCASESTR} -eq 0 ] && \
428 echo "extern char *strcasestr(const char *, const char *);"
430 [ ${HAVE_STRLCAT} -eq 0 ] && \
431 echo "extern size_t strlcat(char *, const char *, size_t);"
433 [ ${HAVE_STRLCPY} -eq 0 ] && \
434 echo "extern size_t strlcpy(char *, const char *, size_t);"
436 [ ${HAVE_STRSEP} -eq 0 ] && \
437 echo "extern char *strsep(char **, const char *);"
439 [ ${HAVE_STRTONUM} -eq 0 ] && \
440 echo "extern long long strtonum(const char *, long long, long long, const char **);"
442 [ ${HAVE_VASPRINTF} -eq 0 ] && \
443 echo "extern int vasprintf(char **, const char *, va_list);"
445 echo "config.h: written" 1>&2
446 echo "config.h: written" 1>&3
448 # --- tests for Makefile.local -----------------------------------------
450 exec > Makefile.
local
452 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
453 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
454 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
455 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
456 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
458 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
459 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
461 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
462 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
463 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
464 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
467 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="man.cgi"
468 [ ${BUILD_CATMAN} -gt 0 ] && \
469 BUILD_TARGETS
="${BUILD_TARGETS} mandocd catman"
471 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS
="lib-install"
472 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
473 [ ${BUILD_CATMAN} -gt 0 ] && \
474 INSTALL_TARGETS
="${INSTALL_TARGETS} catman-install"
477 BUILD_TARGETS = ${BUILD_TARGETS}
478 INSTALL_TARGETS = ${INSTALL_TARGETS}
487 INCLUDEDIR = ${INCLUDEDIR}
490 WWWPREFIX = ${WWWPREFIX}
491 HTDOCDIR = ${HTDOCDIR}
492 CGIBINDIR = ${CGIBINDIR}
493 BINM_APROPOS = ${BINM_APROPOS}
494 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
495 BINM_MAN = ${BINM_MAN}
496 BINM_SOELIM = ${BINM_SOELIM}
497 BINM_WHATIS = ${BINM_WHATIS}
498 MANM_MAN = ${MANM_MAN}
499 MANM_MANCONF = ${MANM_MANCONF}
500 MANM_MDOC = ${MANM_MDOC}
501 MANM_ROFF = ${MANM_ROFF}
502 MANM_EQN = ${MANM_EQN}
503 MANM_TBL = ${MANM_TBL}
505 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
506 INSTALL_LIB = ${INSTALL_LIB}
507 INSTALL_MAN = ${INSTALL_MAN}
508 INSTALL_DATA = ${INSTALL_DATA}
511 echo "Makefile.local: written" 1>&2
512 echo "Makefile.local: written" 1>&3