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.
35 echo "VERSION=\"${VERSION}\"" 1>&2
36 echo "VERSION=\"${VERSION}\"" 1>&3
40 CC
=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
41 CFLAGS
="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
79 BINM_APROPOS
="apropos"
82 BINM_MAKEWHATIS
="makewhatis"
95 # --- manual settings from configure.local -----------------------------
97 if [ -e .
/configure.
local ]; then
98 echo "configure.local: reading..." 1>&2
99 echo "configure.local: reading..." 1>&3
100 cat .
/configure.
local 1>&3
103 echo "configure.local: no (fully automatic configuration)" 1>&2
104 echo "configure.local: no (fully automatic configuration)" 1>&3
108 # --- tests for config.h ----------------------------------------------
110 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
112 # Check whether this HAVE_ setting is manually overridden.
113 # If yes, use the override, if no, do not decide anything yet.
114 # Arguments: lower-case test name, manual value
116 [ -z "${2}" ] && return 1
117 echo "${1}: manual (${2})" 1>&2
118 echo "${1}: manual (${2})" 1>&3
123 # Run a single autoconfiguration test.
124 # In case of success, enable the feature.
125 # In case of failure, do not decide anything yet.
126 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
128 cat 1>&3 << __HEREDOC__
130 ${COMP} ${3} -o test-${1} test-${1}.c
133 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
134 echo "${1}: ${CC} succeeded" 1>&3
136 echo "${1}: ${CC} failed with $?" 1>&3
141 if .
/test-${1} 1>&3 2>&3; then
142 echo "${1}: yes" 1>&2
143 echo "${1}: yes" 1>&3
149 echo "${1}: execution failed with $?" 1>&3
156 # Run a complete autoconfiguration test, including the check for
157 # a manual override and disabling the feature on failure.
158 # Arguments: lower case name, upper case name, additional CFLAGS
160 eval _manual
=\
${HAVE_${2}}
161 ismanual
"${1}" "${_manual}" && return 0
162 singletest
"${1}" "${2}" "${3}" && return 0
168 # --- library functions ---
169 runtest dirent
-namlen DIRENT_NAMLEN
|| true
170 runtest fgetln FGETLN
|| true
171 runtest fts FTS
|| true
172 runtest getsubopt GETSUBOPT
|| true
173 runtest mmap MMAP
|| true
174 runtest reallocarray REALLOCARRAY
|| true
175 runtest strcasestr STRCASESTR
|| true
176 runtest strlcat STRLCAT
|| true
177 runtest strlcpy STRLCPY
|| true
178 runtest strptime STRPTIME
|| true
179 runtest strsep STRSEP
|| true
180 runtest wchar WCHAR
|| true
184 if [ ${BUILD_DB} -eq 0 ]; then
185 echo "BUILD_DB=0 (manual)" 1>&2
186 echo "BUILD_DB=0 (manual)" 1>&3
189 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
190 DETECTLIB
="-lsqlite3"
191 elif [ -n "${DBLIB}" ]; then
192 runtest sqlite3 SQLITE3
"${DBLIB}" || true
193 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
194 DETECTLIB
="-lsqlite3"
195 elif runtest sqlite3 SQLITE3 \
196 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
197 DETECTLIB
="-L/usr/local/lib -lsqlite3"
198 CFLAGS
="${CFLAGS} -I/usr/local/include"
200 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
201 echo "BUILD_DB=0 (no sqlite3)" 1>&2
202 echo "BUILD_DB=0 (no sqlite3)" 1>&3
207 # --- sqlite3_errstr ---
208 if [ ${BUILD_DB} -eq 0 ]; then
209 HAVE_SQLITE3_ERRSTR
=1
210 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
212 elif [ -n "${DBLIB}" ]; then
213 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DBLIB}" || true
215 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DETECTLIB}" || true
219 if [ ${BUILD_DB} -eq 0 ]; then
221 elif ismanual ohash
"${HAVE_OHASH}"; then
223 elif [ -n "${DBLIB}" ]; then
224 runtest ohash OHASH
"${DBLIB}" || true
225 elif singletest ohash OHASH
; then
227 elif runtest ohash OHASH
"-lutil"; then
228 DETECTLIB
="${DETECTLIB} -lutil"
232 if [ ${BUILD_DB} -eq 0 ]; then
234 elif [ -z "${DBLIB}" ]; then
236 echo "DBLIB=\"${DBLIB}\"" 1>&2
237 echo "DBLIB=\"${DBLIB}\"" 1>&3
242 if [ ${BUILD_DB} -eq 0 ]; then
244 elif ismanual manpath
"${HAVE_MANPATH}"; then
246 elif manpath
1>&3 2>&3; then
247 echo "manpath: yes" 1>&2
248 echo "manpath: yes" 1>&3
252 echo "manpath: no" 1>&2
253 echo "manpath: no" 1>&3
258 # --- write config.h ---
263 #ifndef MANDOC_CONFIG_H
264 #define MANDOC_CONFIG_H
266 #if defined(__linux__) || defined(__MINT__)
267 #define _GNU_SOURCE /* See test-*.c what needs this. */
272 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
273 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
274 && echo "#include <sys/types.h>"
275 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
278 echo "#define VERSION \"${VERSION}\""
279 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
280 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
283 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
284 #define HAVE_FGETLN ${HAVE_FGETLN}
285 #define HAVE_FTS ${HAVE_FTS}
286 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
287 #define HAVE_MMAP ${HAVE_MMAP}
288 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
289 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
290 #define HAVE_STRLCAT ${HAVE_STRLCAT}
291 #define HAVE_STRLCPY ${HAVE_STRLCPY}
292 #define HAVE_STRPTIME ${HAVE_STRPTIME}
293 #define HAVE_STRSEP ${HAVE_STRSEP}
294 #define HAVE_WCHAR ${HAVE_WCHAR}
295 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
296 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
297 #define HAVE_OHASH ${HAVE_OHASH}
298 #define HAVE_MANPATH ${HAVE_MANPATH}
300 #define BINM_APROPOS "${BINM_APROPOS}"
301 #define BINM_MAN "${BINM_MAN}"
302 #define BINM_WHATIS "${BINM_WHATIS}"
303 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
305 #if !defined(__BEGIN_DECLS)
307 # define __BEGIN_DECLS extern "C" {
309 # define __BEGIN_DECLS
312 #if !defined(__END_DECLS)
314 # define __END_DECLS }
322 [ ${HAVE_FGETLN} -eq 0 ] && \
323 echo "extern char *fgetln(FILE *, size_t *);"
325 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
326 echo "extern int getsubopt(char **, char * const *, char **);"
328 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
329 echo "extern void *reallocarray(void *, size_t, size_t);"
331 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
332 echo "extern const char *sqlite3_errstr(int);"
334 [ ${HAVE_STRCASESTR} -eq 0 ] && \
335 echo "extern char *strcasestr(const char *, const char *);"
337 [ ${HAVE_STRLCAT} -eq 0 ] && \
338 echo "extern size_t strlcat(char *, const char *, size_t);"
340 [ ${HAVE_STRLCPY} -eq 0 ] && \
341 echo "extern size_t strlcpy(char *, const char *, size_t);"
343 [ ${HAVE_STRSEP} -eq 0 ] && \
344 echo "extern char *strsep(char **, const char *);"
347 echo "#endif /* MANDOC_CONFIG_H */"
349 echo "config.h: written" 1>&2
350 echo "config.h: written" 1>&3
352 # --- tests for Makefile.local -----------------------------------------
354 exec > Makefile.
local
356 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
357 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
358 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
359 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
360 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
361 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR
="${PREFIX}/share/examples/mandoc"
363 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
364 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
366 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
367 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
368 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
369 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
371 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
372 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
373 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
377 BUILD_TARGETS
="base-build"
378 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
379 INSTALL_TARGETS
="base-install"
380 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
381 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
385 BUILD_TARGETS = ${BUILD_TARGETS}
386 INSTALL_TARGETS = ${INSTALL_TARGETS}
393 INCLUDEDIR = ${INCLUDEDIR}
396 EXAMPLEDIR = ${EXAMPLEDIR}
397 WWWPREFIX = ${WWWPREFIX}
398 HTDOCDIR = ${HTDOCDIR}
399 CGIBINDIR = ${CGIBINDIR}
400 BINM_APROPOS = ${BINM_APROPOS}
401 BINM_MAN = ${BINM_MAN}
402 BINM_WHATIS = ${BINM_WHATIS}
403 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
404 MANM_MAN = ${MANM_MAN}
405 MANM_MDOC = ${MANM_MDOC}
406 MANM_ROFF = ${MANM_ROFF}
407 MANM_EQN = ${MANM_EQN}
408 MANM_TBL = ${MANM_TBL}
410 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
411 INSTALL_LIB = ${INSTALL_LIB}
412 INSTALL_MAN = ${INSTALL_MAN}
413 INSTALL_DATA = ${INSTALL_DATA}
416 [ ${BUILD_DB} -gt 0 ] && \
417 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
419 echo "Makefile.local: written" 1>&2
420 echo "Makefile.local: written" 1>&3