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.
36 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
37 CFLAGS
="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
76 BINM_APROPOS
="apropos"
79 BINM_MAKEWHATIS
="makewhatis"
92 # --- manual settings from configure.local -----------------------------
94 if [ -e .
/configure.
local ]; then
95 echo "configure.local: reading..." 1>&2
96 echo "configure.local: reading..." 1>&3
97 cat .
/configure.
local 1>&3
100 echo "configure.local: no (fully automatic configuration)" 1>&2
101 echo "configure.local: no (fully automatic configuration)" 1>&3
105 # --- tests for config.h ----------------------------------------------
107 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
109 # Check whether this HAVE_ setting is manually overridden.
110 # If yes, use the override, if no, do not decide anything yet.
111 # Arguments: lower-case test name, manual value
113 [ -z "${2}" ] && return 1
114 echo "${1}: manual (${2})" 1>&2
115 echo "${1}: manual (${2})" 1>&3
120 # Run a single autoconfiguration test.
121 # In case of success, enable the feature.
122 # In case of failure, do not decide anything yet.
123 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
125 cat 1>&3 << __HEREDOC__
127 ${COMP} ${3} -o test-${1} test-${1}.c
130 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
131 echo "${1}: ${CC} succeeded" 1>&3
133 echo "${1}: ${CC} failed with $?" 1>&3
138 if .
/test-${1} 1>&3 2>&3; then
139 echo "${1}: yes" 1>&2
140 echo "${1}: yes" 1>&3
146 echo "${1}: execution failed with $?" 1>&3
153 # Run a complete autoconfiguration test, including the check for
154 # a manual override and disabling the feature on failure.
155 # Arguments: lower case name, upper case name, additional CFLAGS
157 eval _manual
=\
${HAVE_${2}}
158 ismanual
"${1}" "${_manual}" && return 0
159 singletest
"${1}" "${2}" "${3}" && return 0
165 # --- library functions ---
166 runtest dirent
-namlen DIRENT_NAMLEN
|| true
167 runtest fgetln FGETLN
|| true
168 runtest fts FTS
|| true
169 runtest getsubopt GETSUBOPT
|| true
170 runtest mmap MMAP
|| true
171 runtest reallocarray REALLOCARRAY
|| true
172 runtest strcasestr STRCASESTR
|| true
173 runtest strlcat STRLCAT
|| true
174 runtest strlcpy STRLCPY
|| true
175 runtest strptime STRPTIME
|| true
176 runtest strsep STRSEP
|| true
177 runtest strtonum STRTONUM
|| true
178 runtest wchar WCHAR
|| true
182 if [ ${BUILD_DB} -eq 0 ]; then
183 echo "BUILD_DB=0 (manual)" 1>&2
184 echo "BUILD_DB=0 (manual)" 1>&3
187 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
188 DETECTLIB
="-lsqlite3"
189 elif [ -n "${DBLIB}" ]; then
190 runtest sqlite3 SQLITE3
"${DBLIB}" || true
191 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
192 DETECTLIB
="-lsqlite3"
193 elif runtest sqlite3 SQLITE3 \
194 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
195 DETECTLIB
="-L/usr/local/lib -lsqlite3"
196 CFLAGS
="${CFLAGS} -I/usr/local/include"
198 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
199 echo "BUILD_DB=0 (no sqlite3)" 1>&2
200 echo "BUILD_DB=0 (no sqlite3)" 1>&3
205 # --- sqlite3_errstr ---
206 if [ ${BUILD_DB} -eq 0 ]; then
207 HAVE_SQLITE3_ERRSTR
=1
208 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
210 elif [ -n "${DBLIB}" ]; then
211 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DBLIB}" || true
213 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DETECTLIB}" || true
217 if [ ${BUILD_DB} -eq 0 ]; then
219 elif ismanual ohash
"${HAVE_OHASH}"; then
221 elif [ -n "${DBLIB}" ]; then
222 runtest ohash OHASH
"${DBLIB}" || true
223 elif singletest ohash OHASH
; then
225 elif runtest ohash OHASH
"-lutil"; then
226 DETECTLIB
="${DETECTLIB} -lutil"
230 if [ ${BUILD_DB} -eq 0 ]; then
232 elif [ -z "${DBLIB}" ]; then
234 echo "DBLIB=\"${DBLIB}\"" 1>&2
235 echo "DBLIB=\"${DBLIB}\"" 1>&3
240 if ismanual manpath
"${HAVE_MANPATH}"; then
242 elif manpath
1>&3 2>&3; then
243 echo "manpath: yes" 1>&2
244 echo "manpath: yes" 1>&3
248 echo "manpath: no" 1>&2
249 echo "manpath: no" 1>&3
254 # --- write config.h ---
259 #ifndef MANDOC_CONFIG_H
260 #define MANDOC_CONFIG_H
262 #if defined(__linux__) || defined(__MINT__)
263 #define _GNU_SOURCE /* See test-*.c what needs this. */
268 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
269 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
270 && echo "#include <sys/types.h>"
271 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
274 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
275 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
278 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
279 #define HAVE_FGETLN ${HAVE_FGETLN}
280 #define HAVE_FTS ${HAVE_FTS}
281 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
282 #define HAVE_MMAP ${HAVE_MMAP}
283 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
284 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
285 #define HAVE_STRLCAT ${HAVE_STRLCAT}
286 #define HAVE_STRLCPY ${HAVE_STRLCPY}
287 #define HAVE_STRPTIME ${HAVE_STRPTIME}
288 #define HAVE_STRSEP ${HAVE_STRSEP}
289 #define HAVE_STRTONUM ${HAVE_STRTONUM}
290 #define HAVE_WCHAR ${HAVE_WCHAR}
291 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
292 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
293 #define HAVE_OHASH ${HAVE_OHASH}
294 #define HAVE_MANPATH ${HAVE_MANPATH}
296 #define BINM_APROPOS "${BINM_APROPOS}"
297 #define BINM_MAN "${BINM_MAN}"
298 #define BINM_WHATIS "${BINM_WHATIS}"
299 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
301 #if !defined(__BEGIN_DECLS)
303 # define __BEGIN_DECLS extern "C" {
305 # define __BEGIN_DECLS
308 #if !defined(__END_DECLS)
310 # define __END_DECLS }
318 [ ${HAVE_FGETLN} -eq 0 ] && \
319 echo "extern char *fgetln(FILE *, size_t *);"
321 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
322 echo "extern int getsubopt(char **, char * const *, char **);"
324 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
325 echo "extern void *reallocarray(void *, size_t, size_t);"
327 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
328 echo "extern const char *sqlite3_errstr(int);"
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 **);"
346 echo "#endif /* MANDOC_CONFIG_H */"
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"
360 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR
="${PREFIX}/share/examples/mandoc"
362 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
363 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
365 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
366 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
367 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
368 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
370 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
371 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
372 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
376 BUILD_TARGETS
="base-build"
377 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
378 INSTALL_TARGETS
="base-install"
379 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
380 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
383 BUILD_TARGETS = ${BUILD_TARGETS}
384 INSTALL_TARGETS = ${INSTALL_TARGETS}
392 INCLUDEDIR = ${INCLUDEDIR}
395 EXAMPLEDIR = ${EXAMPLEDIR}
396 WWWPREFIX = ${WWWPREFIX}
397 HTDOCDIR = ${HTDOCDIR}
398 CGIBINDIR = ${CGIBINDIR}
399 BINM_APROPOS = ${BINM_APROPOS}
400 BINM_MAN = ${BINM_MAN}
401 BINM_WHATIS = ${BINM_WHATIS}
402 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
403 MANM_MAN = ${MANM_MAN}
404 MANM_MDOC = ${MANM_MDOC}
405 MANM_ROFF = ${MANM_ROFF}
406 MANM_EQN = ${MANM_EQN}
407 MANM_TBL = ${MANM_TBL}
409 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
410 INSTALL_LIB = ${INSTALL_LIB}
411 INSTALL_MAN = ${INSTALL_MAN}
412 INSTALL_DATA = ${INSTALL_DATA}
415 [ ${BUILD_DB} -gt 0 ] && \
416 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
418 echo "Makefile.local: written" 1>&2
419 echo "Makefile.local: written" 1>&3