3 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 [ -w config.log
] && mv config.log config.log.old
20 [ -w config.h
] && mv config.h config.h.old
22 # Output file descriptor usage:
23 # 1 (stdout): config.h, Makefile.local
24 # 2 (stderr): original stderr, usually to the console
28 echo "config.log: writing..."
30 # --- default settings -------------------------------------------------
31 # Initialize all variables here,
32 # such that nothing can leak in from the environment.
34 MANPATH_DEFAULT
="/usr/share/man:/usr/X11R6/man:/usr/local/man"
37 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -f -`
38 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
39 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 # --- library functions ---
182 runtest dirent
-namlen DIRENT_NAMLEN
|| true
183 runtest err ERR
|| true
184 runtest fts FTS
|| true
185 runtest getline GETLINE
|| true
186 runtest getsubopt GETSUBOPT
|| true
187 runtest isblank ISBLANK
|| true
188 runtest mkdtemp MKDTEMP
|| true
189 runtest mmap MMAP
|| true
190 runtest pledge PLEDGE
|| true
191 runtest sandbox_init SANDBOX_INIT
|| true
192 runtest progname PROGNAME
|| true
193 runtest reallocarray REALLOCARRAY
|| true
194 runtest rewb
-bsd REWB_BSD
|| true
195 runtest rewb
-sysv REWB_SYSV
|| true
196 runtest strcasestr STRCASESTR
|| true
197 runtest stringlist STRINGLIST
|| true
198 runtest strlcat STRLCAT
|| true
199 runtest strlcpy STRLCPY
|| true
200 runtest strptime STRPTIME
|| true
201 runtest strsep STRSEP
|| true
202 runtest strtonum STRTONUM
|| true
203 runtest vasprintf VASPRINTF
|| true
204 runtest wchar WCHAR
|| true
207 if [ ${BUILD_DB} -eq 0 ]; then
208 echo "BUILD_DB=0 (manual)" 1>&2
209 echo "BUILD_DB=0 (manual)" 1>&3
212 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
213 if [ -z "${LD_SQLITE3}" ]; then
214 LD_SQLITE3
="-lsqlite3"
216 elif [ -n "${LD_SQLITE3}" ]; then
217 runtest sqlite3 SQLITE3
"${LD_SQLITE3}" || true
218 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
219 LD_SQLITE3
="-lsqlite3"
220 elif runtest sqlite3 SQLITE3 \
221 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
222 LD_SQLITE3
="-L/usr/local/lib -lsqlite3"
223 CFLAGS
="${CFLAGS} -I/usr/local/include"
225 if [ ${HAVE_SQLITE3} -eq 0 ]; then
227 if [ ${BUILD_DB} -gt 0 ]; then
228 echo "BUILD_DB=0 (no sqlite3)" 1>&2
229 echo "BUILD_DB=0 (no sqlite3)" 1>&3
235 # --- sqlite3_errstr ---
236 if [ ${BUILD_DB} -eq 0 ]; then
237 HAVE_SQLITE3_ERRSTR
=1
238 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
241 runtest sqlite3_errstr SQLITE3_ERRSTR
"${LD_SQLITE3}" || true
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_SQLITE3} ${LD_OHASH} -lz"
260 echo "LDADD=\"${LDADD}\"" 1>&2
261 echo "LDADD=\"${LDADD}\"" 1>&3
265 if ismanual manpath
"${HAVE_MANPATH}"; then
267 elif manpath
1>&3 2>&3; then
268 echo "manpath: yes" 1>&2
269 echo "manpath: yes" 1>&3
273 echo "manpath: no" 1>&2
274 echo "manpath: no" 1>&3
279 # --- write config.h ---
285 #error "Do not use C++. See the INSTALL file."
288 #if !defined(__GNUC__) || (__GNUC__ < 4)
289 #define __attribute__(x)
292 #if defined(__linux__) || defined(__MINT__)
293 #define _GNU_SOURCE /* See test-*.c what needs this. */
298 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
299 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
300 && echo "#include <sys/types.h>"
301 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
302 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
305 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
306 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
307 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
308 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
311 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
312 #define HAVE_ERR ${HAVE_ERR}
313 #define HAVE_FTS ${HAVE_FTS}
314 #define HAVE_GETLINE ${HAVE_GETLINE}
315 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
316 #define HAVE_ISBLANK ${HAVE_ISBLANK}
317 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
318 #define HAVE_MMAP ${HAVE_MMAP}
319 #define HAVE_PLEDGE ${HAVE_PLEDGE}
320 #define HAVE_PROGNAME ${HAVE_PROGNAME}
321 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
322 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
323 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
324 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
325 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
326 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
327 #define HAVE_STRLCAT ${HAVE_STRLCAT}
328 #define HAVE_STRLCPY ${HAVE_STRLCPY}
329 #define HAVE_STRPTIME ${HAVE_STRPTIME}
330 #define HAVE_STRSEP ${HAVE_STRSEP}
331 #define HAVE_STRTONUM ${HAVE_STRTONUM}
332 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
333 #define HAVE_WCHAR ${HAVE_WCHAR}
334 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
335 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
336 #define HAVE_OHASH ${HAVE_OHASH}
337 #define HAVE_MANPATH ${HAVE_MANPATH}
339 #define BINM_APROPOS "${BINM_APROPOS}"
340 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
341 #define BINM_MAN "${BINM_MAN}"
342 #define BINM_SOELIM "${BINM_SOELIM}"
343 #define BINM_WHATIS "${BINM_WHATIS}"
347 if [ ${HAVE_ERR} -eq 0 ]; then
348 echo "extern void err(int, const char *, ...);"
349 echo "extern void errx(int, const char *, ...);"
350 echo "extern void warn(const char *, ...);"
351 echo "extern void warnx(const char *, ...);"
354 [ ${HAVE_GETLINE} -eq 0 ] && \
355 echo "extern ssize_t getline(char **, size_t *, FILE *);"
357 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
358 echo "extern int getsubopt(char **, char * const *, char **);"
360 [ ${HAVE_ISBLANK} -eq 0 ] && \
361 echo "extern int isblank(int);"
363 [ ${HAVE_MKDTEMP} -eq 0 ] && \
364 echo "extern char *mkdtemp(char *);"
366 if [ ${HAVE_PROGNAME} -eq 0 ]; then
367 echo "extern const char *getprogname(void);"
368 echo "extern void setprogname(const char *);"
371 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
372 echo "extern void *reallocarray(void *, size_t, size_t);"
374 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
375 echo "extern const char *sqlite3_errstr(int);"
377 [ ${HAVE_STRCASESTR} -eq 0 ] && \
378 echo "extern char *strcasestr(const char *, const char *);"
380 [ ${HAVE_STRLCAT} -eq 0 ] && \
381 echo "extern size_t strlcat(char *, const char *, size_t);"
383 [ ${HAVE_STRLCPY} -eq 0 ] && \
384 echo "extern size_t strlcpy(char *, const char *, size_t);"
386 [ ${HAVE_STRSEP} -eq 0 ] && \
387 echo "extern char *strsep(char **, const char *);"
389 [ ${HAVE_STRTONUM} -eq 0 ] && \
390 echo "extern long long strtonum(const char *, long long, long long, const char **);"
392 [ ${HAVE_VASPRINTF} -eq 0 ] && \
393 echo "extern int vasprintf(char **, const char *, va_list);"
395 echo "config.h: written" 1>&2
396 echo "config.h: written" 1>&3
398 # --- tests for Makefile.local -----------------------------------------
400 exec > Makefile.
local
402 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
403 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
404 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
405 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
406 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
408 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
409 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
411 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
412 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
413 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
414 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
416 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
417 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
418 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
422 BUILD_TARGETS
="base-build"
423 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
424 INSTALL_TARGETS
="base-install"
425 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
426 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
429 BUILD_TARGETS = ${BUILD_TARGETS}
430 INSTALL_TARGETS = ${INSTALL_TARGETS}
439 INCLUDEDIR = ${INCLUDEDIR}
442 WWWPREFIX = ${WWWPREFIX}
443 HTDOCDIR = ${HTDOCDIR}
444 CGIBINDIR = ${CGIBINDIR}
445 BINM_APROPOS = ${BINM_APROPOS}
446 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
447 BINM_MAN = ${BINM_MAN}
448 BINM_SOELIM = ${BINM_SOELIM}
449 BINM_WHATIS = ${BINM_WHATIS}
450 MANM_MAN = ${MANM_MAN}
451 MANM_MANCONF = ${MANM_MANCONF}
452 MANM_MDOC = ${MANM_MDOC}
453 MANM_ROFF = ${MANM_ROFF}
454 MANM_EQN = ${MANM_EQN}
455 MANM_TBL = ${MANM_TBL}
457 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
458 INSTALL_LIB = ${INSTALL_LIB}
459 INSTALL_MAN = ${INSTALL_MAN}
460 INSTALL_DATA = ${INSTALL_DATA}
463 [ ${BUILD_DB} -gt 0 ] && \
464 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
466 echo "Makefile.local: written" 1>&2
467 echo "Makefile.local: written" 1>&3