3 # Copyright (c) 2014 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"
84 # --- manual settings from configure.local -----------------------------
86 if [ -e .
/configure.
local ]; then
87 echo "configure.local: reading..." 1>&2
88 echo "configure.local: reading..." 1>&3
89 cat .
/configure.
local 1>&3
92 echo "configure.local: no (fully automatic configuration)" 1>&2
93 echo "configure.local: no (fully automatic configuration)" 1>&3
97 # --- tests for config.h ----------------------------------------------
99 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
101 # Check whether this HAVE_ setting is manually overridden.
102 # If yes, use the override, if no, do not decide anything yet.
103 # Arguments: lower-case test name, manual value
105 [ -z "${2}" ] && return 1
106 echo "${1}: manual (${2})" 1>&2
107 echo "${1}: manual (${2})" 1>&3
112 # Run a single autoconfiguration test.
113 # In case of success, enable the feature.
114 # In case of failure, do not decide anything yet.
115 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
117 cat 1>&3 << __HEREDOC__
119 ${COMP} ${3} -o test-${1} test-${1}.c
122 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
123 echo "${1}: ${CC} succeeded" 1>&3
125 echo "${1}: ${CC} failed with $?" 1>&3
130 if .
/test-${1} 1>&3 2>&3; then
131 echo "${1}: yes" 1>&2
132 echo "${1}: yes" 1>&3
138 echo "${1}: execution failed with $?" 1>&3
145 # Run a complete autoconfiguration test, including the check for
146 # a manual override and disabling the feature on failure.
147 # Arguments: lower case name, upper case name, additional CFLAGS
149 eval _manual
=\
${HAVE_${2}}
150 ismanual
"${1}" "${_manual}" && return 0
151 singletest
"${1}" "${2}" "${3}" && return 0
157 # --- library functions ---
158 runtest dirent
-namlen DIRENT_NAMLEN
|| true
159 runtest fgetln FGETLN
|| true
160 runtest fts FTS
|| true
161 runtest getsubopt GETSUBOPT
|| true
162 runtest mmap MMAP
|| true
163 runtest reallocarray REALLOCARRAY
|| true
164 runtest strcasestr STRCASESTR
|| true
165 runtest strlcat STRLCAT
|| true
166 runtest strlcpy STRLCPY
|| true
167 runtest strptime STRPTIME
|| true
168 runtest strsep STRSEP
|| true
169 runtest wchar WCHAR
|| true
173 if [ ${BUILD_DB} -eq 0 ]; then
174 echo "BUILD_DB=0 (manual)" 1>&2
175 echo "BUILD_DB=0 (manual)" 1>&3
178 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
179 DETECTLIB
="-lsqlite3"
180 elif [ -n "${DBLIB}" ]; then
181 runtest sqlite3 SQLITE3
"${DBLIB}" || true
182 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
183 DETECTLIB
="-lsqlite3"
184 elif runtest sqlite3 SQLITE3 \
185 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
186 DETECTLIB
="-L/usr/local/lib -lsqlite3"
187 CFLAGS
="${CFLAGS} -I/usr/local/include"
189 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
190 echo "BUILD_DB=0 (no sqlite3)" 1>&2
191 echo "BUILD_DB=0 (no sqlite3)" 1>&3
196 # --- sqlite3_errstr ---
197 if [ ${BUILD_DB} -eq 0 ]; then
198 HAVE_SQLITE3_ERRSTR
=1
199 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
201 elif [ -n "${DBLIB}" ]; then
202 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DBLIB}" || true
204 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DETECTLIB}" || true
208 if [ ${BUILD_DB} -eq 0 ]; then
210 elif ismanual ohash
"${HAVE_OHASH}"; then
212 elif [ -n "${DBLIB}" ]; then
213 runtest ohash OHASH
"${DBLIB}" || true
214 elif singletest ohash OHASH
; then
216 elif runtest ohash OHASH
"-lutil"; then
217 DETECTLIB
="${DETECTLIB} -lutil"
221 if [ ${BUILD_DB} -eq 0 ]; then
223 elif [ -z "${DBLIB}" ]; then
225 echo "DBLIB=\"${DBLIB}\"" 1>&2
226 echo "DBLIB=\"${DBLIB}\"" 1>&3
231 if [ ${BUILD_DB} -eq 0 ]; then
233 elif ismanual manpath
"${HAVE_MANPATH}"; then
235 elif manpath
1>&3 2>&3; then
236 echo "manpath: yes" 1>&2
237 echo "manpath: yes" 1>&3
241 echo "manpath: no" 1>&2
242 echo "manpath: no" 1>&3
247 # --- write config.h ---
252 #ifndef MANDOC_CONFIG_H
253 #define MANDOC_CONFIG_H
255 #if defined(__linux__) || defined(__MINT__)
256 #define _GNU_SOURCE /* getsubopt(), strcasestr(), strptime() */
261 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
262 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
263 && echo "#include <sys/types.h>"
264 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
267 echo "#define VERSION \"${VERSION}\""
268 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
271 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
272 #define HAVE_FGETLN ${HAVE_FGETLN}
273 #define HAVE_FTS ${HAVE_FTS}
274 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
275 #define HAVE_MMAP ${HAVE_MMAP}
276 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
277 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
278 #define HAVE_STRLCAT ${HAVE_STRLCAT}
279 #define HAVE_STRLCPY ${HAVE_STRLCPY}
280 #define HAVE_STRPTIME ${HAVE_STRPTIME}
281 #define HAVE_STRSEP ${HAVE_STRSEP}
282 #define HAVE_WCHAR ${HAVE_WCHAR}
283 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
284 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
285 #define HAVE_OHASH ${HAVE_OHASH}
286 #define HAVE_MANPATH ${HAVE_MANPATH}
288 #if !defined(__BEGIN_DECLS)
290 # define __BEGIN_DECLS extern "C" {
292 # define __BEGIN_DECLS
295 #if !defined(__END_DECLS)
297 # define __END_DECLS }
305 [ ${HAVE_FGETLN} -eq 0 ] && \
306 echo "extern char *fgetln(FILE *, size_t *);"
308 if [ ${HAVE_GETSUBOPT} -eq 0 ]; then
309 echo "extern int getsubopt(char **, char * const *, char **);"
310 echo "extern char *suboptarg;"
313 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
314 echo "extern void *reallocarray(void *, size_t, size_t);"
316 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
317 echo "extern const char *sqlite3_errstr(int);"
319 [ ${HAVE_STRCASESTR} -eq 0 ] && \
320 echo "extern char *strcasestr(const char *, const char *);"
322 [ ${HAVE_STRLCAT} -eq 0 ] && \
323 echo "extern size_t strlcat(char *, const char *, size_t);"
325 [ ${HAVE_STRLCPY} -eq 0 ] && \
326 echo "extern size_t strlcpy(char *, const char *, size_t);"
328 [ ${HAVE_STRSEP} -eq 0 ] && \
329 echo "extern char *strsep(char **, const char *);"
332 echo "#endif /* MANDOC_CONFIG_H */"
334 echo "config.h: written" 1>&2
335 echo "config.h: written" 1>&3
337 # --- tests for Makefile.local -----------------------------------------
339 exec > Makefile.
local
341 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
342 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
343 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
344 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
345 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
346 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR
="${PREFIX}/share/examples/mandoc"
348 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
349 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
351 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
352 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
353 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
354 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
356 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
357 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
358 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
362 BUILD_TARGETS
="base-build"
363 [ ${BUILD_DB} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} db-build"
364 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
368 BUILD_TARGETS = ${BUILD_TARGETS}
375 INCLUDEDIR = ${INCLUDEDIR}
378 EXAMPLEDIR = ${EXAMPLEDIR}
379 WWWPREFIX = ${WWWPREFIX}
380 HTDOCDIR = ${HTDOCDIR}
381 CGIBINDIR = ${CGIBINDIR}
383 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
384 INSTALL_LIB = ${INSTALL_LIB}
385 INSTALL_MAN = ${INSTALL_MAN}
386 INSTALL_DATA = ${INSTALL_DATA}
389 [ ${BUILD_DB} -gt 0 ] && \
390 echo "MAN_OBJS = \$(MANDOC_OBJS) \$(APROPOS_OBJS)"
392 echo "Makefile.local: written" 1>&2
393 echo "Makefile.local: written" 1>&3