3 # $Id: configure,v 1.49 2016/08/02 11:09:46 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 -f -`
41 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
42 CFLAGS
="${CFLAGS} -Wno-unused-parameter"
90 BINM_APROPOS
="apropos"
91 BINM_MAKEWHATIS
="makewhatis"
96 MANM_MANCONF
="man.conf"
108 # --- manual settings from configure.local -----------------------------
110 if [ -r .
/configure.
local ]; then
111 echo "configure.local: reading..." 1>&2
112 echo "configure.local: reading..." 1>&3
113 cat .
/configure.
local 1>&3
116 echo "configure.local: no (fully automatic configuration)" 1>&2
117 echo "configure.local: no (fully automatic configuration)" 1>&3
121 # --- tests for config.h ----------------------------------------------
123 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
125 # Check whether this HAVE_ setting is manually overridden.
126 # If yes, use the override, if no, do not decide anything yet.
127 # Arguments: lower-case test name, manual value
129 [ -z "${2}" ] && return 1
130 echo "${1}: manual (${2})" 1>&2
131 echo "${1}: manual (${2})" 1>&3
136 # Run a single autoconfiguration test.
137 # In case of success, enable the feature.
138 # In case of failure, do not decide anything yet.
139 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
141 cat 1>&3 << __HEREDOC__
143 ${COMP} ${3} -o test-${1} test-${1}.c
146 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
147 echo "${1}: ${CC} succeeded" 1>&3
149 echo "${1}: ${CC} failed with $?" 1>&3
154 if .
/test-${1} 1>&3 2>&3; then
155 echo "${1}: yes" 1>&2
156 echo "${1}: yes" 1>&3
162 echo "${1}: execution failed with $?" 1>&3
169 # Run a complete autoconfiguration test, including the check for
170 # a manual override and disabling the feature on failure.
171 # Arguments: lower case name, upper case name, additional CFLAGS
173 eval _manual
=\
${HAVE_${2}}
174 ismanual
"${1}" "${_manual}" && return 0
175 singletest
"${1}" "${2}" "${3}" && return 0
181 # Select a UTF-8 locale.
183 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
184 ismanual UTF8_LOCALE
"$UTF8_LOCALE" && return 0
185 echo "UTF8_LOCALE: testing..." 1>&3
186 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
187 if [ -z "${UTF8_LOCALE}" ]; then
188 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
189 [ -n "${UTF8_LOCALE}" ] || return 1
191 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
192 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
198 # --- library functions ---
199 runtest dirent
-namlen DIRENT_NAMLEN
|| true
200 runtest EFTYPE EFTYPE
|| true
201 runtest err ERR
|| true
202 runtest fts FTS
|| true
203 runtest getline GETLINE
|| true
204 runtest getsubopt GETSUBOPT
|| true
205 runtest isblank ISBLANK
|| true
206 runtest mkdtemp MKDTEMP
|| true
207 runtest PATH_MAX PATH_MAX
|| true
208 runtest pledge PLEDGE
|| true
209 runtest sandbox_init SANDBOX_INIT
|| true
210 runtest progname PROGNAME
|| true
211 runtest reallocarray REALLOCARRAY
|| true
212 runtest rewb
-bsd REWB_BSD
|| true
213 runtest rewb
-sysv REWB_SYSV
|| true
214 runtest strcasestr STRCASESTR
|| true
215 runtest stringlist STRINGLIST
|| true
216 runtest strlcat STRLCAT
|| true
217 runtest strlcpy STRLCPY
|| true
218 runtest strptime STRPTIME
|| true
219 runtest strsep STRSEP
|| true
220 runtest strtonum STRTONUM
|| true
221 runtest vasprintf VASPRINTF
|| true
223 # --- wide character and locale support ---
225 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
228 echo "wchar: no (no UTF8_LOCALE)" 1>&2
229 echo "wchar: no (no UTF8_LOCALE)" 1>&3
233 if [ -n "${LD_NANOSLEEP}" ]; then
234 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
235 elif singletest nanosleep NANOSLEEP
; then
237 elif runtest nanosleep NANOSLEEP
"-lrt"; then
240 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
241 echo "FATAL: nanosleep: no" 1>&2
242 echo "FATAL: nanosleep: no" 1>&3
247 if ismanual ohash
"${HAVE_OHASH}"; then
249 elif [ -n "${LD_OHASH}" ]; then
250 runtest ohash OHASH
"${LD_OHASH}" || true
251 elif singletest ohash OHASH
; then
253 elif runtest ohash OHASH
"-lutil"; then
256 if [ "${HAVE_OHASH}" -eq 0 ]; then
261 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
262 echo "LDADD=\"${LDADD}\"" 1>&2
263 echo "LDADD=\"${LDADD}\"" 1>&3
266 # --- write config.h ---
272 #error "Do not use C++. See the INSTALL file."
275 #if !defined(__GNUC__) || (__GNUC__ < 4)
276 #define __attribute__(x)
279 #if defined(__linux__) || defined(__MINT__)
280 #define _GNU_SOURCE /* See test-*.c what needs this. */
285 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
286 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
287 && echo "#include <sys/types.h>"
288 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
289 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
292 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
293 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
294 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
295 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
296 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
297 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
298 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
301 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
302 #define HAVE_ERR ${HAVE_ERR}
303 #define HAVE_FTS ${HAVE_FTS}
304 #define HAVE_GETLINE ${HAVE_GETLINE}
305 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
306 #define HAVE_ISBLANK ${HAVE_ISBLANK}
307 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
308 #define HAVE_PLEDGE ${HAVE_PLEDGE}
309 #define HAVE_PROGNAME ${HAVE_PROGNAME}
310 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
311 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
312 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
313 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
314 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
315 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
316 #define HAVE_STRLCAT ${HAVE_STRLCAT}
317 #define HAVE_STRLCPY ${HAVE_STRLCPY}
318 #define HAVE_STRPTIME ${HAVE_STRPTIME}
319 #define HAVE_STRSEP ${HAVE_STRSEP}
320 #define HAVE_STRTONUM ${HAVE_STRTONUM}
321 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
322 #define HAVE_WCHAR ${HAVE_WCHAR}
323 #define HAVE_OHASH ${HAVE_OHASH}
325 #define BINM_APROPOS "${BINM_APROPOS}"
326 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
327 #define BINM_MAN "${BINM_MAN}"
328 #define BINM_SOELIM "${BINM_SOELIM}"
329 #define BINM_WHATIS "${BINM_WHATIS}"
333 if [ ${HAVE_ERR} -eq 0 ]; then
334 echo "extern void err(int, const char *, ...);"
335 echo "extern void errx(int, const char *, ...);"
336 echo "extern void warn(const char *, ...);"
337 echo "extern void warnx(const char *, ...);"
340 [ ${HAVE_GETLINE} -eq 0 ] && \
341 echo "extern ssize_t getline(char **, size_t *, FILE *);"
343 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
344 echo "extern int getsubopt(char **, char * const *, char **);"
346 [ ${HAVE_ISBLANK} -eq 0 ] && \
347 echo "extern int isblank(int);"
349 [ ${HAVE_MKDTEMP} -eq 0 ] && \
350 echo "extern char *mkdtemp(char *);"
352 if [ ${HAVE_PROGNAME} -eq 0 ]; then
353 echo "extern const char *getprogname(void);"
354 echo "extern void setprogname(const char *);"
357 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
358 echo "extern void *reallocarray(void *, size_t, size_t);"
360 [ ${HAVE_STRCASESTR} -eq 0 ] && \
361 echo "extern char *strcasestr(const char *, const char *);"
363 [ ${HAVE_STRLCAT} -eq 0 ] && \
364 echo "extern size_t strlcat(char *, const char *, size_t);"
366 [ ${HAVE_STRLCPY} -eq 0 ] && \
367 echo "extern size_t strlcpy(char *, const char *, size_t);"
369 [ ${HAVE_STRSEP} -eq 0 ] && \
370 echo "extern char *strsep(char **, const char *);"
372 [ ${HAVE_STRTONUM} -eq 0 ] && \
373 echo "extern long long strtonum(const char *, long long, long long, const char **);"
375 [ ${HAVE_VASPRINTF} -eq 0 ] && \
376 echo "extern int vasprintf(char **, const char *, va_list);"
378 echo "config.h: written" 1>&2
379 echo "config.h: written" 1>&3
381 # --- tests for Makefile.local -----------------------------------------
383 exec > Makefile.
local
385 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
386 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
387 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
388 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
389 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
391 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
392 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
394 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
395 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
396 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
397 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
400 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="cgi-build"
402 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="cgi-install"
405 BUILD_TARGETS = ${BUILD_TARGETS}
406 INSTALL_TARGETS = ${INSTALL_TARGETS}
415 INCLUDEDIR = ${INCLUDEDIR}
418 WWWPREFIX = ${WWWPREFIX}
419 HTDOCDIR = ${HTDOCDIR}
420 CGIBINDIR = ${CGIBINDIR}
421 BINM_APROPOS = ${BINM_APROPOS}
422 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
423 BINM_MAN = ${BINM_MAN}
424 BINM_SOELIM = ${BINM_SOELIM}
425 BINM_WHATIS = ${BINM_WHATIS}
426 MANM_MAN = ${MANM_MAN}
427 MANM_MANCONF = ${MANM_MANCONF}
428 MANM_MDOC = ${MANM_MDOC}
429 MANM_ROFF = ${MANM_ROFF}
430 MANM_EQN = ${MANM_EQN}
431 MANM_TBL = ${MANM_TBL}
433 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
434 INSTALL_LIB = ${INSTALL_LIB}
435 INSTALL_MAN = ${INSTALL_MAN}
436 INSTALL_DATA = ${INSTALL_DATA}
439 echo "Makefile.local: written" 1>&2
440 echo "Makefile.local: written" 1>&3