3 # $Id: configure,v 1.48 2016/07/31 09:29:13 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"
89 BINM_APROPOS
="apropos"
90 BINM_MAKEWHATIS
="makewhatis"
95 MANM_MANCONF
="man.conf"
107 # --- manual settings from configure.local -----------------------------
109 if [ -r .
/configure.
local ]; then
110 echo "configure.local: reading..." 1>&2
111 echo "configure.local: reading..." 1>&3
112 cat .
/configure.
local 1>&3
115 echo "configure.local: no (fully automatic configuration)" 1>&2
116 echo "configure.local: no (fully automatic configuration)" 1>&3
120 # --- tests for config.h ----------------------------------------------
122 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
124 # Check whether this HAVE_ setting is manually overridden.
125 # If yes, use the override, if no, do not decide anything yet.
126 # Arguments: lower-case test name, manual value
128 [ -z "${2}" ] && return 1
129 echo "${1}: manual (${2})" 1>&2
130 echo "${1}: manual (${2})" 1>&3
135 # Run a single autoconfiguration test.
136 # In case of success, enable the feature.
137 # In case of failure, do not decide anything yet.
138 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
140 cat 1>&3 << __HEREDOC__
142 ${COMP} ${3} -o test-${1} test-${1}.c
145 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
146 echo "${1}: ${CC} succeeded" 1>&3
148 echo "${1}: ${CC} failed with $?" 1>&3
153 if .
/test-${1} 1>&3 2>&3; then
154 echo "${1}: yes" 1>&2
155 echo "${1}: yes" 1>&3
161 echo "${1}: execution failed with $?" 1>&3
168 # Run a complete autoconfiguration test, including the check for
169 # a manual override and disabling the feature on failure.
170 # Arguments: lower case name, upper case name, additional CFLAGS
172 eval _manual
=\
${HAVE_${2}}
173 ismanual
"${1}" "${_manual}" && return 0
174 singletest
"${1}" "${2}" "${3}" && return 0
180 # Select a UTF-8 locale.
182 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
183 ismanual UTF8_LOCALE
"$UTF8_LOCALE" && return 0
184 echo "UTF8_LOCALE: testing..." 1>&3
185 UTF8_LOCALE
=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
186 if [ -z "${UTF8_LOCALE}" ]; then
187 UTF8_LOCALE
=`locale -a | grep -i '\.UTF-*8' | head -n 1`
188 [ -n "${UTF8_LOCALE}" ] || return 1
190 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
191 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
197 # --- library functions ---
198 runtest dirent
-namlen DIRENT_NAMLEN
|| true
199 runtest EFTYPE EFTYPE
|| true
200 runtest err ERR
|| true
201 runtest fts FTS
|| true
202 runtest getline GETLINE
|| true
203 runtest getsubopt GETSUBOPT
|| true
204 runtest isblank ISBLANK
|| true
205 runtest mkdtemp MKDTEMP
|| true
206 runtest pledge PLEDGE
|| true
207 runtest sandbox_init SANDBOX_INIT
|| true
208 runtest progname PROGNAME
|| true
209 runtest reallocarray REALLOCARRAY
|| true
210 runtest rewb
-bsd REWB_BSD
|| true
211 runtest rewb
-sysv REWB_SYSV
|| true
212 runtest strcasestr STRCASESTR
|| true
213 runtest stringlist STRINGLIST
|| true
214 runtest strlcat STRLCAT
|| true
215 runtest strlcpy STRLCPY
|| true
216 runtest strptime STRPTIME
|| true
217 runtest strsep STRSEP
|| true
218 runtest strtonum STRTONUM
|| true
219 runtest vasprintf VASPRINTF
|| true
221 # --- wide character and locale support ---
223 runtest wchar WCHAR
-DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
226 echo "wchar: no (no UTF8_LOCALE)" 1>&2
227 echo "wchar: no (no UTF8_LOCALE)" 1>&3
231 if [ -n "${LD_NANOSLEEP}" ]; then
232 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
233 elif singletest nanosleep NANOSLEEP
; then
235 elif runtest nanosleep NANOSLEEP
"-lrt"; then
238 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
239 echo "FATAL: nanosleep: no" 1>&2
240 echo "FATAL: nanosleep: no" 1>&3
245 if ismanual ohash
"${HAVE_OHASH}"; then
247 elif [ -n "${LD_OHASH}" ]; then
248 runtest ohash OHASH
"${LD_OHASH}" || true
249 elif singletest ohash OHASH
; then
251 elif runtest ohash OHASH
"-lutil"; then
254 if [ "${HAVE_OHASH}" -eq 0 ]; then
259 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
260 echo "LDADD=\"${LDADD}\"" 1>&2
261 echo "LDADD=\"${LDADD}\"" 1>&3
264 # --- write config.h ---
270 #error "Do not use C++. See the INSTALL file."
273 #if !defined(__GNUC__) || (__GNUC__ < 4)
274 #define __attribute__(x)
277 #if defined(__linux__) || defined(__MINT__)
278 #define _GNU_SOURCE /* See test-*.c what needs this. */
283 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
284 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
285 && echo "#include <sys/types.h>"
286 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
287 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
290 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
291 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
292 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
293 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
294 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
295 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
298 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
299 #define HAVE_ERR ${HAVE_ERR}
300 #define HAVE_FTS ${HAVE_FTS}
301 #define HAVE_GETLINE ${HAVE_GETLINE}
302 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
303 #define HAVE_ISBLANK ${HAVE_ISBLANK}
304 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
305 #define HAVE_PLEDGE ${HAVE_PLEDGE}
306 #define HAVE_PROGNAME ${HAVE_PROGNAME}
307 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
308 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
309 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
310 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
311 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
312 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
313 #define HAVE_STRLCAT ${HAVE_STRLCAT}
314 #define HAVE_STRLCPY ${HAVE_STRLCPY}
315 #define HAVE_STRPTIME ${HAVE_STRPTIME}
316 #define HAVE_STRSEP ${HAVE_STRSEP}
317 #define HAVE_STRTONUM ${HAVE_STRTONUM}
318 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
319 #define HAVE_WCHAR ${HAVE_WCHAR}
320 #define HAVE_OHASH ${HAVE_OHASH}
322 #define BINM_APROPOS "${BINM_APROPOS}"
323 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
324 #define BINM_MAN "${BINM_MAN}"
325 #define BINM_SOELIM "${BINM_SOELIM}"
326 #define BINM_WHATIS "${BINM_WHATIS}"
330 if [ ${HAVE_ERR} -eq 0 ]; then
331 echo "extern void err(int, const char *, ...);"
332 echo "extern void errx(int, const char *, ...);"
333 echo "extern void warn(const char *, ...);"
334 echo "extern void warnx(const char *, ...);"
337 [ ${HAVE_GETLINE} -eq 0 ] && \
338 echo "extern ssize_t getline(char **, size_t *, FILE *);"
340 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
341 echo "extern int getsubopt(char **, char * const *, char **);"
343 [ ${HAVE_ISBLANK} -eq 0 ] && \
344 echo "extern int isblank(int);"
346 [ ${HAVE_MKDTEMP} -eq 0 ] && \
347 echo "extern char *mkdtemp(char *);"
349 if [ ${HAVE_PROGNAME} -eq 0 ]; then
350 echo "extern const char *getprogname(void);"
351 echo "extern void setprogname(const char *);"
354 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
355 echo "extern void *reallocarray(void *, size_t, size_t);"
357 [ ${HAVE_STRCASESTR} -eq 0 ] && \
358 echo "extern char *strcasestr(const char *, const char *);"
360 [ ${HAVE_STRLCAT} -eq 0 ] && \
361 echo "extern size_t strlcat(char *, const char *, size_t);"
363 [ ${HAVE_STRLCPY} -eq 0 ] && \
364 echo "extern size_t strlcpy(char *, const char *, size_t);"
366 [ ${HAVE_STRSEP} -eq 0 ] && \
367 echo "extern char *strsep(char **, const char *);"
369 [ ${HAVE_STRTONUM} -eq 0 ] && \
370 echo "extern long long strtonum(const char *, long long, long long, const char **);"
372 [ ${HAVE_VASPRINTF} -eq 0 ] && \
373 echo "extern int vasprintf(char **, const char *, va_list);"
375 echo "config.h: written" 1>&2
376 echo "config.h: written" 1>&3
378 # --- tests for Makefile.local -----------------------------------------
380 exec > Makefile.
local
382 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
383 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
384 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
385 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
386 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
388 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
389 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
391 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
392 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
393 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
394 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
397 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="cgi-build"
399 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="cgi-install"
402 BUILD_TARGETS = ${BUILD_TARGETS}
403 INSTALL_TARGETS = ${INSTALL_TARGETS}
412 INCLUDEDIR = ${INCLUDEDIR}
415 WWWPREFIX = ${WWWPREFIX}
416 HTDOCDIR = ${HTDOCDIR}
417 CGIBINDIR = ${CGIBINDIR}
418 BINM_APROPOS = ${BINM_APROPOS}
419 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
420 BINM_MAN = ${BINM_MAN}
421 BINM_SOELIM = ${BINM_SOELIM}
422 BINM_WHATIS = ${BINM_WHATIS}
423 MANM_MAN = ${MANM_MAN}
424 MANM_MANCONF = ${MANM_MANCONF}
425 MANM_MDOC = ${MANM_MDOC}
426 MANM_ROFF = ${MANM_ROFF}
427 MANM_EQN = ${MANM_EQN}
428 MANM_TBL = ${MANM_TBL}
430 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
431 INSTALL_LIB = ${INSTALL_LIB}
432 INSTALL_MAN = ${INSTALL_MAN}
433 INSTALL_DATA = ${INSTALL_DATA}
436 echo "Makefile.local: written" 1>&2
437 echo "Makefile.local: written" 1>&3