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"
78 BINM_APROPOS
="apropos"
81 BINM_MAKEWHATIS
="makewhatis"
94 # --- manual settings from configure.local -----------------------------
96 if [ -e .
/configure.
local ]; then
97 echo "configure.local: reading..." 1>&2
98 echo "configure.local: reading..." 1>&3
99 cat .
/configure.
local 1>&3
102 echo "configure.local: no (fully automatic configuration)" 1>&2
103 echo "configure.local: no (fully automatic configuration)" 1>&3
107 # --- tests for config.h ----------------------------------------------
109 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
111 # Check whether this HAVE_ setting is manually overridden.
112 # If yes, use the override, if no, do not decide anything yet.
113 # Arguments: lower-case test name, manual value
115 [ -z "${2}" ] && return 1
116 echo "${1}: manual (${2})" 1>&2
117 echo "${1}: manual (${2})" 1>&3
122 # Run a single autoconfiguration test.
123 # In case of success, enable the feature.
124 # In case of failure, do not decide anything yet.
125 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
127 cat 1>&3 << __HEREDOC__
129 ${COMP} ${3} -o test-${1} test-${1}.c
132 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
133 echo "${1}: ${CC} succeeded" 1>&3
135 echo "${1}: ${CC} failed with $?" 1>&3
140 if .
/test-${1} 1>&3 2>&3; then
141 echo "${1}: yes" 1>&2
142 echo "${1}: yes" 1>&3
148 echo "${1}: execution failed with $?" 1>&3
155 # Run a complete autoconfiguration test, including the check for
156 # a manual override and disabling the feature on failure.
157 # Arguments: lower case name, upper case name, additional CFLAGS
159 eval _manual
=\
${HAVE_${2}}
160 ismanual
"${1}" "${_manual}" && return 0
161 singletest
"${1}" "${2}" "${3}" && return 0
167 # --- library functions ---
168 runtest dirent
-namlen DIRENT_NAMLEN
|| true
169 runtest fgetln FGETLN
|| true
170 runtest fts FTS
|| true
171 runtest getsubopt GETSUBOPT
|| true
172 runtest mmap MMAP
|| true
173 runtest reallocarray REALLOCARRAY
|| true
174 runtest strcasestr STRCASESTR
|| true
175 runtest strlcat STRLCAT
|| true
176 runtest strlcpy STRLCPY
|| true
177 runtest strptime STRPTIME
|| true
178 runtest strsep STRSEP
|| true
179 runtest wchar WCHAR
|| true
183 if [ ${BUILD_DB} -eq 0 ]; then
184 echo "BUILD_DB=0 (manual)" 1>&2
185 echo "BUILD_DB=0 (manual)" 1>&3
188 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
189 DETECTLIB
="-lsqlite3"
190 elif [ -n "${DBLIB}" ]; then
191 runtest sqlite3 SQLITE3
"${DBLIB}" || true
192 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
193 DETECTLIB
="-lsqlite3"
194 elif runtest sqlite3 SQLITE3 \
195 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
196 DETECTLIB
="-L/usr/local/lib -lsqlite3"
197 CFLAGS
="${CFLAGS} -I/usr/local/include"
199 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
200 echo "BUILD_DB=0 (no sqlite3)" 1>&2
201 echo "BUILD_DB=0 (no sqlite3)" 1>&3
206 # --- sqlite3_errstr ---
207 if [ ${BUILD_DB} -eq 0 ]; then
208 HAVE_SQLITE3_ERRSTR
=1
209 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
211 elif [ -n "${DBLIB}" ]; then
212 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DBLIB}" || true
214 runtest sqlite3_errstr SQLITE3_ERRSTR
"${DETECTLIB}" || true
218 if [ ${BUILD_DB} -eq 0 ]; then
220 elif ismanual ohash
"${HAVE_OHASH}"; then
222 elif [ -n "${DBLIB}" ]; then
223 runtest ohash OHASH
"${DBLIB}" || true
224 elif singletest ohash OHASH
; then
226 elif runtest ohash OHASH
"-lutil"; then
227 DETECTLIB
="${DETECTLIB} -lutil"
231 if [ ${BUILD_DB} -eq 0 ]; then
233 elif [ -z "${DBLIB}" ]; then
235 echo "DBLIB=\"${DBLIB}\"" 1>&2
236 echo "DBLIB=\"${DBLIB}\"" 1>&3
241 if [ ${BUILD_DB} -eq 0 ]; then
243 elif ismanual manpath
"${HAVE_MANPATH}"; then
245 elif manpath
1>&3 2>&3; then
246 echo "manpath: yes" 1>&2
247 echo "manpath: yes" 1>&3
251 echo "manpath: no" 1>&2
252 echo "manpath: no" 1>&3
257 # --- write config.h ---
262 #ifndef MANDOC_CONFIG_H
263 #define MANDOC_CONFIG_H
265 #if defined(__linux__) || defined(__MINT__)
266 #define _GNU_SOURCE /* See test-*.c what needs this. */
271 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
272 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
273 && echo "#include <sys/types.h>"
274 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
277 echo "#define VERSION \"${VERSION}\""
278 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
281 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
282 #define HAVE_FGETLN ${HAVE_FGETLN}
283 #define HAVE_FTS ${HAVE_FTS}
284 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
285 #define HAVE_MMAP ${HAVE_MMAP}
286 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
287 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
288 #define HAVE_STRLCAT ${HAVE_STRLCAT}
289 #define HAVE_STRLCPY ${HAVE_STRLCPY}
290 #define HAVE_STRPTIME ${HAVE_STRPTIME}
291 #define HAVE_STRSEP ${HAVE_STRSEP}
292 #define HAVE_WCHAR ${HAVE_WCHAR}
293 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
294 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
295 #define HAVE_OHASH ${HAVE_OHASH}
296 #define HAVE_MANPATH ${HAVE_MANPATH}
298 #define BINM_APROPOS "${BINM_APROPOS}"
299 #define BINM_MAN "${BINM_MAN}"
300 #define BINM_WHATIS "${BINM_WHATIS}"
301 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
303 #if !defined(__BEGIN_DECLS)
305 # define __BEGIN_DECLS extern "C" {
307 # define __BEGIN_DECLS
310 #if !defined(__END_DECLS)
312 # define __END_DECLS }
320 [ ${HAVE_FGETLN} -eq 0 ] && \
321 echo "extern char *fgetln(FILE *, size_t *);"
323 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
324 echo "extern int getsubopt(char **, char * const *, char **);"
326 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
327 echo "extern void *reallocarray(void *, size_t, size_t);"
329 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
330 echo "extern const char *sqlite3_errstr(int);"
332 [ ${HAVE_STRCASESTR} -eq 0 ] && \
333 echo "extern char *strcasestr(const char *, const char *);"
335 [ ${HAVE_STRLCAT} -eq 0 ] && \
336 echo "extern size_t strlcat(char *, const char *, size_t);"
338 [ ${HAVE_STRLCPY} -eq 0 ] && \
339 echo "extern size_t strlcpy(char *, const char *, size_t);"
341 [ ${HAVE_STRSEP} -eq 0 ] && \
342 echo "extern char *strsep(char **, const char *);"
345 echo "#endif /* MANDOC_CONFIG_H */"
347 echo "config.h: written" 1>&2
348 echo "config.h: written" 1>&3
350 # --- tests for Makefile.local -----------------------------------------
352 exec > Makefile.
local
354 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
355 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
356 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
357 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
358 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
359 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR
="${PREFIX}/share/examples/mandoc"
361 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
362 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
364 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
365 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
366 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
367 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
369 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
370 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
371 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
375 BUILD_TARGETS
="base-build"
376 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
377 INSTALL_TARGETS
="base-install"
378 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
379 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
383 BUILD_TARGETS = ${BUILD_TARGETS}
384 INSTALL_TARGETS = ${INSTALL_TARGETS}
391 INCLUDEDIR = ${INCLUDEDIR}
394 EXAMPLEDIR = ${EXAMPLEDIR}
395 WWWPREFIX = ${WWWPREFIX}
396 HTDOCDIR = ${HTDOCDIR}
397 CGIBINDIR = ${CGIBINDIR}
398 BINM_APROPOS = ${BINM_APROPOS}
399 BINM_MAN = ${BINM_MAN}
400 BINM_WHATIS = ${BINM_WHATIS}
401 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
402 MANM_MAN = ${MANM_MAN}
403 MANM_MDOC = ${MANM_MDOC}
404 MANM_ROFF = ${MANM_ROFF}
405 MANM_EQN = ${MANM_EQN}
406 MANM_TBL = ${MANM_TBL}
408 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
409 INSTALL_LIB = ${INSTALL_LIB}
410 INSTALL_MAN = ${INSTALL_MAN}
411 INSTALL_DATA = ${INSTALL_DATA}
414 [ ${BUILD_DB} -gt 0 ] && \
415 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
417 echo "Makefile.local: written" 1>&2
418 echo "Makefile.local: written" 1>&3