3 # $Id: configure,v 1.47 2016/07/20 14:03:06 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"
39 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -f -`
40 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
41 CFLAGS
="${CFLAGS} -Wno-unused-parameter"
88 BINM_APROPOS
="apropos"
89 BINM_MAKEWHATIS
="makewhatis"
94 MANM_MANCONF
="man.conf"
106 # --- manual settings from configure.local -----------------------------
108 if [ -r .
/configure.
local ]; then
109 echo "configure.local: reading..." 1>&2
110 echo "configure.local: reading..." 1>&3
111 cat .
/configure.
local 1>&3
114 echo "configure.local: no (fully automatic configuration)" 1>&2
115 echo "configure.local: no (fully automatic configuration)" 1>&3
119 # --- tests for config.h ----------------------------------------------
121 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
123 # Check whether this HAVE_ setting is manually overridden.
124 # If yes, use the override, if no, do not decide anything yet.
125 # Arguments: lower-case test name, manual value
127 [ -z "${2}" ] && return 1
128 echo "${1}: manual (${2})" 1>&2
129 echo "${1}: manual (${2})" 1>&3
134 # Run a single autoconfiguration test.
135 # In case of success, enable the feature.
136 # In case of failure, do not decide anything yet.
137 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
139 cat 1>&3 << __HEREDOC__
141 ${COMP} ${3} -o test-${1} test-${1}.c
144 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
145 echo "${1}: ${CC} succeeded" 1>&3
147 echo "${1}: ${CC} failed with $?" 1>&3
152 if .
/test-${1} 1>&3 2>&3; then
153 echo "${1}: yes" 1>&2
154 echo "${1}: yes" 1>&3
160 echo "${1}: execution failed with $?" 1>&3
167 # Run a complete autoconfiguration test, including the check for
168 # a manual override and disabling the feature on failure.
169 # Arguments: lower case name, upper case name, additional CFLAGS
171 eval _manual
=\
${HAVE_${2}}
172 ismanual
"${1}" "${_manual}" && return 0
173 singletest
"${1}" "${2}" "${3}" && return 0
179 # --- library functions ---
180 runtest dirent
-namlen DIRENT_NAMLEN
|| true
181 runtest EFTYPE EFTYPE
|| true
182 runtest err ERR
|| true
183 runtest fts FTS
|| true
184 runtest getline GETLINE
|| true
185 runtest getsubopt GETSUBOPT
|| true
186 runtest isblank ISBLANK
|| true
187 runtest mkdtemp MKDTEMP
|| true
188 runtest pledge PLEDGE
|| true
189 runtest sandbox_init SANDBOX_INIT
|| true
190 runtest progname PROGNAME
|| true
191 runtest reallocarray REALLOCARRAY
|| true
192 runtest rewb
-bsd REWB_BSD
|| true
193 runtest rewb
-sysv REWB_SYSV
|| true
194 runtest strcasestr STRCASESTR
|| true
195 runtest stringlist STRINGLIST
|| true
196 runtest strlcat STRLCAT
|| true
197 runtest strlcpy STRLCPY
|| true
198 runtest strptime STRPTIME
|| true
199 runtest strsep STRSEP
|| true
200 runtest strtonum STRTONUM
|| true
201 runtest vasprintf VASPRINTF
|| true
202 runtest wchar WCHAR
|| true
205 if [ -n "${LD_NANOSLEEP}" ]; then
206 runtest nanosleep NANOSLEEP
"${LD_NANOSLEEP}" || true
207 elif singletest nanosleep NANOSLEEP
; then
209 elif runtest nanosleep NANOSLEEP
"-lrt"; then
212 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
213 echo "FATAL: nanosleep: no" 1>&2
214 echo "FATAL: nanosleep: no" 1>&3
219 if ismanual ohash
"${HAVE_OHASH}"; then
221 elif [ -n "${LD_OHASH}" ]; then
222 runtest ohash OHASH
"${LD_OHASH}" || true
223 elif singletest ohash OHASH
; then
225 elif runtest ohash OHASH
"-lutil"; then
228 if [ "${HAVE_OHASH}" -eq 0 ]; then
233 LDADD
="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
234 echo "LDADD=\"${LDADD}\"" 1>&2
235 echo "LDADD=\"${LDADD}\"" 1>&3
238 # --- write config.h ---
244 #error "Do not use C++. See the INSTALL file."
247 #if !defined(__GNUC__) || (__GNUC__ < 4)
248 #define __attribute__(x)
251 #if defined(__linux__) || defined(__MINT__)
252 #define _GNU_SOURCE /* See test-*.c what needs this. */
257 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
258 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
259 && echo "#include <sys/types.h>"
260 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
261 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
264 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
265 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
266 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
267 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
268 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
271 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
272 #define HAVE_ERR ${HAVE_ERR}
273 #define HAVE_FTS ${HAVE_FTS}
274 #define HAVE_GETLINE ${HAVE_GETLINE}
275 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
276 #define HAVE_ISBLANK ${HAVE_ISBLANK}
277 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
278 #define HAVE_PLEDGE ${HAVE_PLEDGE}
279 #define HAVE_PROGNAME ${HAVE_PROGNAME}
280 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
281 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
282 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
283 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
284 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
285 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
286 #define HAVE_STRLCAT ${HAVE_STRLCAT}
287 #define HAVE_STRLCPY ${HAVE_STRLCPY}
288 #define HAVE_STRPTIME ${HAVE_STRPTIME}
289 #define HAVE_STRSEP ${HAVE_STRSEP}
290 #define HAVE_STRTONUM ${HAVE_STRTONUM}
291 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
292 #define HAVE_WCHAR ${HAVE_WCHAR}
293 #define HAVE_OHASH ${HAVE_OHASH}
295 #define BINM_APROPOS "${BINM_APROPOS}"
296 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
297 #define BINM_MAN "${BINM_MAN}"
298 #define BINM_SOELIM "${BINM_SOELIM}"
299 #define BINM_WHATIS "${BINM_WHATIS}"
303 if [ ${HAVE_ERR} -eq 0 ]; then
304 echo "extern void err(int, const char *, ...);"
305 echo "extern void errx(int, const char *, ...);"
306 echo "extern void warn(const char *, ...);"
307 echo "extern void warnx(const char *, ...);"
310 [ ${HAVE_GETLINE} -eq 0 ] && \
311 echo "extern ssize_t getline(char **, size_t *, FILE *);"
313 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
314 echo "extern int getsubopt(char **, char * const *, char **);"
316 [ ${HAVE_ISBLANK} -eq 0 ] && \
317 echo "extern int isblank(int);"
319 [ ${HAVE_MKDTEMP} -eq 0 ] && \
320 echo "extern char *mkdtemp(char *);"
322 if [ ${HAVE_PROGNAME} -eq 0 ]; then
323 echo "extern const char *getprogname(void);"
324 echo "extern void setprogname(const char *);"
327 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
328 echo "extern void *reallocarray(void *, size_t, size_t);"
330 [ ${HAVE_STRCASESTR} -eq 0 ] && \
331 echo "extern char *strcasestr(const char *, const char *);"
333 [ ${HAVE_STRLCAT} -eq 0 ] && \
334 echo "extern size_t strlcat(char *, const char *, size_t);"
336 [ ${HAVE_STRLCPY} -eq 0 ] && \
337 echo "extern size_t strlcpy(char *, const char *, size_t);"
339 [ ${HAVE_STRSEP} -eq 0 ] && \
340 echo "extern char *strsep(char **, const char *);"
342 [ ${HAVE_STRTONUM} -eq 0 ] && \
343 echo "extern long long strtonum(const char *, long long, long long, const char **);"
345 [ ${HAVE_VASPRINTF} -eq 0 ] && \
346 echo "extern int vasprintf(char **, const char *, va_list);"
348 echo "config.h: written" 1>&2
349 echo "config.h: written" 1>&3
351 # --- tests for Makefile.local -----------------------------------------
353 exec > Makefile.
local
355 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
356 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
357 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
358 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
359 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
361 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
362 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
364 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
365 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
366 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
367 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
370 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="cgi-build"
372 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="cgi-install"
375 BUILD_TARGETS = ${BUILD_TARGETS}
376 INSTALL_TARGETS = ${INSTALL_TARGETS}
385 INCLUDEDIR = ${INCLUDEDIR}
388 WWWPREFIX = ${WWWPREFIX}
389 HTDOCDIR = ${HTDOCDIR}
390 CGIBINDIR = ${CGIBINDIR}
391 BINM_APROPOS = ${BINM_APROPOS}
392 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
393 BINM_MAN = ${BINM_MAN}
394 BINM_SOELIM = ${BINM_SOELIM}
395 BINM_WHATIS = ${BINM_WHATIS}
396 MANM_MAN = ${MANM_MAN}
397 MANM_MANCONF = ${MANM_MANCONF}
398 MANM_MDOC = ${MANM_MDOC}
399 MANM_ROFF = ${MANM_ROFF}
400 MANM_EQN = ${MANM_EQN}
401 MANM_TBL = ${MANM_TBL}
403 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
404 INSTALL_LIB = ${INSTALL_LIB}
405 INSTALL_MAN = ${INSTALL_MAN}
406 INSTALL_DATA = ${INSTALL_DATA}
409 echo "Makefile.local: written" 1>&2
410 echo "Makefile.local: written" 1>&3