3 # Copyright (c) 2014, 2015, 2016 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 [ -w config.log
] && mv config.log config.log.old
20 [ -w 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"
87 BINM_APROPOS
="apropos"
88 BINM_MAKEWHATIS
="makewhatis"
93 MANM_MANCONF
="man.conf"
105 # --- manual settings from configure.local -----------------------------
107 if [ -r .
/configure.
local ]; then
108 echo "configure.local: reading..." 1>&2
109 echo "configure.local: reading..." 1>&3
110 cat .
/configure.
local 1>&3
113 echo "configure.local: no (fully automatic configuration)" 1>&2
114 echo "configure.local: no (fully automatic configuration)" 1>&3
118 # --- tests for config.h ----------------------------------------------
120 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
122 # Check whether this HAVE_ setting is manually overridden.
123 # If yes, use the override, if no, do not decide anything yet.
124 # Arguments: lower-case test name, manual value
126 [ -z "${2}" ] && return 1
127 echo "${1}: manual (${2})" 1>&2
128 echo "${1}: manual (${2})" 1>&3
133 # Run a single autoconfiguration test.
134 # In case of success, enable the feature.
135 # In case of failure, do not decide anything yet.
136 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
138 cat 1>&3 << __HEREDOC__
140 ${COMP} ${3} -o test-${1} test-${1}.c
143 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
144 echo "${1}: ${CC} succeeded" 1>&3
146 echo "${1}: ${CC} failed with $?" 1>&3
151 if .
/test-${1} 1>&3 2>&3; then
152 echo "${1}: yes" 1>&2
153 echo "${1}: yes" 1>&3
159 echo "${1}: execution failed with $?" 1>&3
166 # Run a complete autoconfiguration test, including the check for
167 # a manual override and disabling the feature on failure.
168 # Arguments: lower case name, upper case name, additional CFLAGS
170 eval _manual
=\
${HAVE_${2}}
171 ismanual
"${1}" "${_manual}" && return 0
172 singletest
"${1}" "${2}" "${3}" && return 0
178 # --- library functions ---
179 runtest dirent
-namlen DIRENT_NAMLEN
|| true
180 runtest err ERR
|| true
181 runtest fts FTS
|| true
182 runtest getline GETLINE
|| true
183 runtest getsubopt GETSUBOPT
|| true
184 runtest isblank ISBLANK
|| true
185 runtest mkdtemp MKDTEMP
|| true
186 runtest mmap MMAP
|| true
187 runtest pledge PLEDGE
|| true
188 runtest progname PROGNAME
|| true
189 runtest reallocarray REALLOCARRAY
|| true
190 runtest rewb
-bsd REWB_BSD
|| true
191 runtest rewb
-sysv REWB_SYSV
|| true
192 runtest strcasestr STRCASESTR
|| true
193 runtest stringlist STRINGLIST
|| true
194 runtest strlcat STRLCAT
|| true
195 runtest strlcpy STRLCPY
|| true
196 runtest strptime STRPTIME
|| true
197 runtest strsep STRSEP
|| true
198 runtest strtonum STRTONUM
|| true
199 runtest vasprintf VASPRINTF
|| true
200 runtest wchar WCHAR
|| true
203 if [ ${BUILD_DB} -eq 0 ]; then
204 echo "BUILD_DB=0 (manual)" 1>&2
205 echo "BUILD_DB=0 (manual)" 1>&3
208 elif ismanual sqlite3
"${HAVE_SQLITE3}"; then
209 if [ -z "${LD_SQLITE3}" ]; then
210 LD_SQLITE3
="-lsqlite3"
212 elif [ -n "${LD_SQLITE3}" ]; then
213 runtest sqlite3 SQLITE3
"${LD_SQLITE3}" || true
214 elif singletest sqlite3 SQLITE3
"-lsqlite3"; then
215 LD_SQLITE3
="-lsqlite3"
216 elif runtest sqlite3 SQLITE3 \
217 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
218 LD_SQLITE3
="-L/usr/local/lib -lsqlite3"
219 CFLAGS
="${CFLAGS} -I/usr/local/include"
221 if [ ${HAVE_SQLITE3} -eq 0 ]; then
223 if [ ${BUILD_DB} -gt 0 ]; then
224 echo "BUILD_DB=0 (no sqlite3)" 1>&2
225 echo "BUILD_DB=0 (no sqlite3)" 1>&3
231 # --- sqlite3_errstr ---
232 if [ ${BUILD_DB} -eq 0 ]; then
233 HAVE_SQLITE3_ERRSTR
=1
234 elif ismanual sqlite3_errstr
"${HAVE_SQLITE3_ERRSTR}"; then
237 runtest sqlite3_errstr SQLITE3_ERRSTR
"${LD_SQLITE3}" || true
241 if ismanual ohash
"${HAVE_OHASH}"; then
243 elif [ -n "${LD_OHASH}" ]; then
244 runtest ohash OHASH
"${LD_OHASH}" || true
245 elif singletest ohash OHASH
; then
247 elif runtest ohash OHASH
"-lutil"; then
250 if [ "${HAVE_OHASH}" -eq 0 ]; then
255 LDADD
="${LDADD} ${LD_SQLITE3} ${LD_OHASH} -lz"
256 echo "LDADD=\"${LDADD}\"" 1>&2
257 echo "LDADD=\"${LDADD}\"" 1>&3
261 if ismanual manpath
"${HAVE_MANPATH}"; then
263 elif manpath
1>&3 2>&3; then
264 echo "manpath: yes" 1>&2
265 echo "manpath: yes" 1>&3
269 echo "manpath: no" 1>&2
270 echo "manpath: no" 1>&3
275 # --- write config.h ---
281 #error "Do not use C++. See the INSTALL file."
284 #ifndef MANDOC_CONFIG_H
285 #define MANDOC_CONFIG_H
287 #if defined(__linux__) || defined(__MINT__)
288 #define _GNU_SOURCE /* See test-*.c what needs this. */
293 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
294 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
295 && echo "#include <sys/types.h>"
296 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
297 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
300 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
301 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
302 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
303 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
306 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
307 #define HAVE_ERR ${HAVE_ERR}
308 #define HAVE_FTS ${HAVE_FTS}
309 #define HAVE_GETLINE ${HAVE_GETLINE}
310 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
311 #define HAVE_ISBLANK ${HAVE_ISBLANK}
312 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
313 #define HAVE_MMAP ${HAVE_MMAP}
314 #define HAVE_PLEDGE ${HAVE_PLEDGE}
315 #define HAVE_PROGNAME ${HAVE_PROGNAME}
316 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
317 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
318 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
319 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
320 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
321 #define HAVE_STRLCAT ${HAVE_STRLCAT}
322 #define HAVE_STRLCPY ${HAVE_STRLCPY}
323 #define HAVE_STRPTIME ${HAVE_STRPTIME}
324 #define HAVE_STRSEP ${HAVE_STRSEP}
325 #define HAVE_STRTONUM ${HAVE_STRTONUM}
326 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
327 #define HAVE_WCHAR ${HAVE_WCHAR}
328 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
329 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
330 #define HAVE_OHASH ${HAVE_OHASH}
331 #define HAVE_MANPATH ${HAVE_MANPATH}
333 #define BINM_APROPOS "${BINM_APROPOS}"
334 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
335 #define BINM_MAN "${BINM_MAN}"
336 #define BINM_SOELIM "${BINM_SOELIM}"
337 #define BINM_WHATIS "${BINM_WHATIS}"
341 if [ ${HAVE_ERR} -eq 0 ]; then
342 echo "extern void err(int, const char *, ...);"
343 echo "extern void errx(int, const char *, ...);"
344 echo "extern void warn(const char *, ...);"
345 echo "extern void warnx(const char *, ...);"
348 [ ${HAVE_GETLINE} -eq 0 ] && \
349 echo "extern ssize_t getline(char **, size_t *, FILE *);"
351 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
352 echo "extern int getsubopt(char **, char * const *, char **);"
354 [ ${HAVE_ISBLANK} -eq 0 ] && \
355 echo "extern int isblank(int);"
357 [ ${HAVE_MKDTEMP} -eq 0 ] && \
358 echo "extern char *mkdtemp(char *);"
360 if [ ${HAVE_PROGNAME} -eq 0 ]; then
361 echo "extern const char *getprogname(void);"
362 echo "extern void setprogname(const char *);"
365 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
366 echo "extern void *reallocarray(void *, size_t, size_t);"
368 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
369 echo "extern const char *sqlite3_errstr(int);"
371 [ ${HAVE_STRCASESTR} -eq 0 ] && \
372 echo "extern char *strcasestr(const char *, const char *);"
374 [ ${HAVE_STRLCAT} -eq 0 ] && \
375 echo "extern size_t strlcat(char *, const char *, size_t);"
377 [ ${HAVE_STRLCPY} -eq 0 ] && \
378 echo "extern size_t strlcpy(char *, const char *, size_t);"
380 [ ${HAVE_STRSEP} -eq 0 ] && \
381 echo "extern char *strsep(char **, const char *);"
383 [ ${HAVE_STRTONUM} -eq 0 ] && \
384 echo "extern long long strtonum(const char *, long long, long long, const char **);"
386 [ ${HAVE_VASPRINTF} -eq 0 ] && \
387 echo "extern int vasprintf(char **, const char *, va_list);"
390 echo "#endif /* MANDOC_CONFIG_H */"
392 echo "config.h: written" 1>&2
393 echo "config.h: written" 1>&3
395 # --- tests for Makefile.local -----------------------------------------
397 exec > Makefile.
local
399 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
400 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
401 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
402 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
403 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
405 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
406 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
408 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
409 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
410 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
411 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
413 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
414 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
415 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
419 BUILD_TARGETS
="base-build"
420 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="${BUILD_TARGETS} cgi-build"
421 INSTALL_TARGETS
="base-install"
422 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} db-install"
423 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="${INSTALL_TARGETS} cgi-install"
426 BUILD_TARGETS = ${BUILD_TARGETS}
427 INSTALL_TARGETS = ${INSTALL_TARGETS}
435 INCLUDEDIR = ${INCLUDEDIR}
438 WWWPREFIX = ${WWWPREFIX}
439 HTDOCDIR = ${HTDOCDIR}
440 CGIBINDIR = ${CGIBINDIR}
441 BINM_APROPOS = ${BINM_APROPOS}
442 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
443 BINM_MAN = ${BINM_MAN}
444 BINM_SOELIM = ${BINM_SOELIM}
445 BINM_WHATIS = ${BINM_WHATIS}
446 MANM_MAN = ${MANM_MAN}
447 MANM_MANCONF = ${MANM_MANCONF}
448 MANM_MDOC = ${MANM_MDOC}
449 MANM_ROFF = ${MANM_ROFF}
450 MANM_EQN = ${MANM_EQN}
451 MANM_TBL = ${MANM_TBL}
453 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
454 INSTALL_LIB = ${INSTALL_LIB}
455 INSTALL_MAN = ${INSTALL_MAN}
456 INSTALL_DATA = ${INSTALL_DATA}
459 [ ${BUILD_DB} -gt 0 ] && \
460 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
462 echo "Makefile.local: written" 1>&2
463 echo "Makefile.local: written" 1>&3