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" | env -i make -f -`
38 CFLAGS
="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
39 CFLAGS
="${CFLAGS} -Wno-unused-parameter"
85 BINM_APROPOS
="apropos"
86 BINM_MAKEWHATIS
="makewhatis"
91 MANM_MANCONF
="man.conf"
103 # --- manual settings from configure.local -----------------------------
105 if [ -r .
/configure.
local ]; then
106 echo "configure.local: reading..." 1>&2
107 echo "configure.local: reading..." 1>&3
108 cat .
/configure.
local 1>&3
111 echo "configure.local: no (fully automatic configuration)" 1>&2
112 echo "configure.local: no (fully automatic configuration)" 1>&3
116 # --- tests for config.h ----------------------------------------------
118 COMP
="${CC} ${CFLAGS} -Wno-unused -Werror"
120 # Check whether this HAVE_ setting is manually overridden.
121 # If yes, use the override, if no, do not decide anything yet.
122 # Arguments: lower-case test name, manual value
124 [ -z "${2}" ] && return 1
125 echo "${1}: manual (${2})" 1>&2
126 echo "${1}: manual (${2})" 1>&3
131 # Run a single autoconfiguration test.
132 # In case of success, enable the feature.
133 # In case of failure, do not decide anything yet.
134 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
136 cat 1>&3 << __HEREDOC__
138 ${COMP} ${3} -o test-${1} test-${1}.c
141 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
142 echo "${1}: ${CC} succeeded" 1>&3
144 echo "${1}: ${CC} failed with $?" 1>&3
149 if .
/test-${1} 1>&3 2>&3; then
150 echo "${1}: yes" 1>&2
151 echo "${1}: yes" 1>&3
157 echo "${1}: execution failed with $?" 1>&3
164 # Run a complete autoconfiguration test, including the check for
165 # a manual override and disabling the feature on failure.
166 # Arguments: lower case name, upper case name, additional CFLAGS
168 eval _manual
=\
${HAVE_${2}}
169 ismanual
"${1}" "${_manual}" && return 0
170 singletest
"${1}" "${2}" "${3}" && return 0
176 # --- library functions ---
177 runtest dirent
-namlen DIRENT_NAMLEN
|| true
178 runtest err ERR
|| true
179 runtest fts FTS
|| true
180 runtest getline GETLINE
|| true
181 runtest getsubopt GETSUBOPT
|| true
182 runtest isblank ISBLANK
|| true
183 runtest mkdtemp MKDTEMP
|| true
184 runtest pledge PLEDGE
|| true
185 runtest sandbox_init SANDBOX_INIT
|| true
186 runtest progname PROGNAME
|| true
187 runtest reallocarray REALLOCARRAY
|| true
188 runtest rewb
-bsd REWB_BSD
|| true
189 runtest rewb
-sysv REWB_SYSV
|| true
190 runtest strcasestr STRCASESTR
|| true
191 runtest stringlist STRINGLIST
|| true
192 runtest strlcat STRLCAT
|| true
193 runtest strlcpy STRLCPY
|| true
194 runtest strptime STRPTIME
|| true
195 runtest strsep STRSEP
|| true
196 runtest strtonum STRTONUM
|| true
197 runtest vasprintf VASPRINTF
|| true
198 runtest wchar WCHAR
|| true
201 if ismanual ohash
"${HAVE_OHASH}"; then
203 elif [ -n "${LD_OHASH}" ]; then
204 runtest ohash OHASH
"${LD_OHASH}" || true
205 elif singletest ohash OHASH
; then
207 elif runtest ohash OHASH
"-lutil"; then
210 if [ "${HAVE_OHASH}" -eq 0 ]; then
215 LDADD
="${LDADD} ${LD_OHASH} -lz"
216 echo "LDADD=\"${LDADD}\"" 1>&2
217 echo "LDADD=\"${LDADD}\"" 1>&3
221 if ismanual manpath
"${HAVE_MANPATH}"; then
223 elif manpath
1>&3 2>&3; then
224 echo "manpath: yes" 1>&2
225 echo "manpath: yes" 1>&3
229 echo "manpath: no" 1>&2
230 echo "manpath: no" 1>&3
235 # --- write config.h ---
241 #error "Do not use C++. See the INSTALL file."
244 #if !defined(__GNUC__) || (__GNUC__ < 4)
245 #define __attribute__(x)
248 #if defined(__linux__) || defined(__MINT__)
249 #define _GNU_SOURCE /* See test-*.c what needs this. */
254 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
255 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
256 && echo "#include <sys/types.h>"
257 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
258 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
261 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
262 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
263 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
264 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
267 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
268 #define HAVE_ERR ${HAVE_ERR}
269 #define HAVE_FTS ${HAVE_FTS}
270 #define HAVE_GETLINE ${HAVE_GETLINE}
271 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
272 #define HAVE_ISBLANK ${HAVE_ISBLANK}
273 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
274 #define HAVE_PLEDGE ${HAVE_PLEDGE}
275 #define HAVE_PROGNAME ${HAVE_PROGNAME}
276 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
277 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
278 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
279 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
280 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
281 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
282 #define HAVE_STRLCAT ${HAVE_STRLCAT}
283 #define HAVE_STRLCPY ${HAVE_STRLCPY}
284 #define HAVE_STRPTIME ${HAVE_STRPTIME}
285 #define HAVE_STRSEP ${HAVE_STRSEP}
286 #define HAVE_STRTONUM ${HAVE_STRTONUM}
287 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
288 #define HAVE_WCHAR ${HAVE_WCHAR}
289 #define HAVE_OHASH ${HAVE_OHASH}
290 #define HAVE_MANPATH ${HAVE_MANPATH}
292 #define BINM_APROPOS "${BINM_APROPOS}"
293 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
294 #define BINM_MAN "${BINM_MAN}"
295 #define BINM_SOELIM "${BINM_SOELIM}"
296 #define BINM_WHATIS "${BINM_WHATIS}"
300 if [ ${HAVE_ERR} -eq 0 ]; then
301 echo "extern void err(int, const char *, ...);"
302 echo "extern void errx(int, const char *, ...);"
303 echo "extern void warn(const char *, ...);"
304 echo "extern void warnx(const char *, ...);"
307 [ ${HAVE_GETLINE} -eq 0 ] && \
308 echo "extern ssize_t getline(char **, size_t *, FILE *);"
310 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
311 echo "extern int getsubopt(char **, char * const *, char **);"
313 [ ${HAVE_ISBLANK} -eq 0 ] && \
314 echo "extern int isblank(int);"
316 [ ${HAVE_MKDTEMP} -eq 0 ] && \
317 echo "extern char *mkdtemp(char *);"
319 if [ ${HAVE_PROGNAME} -eq 0 ]; then
320 echo "extern const char *getprogname(void);"
321 echo "extern void setprogname(const char *);"
324 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
325 echo "extern void *reallocarray(void *, size_t, size_t);"
327 [ ${HAVE_STRCASESTR} -eq 0 ] && \
328 echo "extern char *strcasestr(const char *, const char *);"
330 [ ${HAVE_STRLCAT} -eq 0 ] && \
331 echo "extern size_t strlcat(char *, const char *, size_t);"
333 [ ${HAVE_STRLCPY} -eq 0 ] && \
334 echo "extern size_t strlcpy(char *, const char *, size_t);"
336 [ ${HAVE_STRSEP} -eq 0 ] && \
337 echo "extern char *strsep(char **, const char *);"
339 [ ${HAVE_STRTONUM} -eq 0 ] && \
340 echo "extern long long strtonum(const char *, long long, long long, const char **);"
342 [ ${HAVE_VASPRINTF} -eq 0 ] && \
343 echo "extern int vasprintf(char **, const char *, va_list);"
345 echo "config.h: written" 1>&2
346 echo "config.h: written" 1>&3
348 # --- tests for Makefile.local -----------------------------------------
350 exec > Makefile.
local
352 [ -z "${BINDIR}" ] && BINDIR
="${PREFIX}/bin"
353 [ -z "${SBINDIR}" ] && SBINDIR
="${PREFIX}/sbin"
354 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR
="${PREFIX}/include/mandoc"
355 [ -z "${LIBDIR}" ] && LIBDIR
="${PREFIX}/lib/mandoc"
356 [ -z "${MANDIR}" ] && MANDIR
="${PREFIX}/man"
358 [ -z "${HTDOCDIR}" ] && HTDOCDIR
="${WWWPREFIX}/htdocs"
359 [ -z "${CGIBINDIR}" ] && CGIBINDIR
="${WWWPREFIX}/cgi-bin"
361 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM
="${INSTALL} -m 0555"
362 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB
="${INSTALL} -m 0444"
363 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN
="${INSTALL} -m 0444"
364 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA
="${INSTALL} -m 0444"
367 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS
="cgi-build"
369 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS
="cgi-install"
372 BUILD_TARGETS = ${BUILD_TARGETS}
373 INSTALL_TARGETS = ${INSTALL_TARGETS}
382 INCLUDEDIR = ${INCLUDEDIR}
385 WWWPREFIX = ${WWWPREFIX}
386 HTDOCDIR = ${HTDOCDIR}
387 CGIBINDIR = ${CGIBINDIR}
388 BINM_APROPOS = ${BINM_APROPOS}
389 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
390 BINM_MAN = ${BINM_MAN}
391 BINM_SOELIM = ${BINM_SOELIM}
392 BINM_WHATIS = ${BINM_WHATIS}
393 MANM_MAN = ${MANM_MAN}
394 MANM_MANCONF = ${MANM_MANCONF}
395 MANM_MDOC = ${MANM_MDOC}
396 MANM_ROFF = ${MANM_ROFF}
397 MANM_EQN = ${MANM_EQN}
398 MANM_TBL = ${MANM_TBL}
400 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
401 INSTALL_LIB = ${INSTALL_LIB}
402 INSTALL_MAN = ${INSTALL_MAN}
403 INSTALL_DATA = ${INSTALL_DATA}
406 echo "Makefile.local: written" 1>&2
407 echo "Makefile.local: written" 1>&3