3 # Copyright (c) 2014, 2015 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 [ -e config.log
] && mv config.log config.log.old
20 [ -e 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" | make -f -`
38 CFLAGS
="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
80 BINM_APROPOS
="apropos"
83 BINM_MAKEWHATIS
="makewhatis"
85 MANM_MANCONF
="man.conf"
97 # --- manual settings from configure.local -----------------------------
99 if [ -e .
/configure.
local ]; then
100 echo "configure.local: reading..." 1>&2
101 echo "configure.local: reading..." 1>&3
102 cat .
/configure.
local 1>&3
105 echo "configure.local: no (fully automatic configuration)" 1>&2
106 echo "configure.local: no (fully automatic configuration)" 1>&3
110 # --- tests for config.h ----------------------------------------------
112 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
114 # Check whether this HAVE_ setting is manually overridden.
115 # If yes, use the override, if no, do not decide anything yet.
116 # Arguments: lower-case test name, manual value
118 [ -z "${2}" ] && return 1
119 echo "${1}: manual (${2})" 1>&2
120 echo "${1}: manual (${2})" 1>&3
125 # Run a single autoconfiguration test.
126 # In case of success, enable the feature.
127 # In case of failure, do not decide anything yet.
128 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
130 cat 1>&3 << __HEREDOC__
132 ${COMP} ${3} -o test-${1} test-${1}.c
135 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
136 echo "${1}: ${CC} succeeded" 1>&3
138 echo "${1}: ${CC} failed with $?" 1>&3
143 if .
/test-${1} 1>&3 2>&3; then
144 echo "${1}: yes" 1>&2
145 echo "${1}: yes" 1>&3
151 echo "${1}: execution failed with $?" 1>&3
158 # Run a complete autoconfiguration test, including the check for
159 # a manual override and disabling the feature on failure.
160 # Arguments: lower case name, upper case name, additional CFLAGS
162 eval _manual
=\
${HAVE_${2}}
163 ismanual
"${1}" "${_manual}" && return 0
164 singletest
"${1}" "${2}" "${3}" && return 0
170 # --- library functions ---
171 runtest dirent
-namlen DIRENT_NAMLEN
|| true
172 runtest fgetln FGETLN
|| true
173 runtest fts FTS
|| true
174 runtest getsubopt GETSUBOPT
|| true
175 runtest isblank ISBLANK
|| true
176 runtest mkdtemp MKDTEMP
|| true
177 runtest mmap MMAP
|| true
178 runtest reallocarray REALLOCARRAY
|| true
179 runtest strcasestr STRCASESTR
|| true
180 runtest strlcat STRLCAT
|| true
181 runtest strlcpy STRLCPY
|| true
182 runtest strptime STRPTIME
|| true
183 runtest strsep STRSEP
|| true
184 runtest strtonum STRTONUM
|| true
185 runtest vasprintf VASPRINTF
|| true
186 runtest wchar WCHAR
|| true
190 if [ ${BUILD_DB} -eq 0 ]; then
191 echo "BUILD_DB=0 (manual)" 1>&2
192 echo "BUILD_DB=0 (manual)" 1>&3
195 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
196 DETECTLIB
="-lsqlite3"
197 elif [ -n "${DBLIB}" ]; then
198 runtest sqlite3 SQLITE3
"${DBLIB}" || true
199 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
200 DETECTLIB
="-lsqlite3"
201 elif runtest sqlite3 SQLITE3 \
202 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
203 DETECTLIB
="-L/usr/local/lib -lsqlite3"
204 CFLAGS
="${CFLAGS} -I/usr/local/include"
206 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
207 echo "BUILD_DB=0 (no sqlite3)" 1>&2
208 echo "BUILD_DB=0 (no sqlite3)" 1>&3
213 # --- sqlite3_errstr ---
214 if [ ${BUILD_DB} -eq 0 ]; then
215 HAVE_SQLITE3_ERRSTR
=1
216 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
218 elif [ -n "${DBLIB}" ]; then
219 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DBLIB}" || true
221 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DETECTLIB}" || true
225 if [ ${BUILD_DB} -eq 0 ]; then
227 elif ismanual ohash
"${HAVE_OHASH}"; then
229 elif [ -n "${DBLIB}" ]; then
230 runtest ohash OHASH
"${DBLIB}" || true
231 elif singletest ohash OHASH
; then
233 elif runtest ohash OHASH
"-lutil"; then
234 DETECTLIB
="${DETECTLIB} -lutil"
238 if [ ${BUILD_DB} -eq 0 ]; then
240 elif [ -z "${DBLIB}" ]; then
242 echo "DBLIB=\"${DBLIB}\"" 1>&2
243 echo "DBLIB=\"${DBLIB}\"" 1>&3
248 if ismanual manpath
"${HAVE_MANPATH}"; then
250 elif manpath
1>&3 2>&3; then
251 echo "manpath: yes" 1>&2
252 echo "manpath: yes" 1>&3
256 echo "manpath: no" 1>&2
257 echo "manpath: no" 1>&3
262 # --- write config.h ---
267 #ifndef MANDOC_CONFIG_H
268 #define MANDOC_CONFIG_H
270 #if defined(__linux__) || defined(__MINT__)
271 #define _GNU_SOURCE /* See test-*.c what needs this. */
276 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
277 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
278 && echo "#include <sys/types.h>"
279 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
280 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
283 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
284 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
285 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
286 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
289 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
290 #define HAVE_FGETLN ${HAVE_FGETLN}
291 #define HAVE_FTS ${HAVE_FTS}
292 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
293 #define HAVE_ISBLANK ${HAVE_ISBLANK}
294 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
295 #define HAVE_MMAP ${HAVE_MMAP}
296 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
297 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
298 #define HAVE_STRLCAT ${HAVE_STRLCAT}
299 #define HAVE_STRLCPY ${HAVE_STRLCPY}
300 #define HAVE_STRPTIME ${HAVE_STRPTIME}
301 #define HAVE_STRSEP ${HAVE_STRSEP}
302 #define HAVE_STRTONUM ${HAVE_STRTONUM}
303 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
304 #define HAVE_WCHAR ${HAVE_WCHAR}
305 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
306 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
307 #define HAVE_OHASH ${HAVE_OHASH}
308 #define HAVE_MANPATH ${HAVE_MANPATH}
310 #define BINM_APROPOS "${BINM_APROPOS}"
311 #define BINM_MAN "${BINM_MAN}"
312 #define BINM_WHATIS "${BINM_WHATIS}"
313 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
315 #if !defined(__BEGIN_DECLS)
317 # define __BEGIN_DECLS extern "C" {
319 # define __BEGIN_DECLS
322 #if !defined(__END_DECLS)
324 # define __END_DECLS }
332 [ ${HAVE_FGETLN} -eq 0 ] && \
333 echo "extern char *fgetln(FILE *, size_t *);"
335 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
336 echo "extern int getsubopt(char **, char * const *, char **);"
338 [ ${HAVE_ISBLANK} -eq 0 ] && \
339 echo "extern int isblank(int);"
341 [ ${HAVE_MKDTEMP} -eq 0 ] && \
342 echo "extern char *mkdtemp(char *);"
344 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
345 echo "extern void *reallocarray(void *, size_t, size_t);"
347 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
348 echo "extern const char *sqlite3_errstr(int);"
350 [ ${HAVE_STRCASESTR} -eq 0 ] && \
351 echo "extern char *strcasestr(const char *, const char *);"
353 [ ${HAVE_STRLCAT} -eq 0 ] && \
354 echo "extern size_t strlcat(char *, const char *, size_t);"
356 [ ${HAVE_STRLCPY} -eq 0 ] && \
357 echo "extern size_t strlcpy(char *, const char *, size_t);"
359 [ ${HAVE_STRSEP} -eq 0 ] && \
360 echo "extern char *strsep(char **, const char *);"
362 [ ${HAVE_STRTONUM} -eq 0 ] && \
363 echo "extern long long strtonum(const char *, long long, long long, const char **);"
365 [ ${HAVE_VASPRINTF} -eq 0 ] && \
366 echo "extern int vasprintf(char **, const char *, va_list);"
369 echo "#endif /* MANDOC_CONFIG_H */"
371 echo "config.h: written" 1>&2
372 echo "config.h: written" 1>&3
374 # --- tests for Makefile.local -----------------------------------------
376 exec > Makefile.
local
378 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
379 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
380 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
381 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
382 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
383 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR
="${PREFIX}/share/examples/mandoc"
385 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
386 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
388 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
389 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
390 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
391 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
393 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
394 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
395 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
399 BUILD_TARGETS
="base-build"
400 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
401 INSTALL_TARGETS
="base-install"
402 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
403 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
406 BUILD_TARGETS = ${BUILD_TARGETS}
407 INSTALL_TARGETS = ${INSTALL_TARGETS}
415 INCLUDEDIR = ${INCLUDEDIR}
418 EXAMPLEDIR = ${EXAMPLEDIR}
419 WWWPREFIX = ${WWWPREFIX}
420 HTDOCDIR = ${HTDOCDIR}
421 CGIBINDIR = ${CGIBINDIR}
422 BINM_APROPOS = ${BINM_APROPOS}
423 BINM_MAN = ${BINM_MAN}
424 BINM_WHATIS = ${BINM_WHATIS}
425 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
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 [ ${BUILD_DB} -gt 0 ] && \
440 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
442 echo "Makefile.local: written" 1>&2
443 echo "Makefile.local: written" 1>&3