xref: /freebsd/contrib/mandoc/configure (revision c1c95add8c80843ba15d784f95c361d795b1f593)
1#!/bin/sh
2#
3# $Id: configure,v 1.83 2023/10/19 11:45:42 schwarze Exp $
4#
5# Copyright (c) 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
6#
7# Permission to use, copy, modify, and distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19set -e
20
21[ -w config.log ] && mv config.log config.log.old
22[ -w config.h   ] && mv config.h config.h.old
23
24# Output file descriptor usage:
25# 1 (stdout): config.h, Makefile.local
26# 2 (stderr): original stderr, usually to the console
27# 3: config.log
28
29exec 3> config.log
30echo "file config.log: writing..."
31
32# --- default settings -------------------------------------------------
33# Initialize all variables here,
34# such that nothing can leak in from the environment.
35
36SOURCEDIR=`dirname "${0}"`
37
38MANPATH_BASE="/usr/share/man:/usr/X11R6/man"
39MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
40DEBUG_MEMORY=0
41OSENUM=
42OSNAME=
43UTF8_LOCALE=
44
45AR=ar
46CC=cc
47CFLAGS=
48FATAL=0
49LDADD=
50LDFLAGS=
51LD_NANOSLEEP=
52LD_OHASH=
53LD_RECVMSG=
54STATIC=
55
56BUILD_CGI=0
57BUILD_CATMAN=0
58INSTALL_LIBMANDOC=0
59
60HAVE_ATTRIBUTE=
61HAVE_CMSG=
62HAVE_DIRENT_NAMLEN=
63HAVE_EFTYPE=
64HAVE_ENDIAN=
65HAVE_ERR=
66HAVE_FTS=
67HAVE_FTS_COMPARE_CONST=
68HAVE_GETLINE=
69HAVE_GETSUBOPT=
70HAVE_ISBLANK=
71HAVE_LESS_T=
72HAVE_MKDTEMP=
73HAVE_MKSTEMPS=
74HAVE_NANOSLEEP=
75HAVE_NTOHL=
76HAVE_O_DIRECTORY=
77HAVE_OHASH=
78HAVE_PATH_MAX=
79HAVE_PLEDGE=
80HAVE_PROGNAME=
81HAVE_REALLOCARRAY=
82HAVE_RECALLOCARRAY=
83HAVE_RECVMSG=
84HAVE_REWB_BSD=
85HAVE_REWB_SYSV=
86HAVE_SANDBOX_INIT=
87HAVE_STRCASESTR=
88HAVE_STRINGLIST=
89HAVE_STRLCAT=
90HAVE_STRLCPY=
91HAVE_STRNDUP=
92HAVE_STRPTIME=
93HAVE_STRSEP=
94HAVE_STRTONUM=
95HAVE_SYS_ENDIAN=
96HAVE_VASPRINTF=
97HAVE_WCHAR=
98
99NEED_GNU_SOURCE=0
100NEED_OPENBSD_SOURCE=0
101NEED_XPG4_2=0
102
103DEBUG_OBJS=
104MANDOC_COBJS=
105SOELIM_COBJS=
106
107PREFIX="/usr/local"
108BINDIR=
109SBINDIR=
110BIN_FROM_SBIN=
111INCLUDEDIR=
112LIBDIR=
113MANDIR=
114MISCDIR=
115READ_ALLOWED_PATH=
116
117WWWPREFIX="/var/www"
118HTDOCDIR=
119CGIBINDIR=
120
121BINM_APROPOS="apropos"
122BINM_CATMAN="catman"
123BINM_MAKEWHATIS="makewhatis"
124BINM_MAN="man"
125BINM_SOELIM="soelim"
126BINM_WHATIS="whatis"
127BINM_PAGER=
128MANM_MAN="man"
129MANM_MANCONF="man.conf"
130MANM_MDOC="mdoc"
131MANM_ROFF="roff"
132MANM_EQN="eqn"
133MANM_TBL="tbl"
134
135INSTALL="install"
136INSTALL_PROGRAM=
137INSTALL_LIB=
138INSTALL_MAN=
139INSTALL_DATA=
140LN="ln -f"
141
142# --- manual settings from configure.local -----------------------------
143
144if [ -r ./configure.local ]; then
145	echo "file configure.local: reading..." 1>&2
146	echo "file configure.local: reading..." 1>&3
147	cat ./configure.local 1>&3
148	. ./configure.local
149else
150	echo "file configure.local: no (fully automatic configuration)" 1>&2
151	echo "file configure.local: no (fully automatic configuration)" 1>&3
152fi
153echo 1>&3
154
155# --- tests functions --------------------------------------------------
156
157# Check whether this HAVE_ setting is manually overridden.
158# If yes, use the override, if no, do not decide anything yet.
159# Arguments: test file name, test var name, manual value
160ismanual() {
161	[ -z "${3}" ] && return 1
162	echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&2
163	echo "tested ${1}: HAVE_${2}=${3} (manual)" 1>&3
164	echo 1>&3
165	return 0
166}
167
168# Run a single autoconfiguration test.
169# In case of success, enable the feature.
170# In case of failure, do not decide anything yet.
171# Arguments: test file name, test var name, additional CFLAGS
172singletest() {
173	n=${1}${3}
174	cat 1>&3 << __HEREDOC__
175testing ${n} ...
176${COMP} -o test-${1} test-${1}.c ${3}
177__HEREDOC__
178
179	if ${COMP} -o "test-${1}" "${SOURCEDIR}/test-${1}.c" ${3} 1>&3 2>&3
180	then
181		echo "partial result of ${n}: ${CC} succeeded" 1>&3
182	else
183		echo "tested ${n}: no (compilation failed)" 1>&2
184		echo "result of ${n}: ${CC} failed with exit status $?" 1>&3
185		echo "result of compiling ${n}: no" 1>&3
186		echo 1>&3
187		return 1
188	fi
189
190	if ./test-${1} 1>&3 2>&3; then
191		echo "tested ${n}: yes" 1>&2
192		echo "result of running ${n}: yes" 1>&3
193		echo 1>&3
194		eval HAVE_${2}=1
195		[ "${3}" = "-D_GNU_SOURCE" ] && NEED_GNU_SOURCE=1
196		[ "${3}" = "-D_OPENBSD_SOURCE" ] && NEED_OPENBSD_SOURCE=1
197		[ "${3}" = "-D_XPG4_2" ] && NEED_XPG4_2=1
198		[ "${3}" = "-lrt" ] && LD_NANOSLEEP="-lrt"
199		[ "${3}" = "-lsocket" ] && LD_RECVMSG="-lsocket"
200		[ "${3}" = "-lutil" ] && LD_OHASH="-lutil"
201		rm "test-${1}"
202		return 0
203	else
204		echo "tested ${n}: no (execution failed)" 1>&2
205		echo "result of ${n}: execution failed with exit status $?" 1>&3
206		echo "result of running ${n}: no" 1>&3
207		echo 1>&3
208		rm "test-${1}"
209		return 1
210	fi
211}
212
213# Run a complete autoconfiguration test, including the check for
214# a manual override and disabling the feature on failure.
215# Arguments: test file name, test var name, additional CFLAGS
216# The final argument can optionally be repeated a second time.
217runtest() {
218	eval _manual=\${HAVE_${2}}
219	ismanual "${1}" "${2}" "${_manual}" && return 0
220	singletest "${1}" "${2}" "${3}" && return 0
221	[ -n "${4}" ] && singletest "${1}" "${2}" "${4}" && return 0
222	eval HAVE_${2}=0
223	return 1
224}
225
226# Select a UTF-8 locale.
227get_locale() {
228	[ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
229	ismanual UTF8_LOCALE UTF8_LOCALE "${UTF8_LOCALE}" && return 0
230	echo "testing UTF8_LOCALE ..." 1>&3
231	UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
232	if [ -z "${UTF8_LOCALE}" ]; then
233		UTF8_LOCALE=`locale -a | grep -i '\.UTF-*8' | head -n 1`
234		[ -n "${UTF8_LOCALE}" ] || return 1
235	fi
236	echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
237	echo "selected UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
238	echo 1>&3
239	return 0;
240}
241
242# --- operating system -------------------------------------------------
243
244if [ -n "${OSENUM}" ]; then
245	echo "OSENUM specified manually: ${OSENUM}" 1>&2
246	echo "OSENUM specified manually: ${OSENUM}" 1>&3
247else
248	OSDETECT=`uname`
249	if [ "${OSDETECT}" = "NetBSD" ]; then
250		OSENUM=MANDOC_OS_NETBSD
251	elif [ "${OSDETECT}" = "OpenBSD" ]; then
252		OSENUM=MANDOC_OS_OPENBSD
253	else
254		OSENUM=MANDOC_OS_OTHER
255	fi
256	echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&2
257	echo "tested operating system: ${OSDETECT} -> OSENUM=${OSENUM}" 1>&3
258	unset OSDETECT
259fi
260echo 1>&3
261
262# --- compiler options -------------------------------------------------
263
264DEFCFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter"
265
266if [ -n "${CFLAGS}" ]; then
267	COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
268else
269	COMP="${CC} ${DEFCFLAGS} -Wno-unused -Werror"
270fi
271printf "%s" "tested ${CC} -W: " 1>&2
272printf "%s" "testing ${CC} -W: " 1>&3
273runtest noop WFLAG || true
274
275if [ -n "${CFLAGS}" ]; then
276	echo "CFLAGS specified manually:" 1>&3
277elif [ ${HAVE_WFLAG} -eq 0 ]; then
278	CFLAGS="-g"
279else
280	CFLAGS="${DEFCFLAGS}"
281fi
282echo "selected CFLAGS=\"${CFLAGS}\"" 1>&2
283echo "selected CFLAGS=\"${CFLAGS}\"" 1>&3
284echo 1>&3
285
286COMP="${CC} ${CFLAGS}"
287[ ${HAVE_WFLAG} -eq 0 ] || COMP="${COMP} -Wno-unused -Werror"
288
289if [ -n "${STATIC}" ]; then
290	echo "selected STATIC=\"${STATIC}\" (manual)" 1>&2
291	echo "selected STATIC=\"${STATIC}\" (manual)" 1>&3
292	echo 1>&3
293else
294	runtest noop STATIC -static || true
295	[ ${HAVE_STATIC} -eq 0 ] || STATIC="-static"
296	echo "selected STATIC=\"${STATIC}\"" 1>&2
297	echo "selected STATIC=\"${STATIC}\"" 1>&3
298	echo 1>&3
299fi
300
301# --- tests for config.h  ----------------------------------------------
302
303# --- library functions ---
304runtest attribute	ATTRIBUTE	|| true
305runtest cmsg		CMSG		"" "-D_XPG4_2" || true
306runtest dirent-namlen	DIRENT_NAMLEN	|| true
307runtest be32toh		ENDIAN		|| true
308runtest be32toh		SYS_ENDIAN	-DSYS_ENDIAN || true
309runtest EFTYPE		EFTYPE		|| true
310runtest err		ERR		|| true
311runtest getline		GETLINE		|| true
312runtest getsubopt	GETSUBOPT	"" -D_GNU_SOURCE || true
313runtest isblank		ISBLANK		|| true
314runtest mkdtemp		MKDTEMP		|| true
315runtest mkstemps	MKSTEMPS	|| true
316runtest nanosleep	NANOSLEEP	"${LD_NANOSLEEP}" "-lrt" || true
317runtest ntohl		NTOHL		|| true
318runtest O_DIRECTORY	O_DIRECTORY	|| true
319runtest PATH_MAX	PATH_MAX	|| true
320runtest pledge		PLEDGE		|| true
321runtest sandbox_init	SANDBOX_INIT	|| true
322runtest progname	PROGNAME	|| true
323runtest reallocarray	REALLOCARRAY	"" -D_OPENBSD_SOURCE || true
324runtest recallocarray	RECALLOCARRAY	"" -D_OPENBSD_SOURCE || true
325runtest recvmsg		RECVMSG		"${LD_RECVMSG}" "-lsocket" || true
326runtest rewb-bsd	REWB_BSD	|| true
327runtest rewb-sysv	REWB_SYSV	|| true
328runtest strcasestr	STRCASESTR	"" -D_GNU_SOURCE || true
329runtest stringlist	STRINGLIST	|| true
330runtest strlcat		STRLCAT		|| true
331runtest strlcpy		STRLCPY		|| true
332runtest strndup		STRNDUP		|| true
333runtest strptime	STRPTIME	"" -D_GNU_SOURCE || true
334runtest strsep		STRSEP		|| true
335runtest strtonum	STRTONUM	"" -D_OPENBSD_SOURCE || true
336runtest vasprintf	VASPRINTF	"" -D_GNU_SOURCE || true
337
338# --- fts ---
339if [ "${1}" = "-depend" ]; then
340	DEBUG_MEMORY=1
341	HAVE_FTS=0
342	HAVE_FTS_COMPARE_CONST=0
343	echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&2
344	echo "tested fts: HAVE_FTS=0 (for make depend)" 1>&3
345	echo 1>&3
346elif ismanual fts FTS ${HAVE_FTS}; then
347	HAVE_FTS_COMPARE_CONST=0
348elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then
349	HAVE_FTS=1
350else
351	runtest fts FTS || true
352fi
353
354# --- pager ---
355manual=
356if [ -n "${BINM_PAGER}" ]; then
357	manual=" (manual)"
358elif less test-noop.c 1>/dev/null 2>&3; then
359	BINM_PAGER=less
360	echo "tested less: yes" 1>&2
361	echo "tested less: yes" 1>&3
362else
363	BINM_PAGER=more
364	echo "tested less: no" 1>&2
365	echo "tested less: no" 1>&3
366fi
367echo "selected BINM_PAGER=${BINM_PAGER}${manual}" 1>&2
368echo "selected BINM_PAGER=${BINM_PAGER}${manual}" 1>&3
369
370# --- tagging support in the pager ---
371if ismanual "${BINM_PAGER} -T" LESS_T ${HAVE_LESS_T}; then
372	:
373elif ${BINM_PAGER} -T /dev/null test-noop.c 1>/dev/null 2>&3; then
374	HAVE_LESS_T=1
375	echo "tested ${BINM_PAGER} -T: yes" 1>&2
376	echo "tested ${BINM_PAGER} -T: yes" 1>&3
377	echo 1>&3
378else
379	HAVE_LESS_T=0
380	echo "tested ${BINM_PAGER} -T: no" 1>&2
381	echo "tested ${BINM_PAGER} -T: no" 1>&3
382	echo 1>&3
383fi
384
385# --- wide character and locale support ---
386if get_locale; then
387	runtest wchar WCHAR "-DUTF8_LOCALE=\"${UTF8_LOCALE}\"" \
388	    "-D_GNU_SOURCE -DUTF8_LOCALE=\"${UTF8_LOCALE}\"" || true
389else
390	HAVE_WCHAR=0
391	echo "tested wchar: no (no UTF8_LOCALE)" 1>&2
392	echo "tested wchar: no (no UTF8_LOCALE)" 1>&3
393	echo 1>&3
394fi
395
396# --- ohash ---
397if [ "${1}" = "-depend" ]; then
398	HAVE_OHASH=0
399	echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&2
400	echo "tested ohash: HAVE_OHASH=0 (for make depend)" 1>&3
401	echo 1>&3
402else
403	runtest ohash OHASH "${LD_OHASH}" "-lutil" || true
404fi
405if [ "${HAVE_OHASH}" -eq 0 ]; then
406	LD_OHASH=
407fi
408
409# --- required functions ---
410if [ ${HAVE_ENDIAN} -eq 0 -a \
411     ${HAVE_SYS_ENDIAN} -eq 0 -a \
412     ${HAVE_NTOHL} -eq 0 ]; then
413	echo "FATAL: no endian conversion functions found" 1>&2
414	echo "FATAL: no endian conversion functions found" 1>&3
415	FATAL=1
416fi
417if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
418	echo "FATAL: nanosleep: no" 1>&2
419	echo "FATAL: nanosleep: no" 1>&3
420	FATAL=1
421fi
422if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_RECVMSG}" -eq 0 ]; then
423	echo "FATAL: recvmsg: no" 1>&2
424	echo "FATAL: recvmsg: no" 1>&3
425	echo "Without recvmsg(2), you cannot BUILD_CATMAN." 1>&2
426	FATAL=1
427fi
428if [ ${BUILD_CATMAN} -gt 0 -a "${HAVE_CMSG}" -eq 0 ]; then
429	echo "FATAL: cmsg: no" 1>&2
430	echo "FATAL: cmsg: no" 1>&3
431	echo "Without CMSG_FIRSTHDR(3), you cannot BUILD_CATMAN." 1>&2
432	FATAL=1
433fi
434[ "${FATAL}" -eq 0 ] || exit 1
435
436# --- LDADD ---
437LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_RECVMSG} ${LD_OHASH} -lz"
438echo "selected LDADD=\"${LDADD}\"" 1>&2
439echo "selected LDADD=\"${LDADD}\"" 1>&3
440echo 1>&3
441
442# --- write config.h ---
443
444exec > config.h
445
446cat << __HEREDOC__
447#ifdef __cplusplus
448#error "Do not use C++.  See the INSTALL file."
449#endif
450
451__HEREDOC__
452
453[ ${NEED_GNU_SOURCE} -eq 0 ] || echo "#define _GNU_SOURCE"
454[ ${NEED_OPENBSD_SOURCE} -eq 0 ] || echo "#define _OPENBSD_SOURCE"
455
456[ ${HAVE_GETLINE} -eq 0 -o \
457  ${HAVE_REALLOCARRAY} -eq 0 -o ${HAVE_RECALLOCARRAY} -eq 0 -o \
458  ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o \
459  ${HAVE_STRNDUP} -eq 0 ] \
460	&& echo "#include <sys/types.h>"
461[ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
462[ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
463
464echo
465echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
466echo "#define MANPATH_BASE \"${MANPATH_BASE}\""
467echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
468if [ ${DEBUG_MEMORY} -ne 0 ]; then
469	echo "#define DEBUG_MEMORY ${DEBUG_MEMORY}"
470	DEBUG_OBJS=mandoc_dbg.o
471fi
472echo "#define OSENUM ${OSENUM}"
473[ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
474[ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
475[ -n "${READ_ALLOWED_PATH}" ] \
476	&& echo "#define READ_ALLOWED_PATH \"${READ_ALLOWED_PATH}\""
477[ ${HAVE_ATTRIBUTE} -eq 0 ] && echo "#define __attribute__(x)"
478[ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
479[ ${HAVE_O_DIRECTORY} -eq 0 ] && echo "#define O_DIRECTORY 0"
480[ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
481if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
482	echo "#define be32toh ntohl"
483	echo "#define htobe32 htonl"
484fi
485cat << __HEREDOC__
486
487#define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
488#define HAVE_ENDIAN ${HAVE_ENDIAN}
489#define HAVE_ERR ${HAVE_ERR}
490#define HAVE_FTS ${HAVE_FTS}
491#define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
492#define HAVE_GETLINE ${HAVE_GETLINE}
493#define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
494#define HAVE_ISBLANK ${HAVE_ISBLANK}
495#define HAVE_LESS_T ${HAVE_LESS_T}
496#define HAVE_MKDTEMP ${HAVE_MKDTEMP}
497#define HAVE_MKSTEMPS ${HAVE_MKSTEMPS}
498#define HAVE_NTOHL ${HAVE_NTOHL}
499#define HAVE_PLEDGE ${HAVE_PLEDGE}
500#define HAVE_PROGNAME ${HAVE_PROGNAME}
501#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
502#define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
503#define HAVE_REWB_BSD ${HAVE_REWB_BSD}
504#define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
505#define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
506#define HAVE_STRCASESTR ${HAVE_STRCASESTR}
507#define HAVE_STRINGLIST ${HAVE_STRINGLIST}
508#define HAVE_STRLCAT ${HAVE_STRLCAT}
509#define HAVE_STRLCPY ${HAVE_STRLCPY}
510#define HAVE_STRNDUP ${HAVE_STRNDUP}
511#define HAVE_STRPTIME ${HAVE_STRPTIME}
512#define HAVE_STRSEP ${HAVE_STRSEP}
513#define HAVE_STRTONUM ${HAVE_STRTONUM}
514#define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
515#define HAVE_VASPRINTF ${HAVE_VASPRINTF}
516#define HAVE_WCHAR ${HAVE_WCHAR}
517#define HAVE_OHASH ${HAVE_OHASH}
518#define NEED_XPG4_2 ${NEED_XPG4_2}
519
520#define BINM_APROPOS "${BINM_APROPOS}"
521#define BINM_CATMAN "${BINM_CATMAN}"
522#define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
523#define BINM_MAN "${BINM_MAN}"
524#define BINM_SOELIM "${BINM_SOELIM}"
525#define BINM_WHATIS "${BINM_WHATIS}"
526#define BINM_PAGER "${BINM_PAGER}"
527
528__HEREDOC__
529
530if [ ${HAVE_ERR} -eq 0 ]; then
531	echo "extern	void	  err(int, const char *, ...);"
532	echo "extern	void	  errx(int, const char *, ...);"
533	echo "extern	void	  warn(const char *, ...);"
534	echo "extern	void	  warnx(const char *, ...);"
535	MANDOC_COBJS="${MANDOC_COBJS} compat_err.o"
536	SOELIM_COBJS="${SOELIM_COBJS} compat_err.o"
537fi
538if [ ${HAVE_FTS} -eq 0 ]; then
539	MANDOC_COBJS="${MANDOC_COBJS} compat_fts.o"
540fi
541if [ ${HAVE_GETLINE} -eq 0 ]; then
542	echo "extern	ssize_t	  getline(char **, size_t *, FILE *);"
543	MANDOC_COBJS="${MANDOC_COBJS} compat_getline.o"
544	SOELIM_COBJS="${SOELIM_COBJS} compat_getline.o"
545fi
546if [ ${HAVE_GETSUBOPT} -eq 0 ]; then
547	echo "extern	int	  getsubopt(char **, char * const *, char **);"
548	MANDOC_COBJS="${MANDOC_COBJS} compat_getsubopt.o"
549fi
550if [ ${HAVE_ISBLANK} -eq 0 ]; then
551	echo "extern	int	  isblank(int);"
552	MANDOC_COBJS="${MANDOC_COBJS} compat_isblank.o"
553fi
554if [ ${HAVE_MKDTEMP} -eq 0 ]; then
555	echo "extern	char	 *mkdtemp(char *);"
556	MANDOC_COBJS="${MANDOC_COBJS} compat_mkdtemp.o"
557fi
558if [ ${HAVE_MKSTEMPS} -eq 0 ]; then
559	echo "extern	int	  mkstemps(char *, int);"
560	MANDOC_COBJS="${MANDOC_COBJS} compat_mkstemps.o"
561fi
562if [ ${HAVE_OHASH} -eq 0 ]; then
563	MANDOC_COBJS="${MANDOC_COBJS} compat_ohash.o"
564fi
565if [ ${HAVE_PROGNAME} -eq 0 ]; then
566	echo "extern	const char *getprogname(void);"
567	echo "extern	void	  setprogname(const char *);"
568	MANDOC_COBJS="${MANDOC_COBJS} compat_progname.o"
569	SOELIM_COBJS="${SOELIM_COBJS} compat_progname.o"
570fi
571if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then
572	echo "extern	void	 *reallocarray(void *, size_t, size_t);"
573	MANDOC_COBJS="${MANDOC_COBJS} compat_reallocarray.o"
574	SOELIM_COBJS="${SOELIM_COBJS} compat_reallocarray.o"
575fi
576if [ ${HAVE_RECALLOCARRAY} -eq 0 ]; then
577	echo "extern	void	 *recallocarray(void *, size_t, size_t, size_t);"
578	MANDOC_COBJS="${MANDOC_COBJS} compat_recallocarray.o"
579fi
580if [ ${HAVE_STRCASESTR} -eq 0 ]; then
581	echo "extern	char	 *strcasestr(const char *, const char *);"
582	MANDOC_COBJS="${MANDOC_COBJS} compat_strcasestr.o"
583fi
584if [ ${HAVE_STRINGLIST} -eq 0 ]; then
585	SOELIM_COBJS="${SOELIM_COBJS} compat_stringlist.o"
586fi
587if [ ${HAVE_STRLCAT} -eq 0 ]; then
588	echo "extern	size_t	  strlcat(char *, const char *, size_t);"
589	MANDOC_COBJS="${MANDOC_COBJS} compat_strlcat.o"
590fi
591if [ ${HAVE_STRLCPY} -eq 0 ]; then
592	echo "extern	size_t	  strlcpy(char *, const char *, size_t);"
593	MANDOC_COBJS="${MANDOC_COBJS} compat_strlcpy.o"
594fi
595if [ ${HAVE_STRNDUP} -eq 0 ]; then
596	echo "extern	char	 *strndup(const char *, size_t);"
597	MANDOC_COBJS="${MANDOC_COBJS} compat_strndup.o"
598fi
599if [ ${HAVE_STRSEP} -eq 0 ]; then
600	echo "extern	char	 *strsep(char **, const char *);"
601	MANDOC_COBJS="${MANDOC_COBJS} compat_strsep.o"
602fi
603if [ ${HAVE_STRTONUM} -eq 0 ]; then
604	echo "extern	long long strtonum(const char *, long long, long long, const char **);"
605	MANDOC_COBJS="${MANDOC_COBJS} compat_strtonum.o"
606fi
607if [ ${HAVE_VASPRINTF} -eq 0 ]; then
608	echo "extern	int	  vasprintf(char **, const char *, va_list);"
609	MANDOC_COBJS="${MANDOC_COBJS} compat_vasprintf.o"
610fi
611echo "file config.h: written" 1>&2
612echo "file config.h: written" 1>&3
613
614# --- tests for Makefile.local -----------------------------------------
615
616exec > Makefile.local
617
618[ -z "${BINDIR}"          ] && BINDIR="${PREFIX}/bin"
619[ -z "${SBINDIR}"         ] && SBINDIR="${PREFIX}/sbin"
620[ -z "${BIN_FROM_SBIN}"   ] && BIN_FROM_SBIN="../bin"
621[ -z "${INCLUDEDIR}"      ] && INCLUDEDIR="${PREFIX}/include/mandoc"
622[ -z "${LIBDIR}"          ] && LIBDIR="${PREFIX}/lib/mandoc"
623[ -z "${MANDIR}"          ] && MANDIR="${PREFIX}/man"
624[ -z "${MISCDIR}"         ] && MISCDIR="${PREFIX}/share/misc"
625
626[ -z "${HTDOCDIR}"        ] && HTDOCDIR="${WWWPREFIX}/htdocs"
627[ -z "${CGIBINDIR}"       ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
628
629[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
630[ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0444"
631[ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0444"
632[ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0444"
633
634BUILD_TARGETS=
635[ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="man.cgi"
636[ ${BUILD_CATMAN} -gt 0 ] && \
637	BUILD_TARGETS="${BUILD_TARGETS} mandocd catman"
638INSTALL_TARGETS=
639[ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS="lib-install"
640[ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
641[ ${BUILD_CATMAN} -gt 0 ] && \
642	INSTALL_TARGETS="${INSTALL_TARGETS} catman-install"
643
644cat << __HEREDOC__
645BUILD_TARGETS	= ${BUILD_TARGETS}
646INSTALL_TARGETS	= ${INSTALL_TARGETS}
647AR		= ${AR}
648CC		= ${CC}
649CFLAGS		= ${CFLAGS}
650LDADD		= ${LDADD}
651LDFLAGS		= ${LDFLAGS}
652DEBUG_OBJS	= ${DEBUG_OBJS}
653MANDOC_COBJS	= ${MANDOC_COBJS}
654SOELIM_COBJS	= ${SOELIM_COBJS}
655STATIC		= ${STATIC}
656PREFIX		= ${PREFIX}
657BINDIR		= ${BINDIR}
658SBINDIR		= ${SBINDIR}
659BIN_FROM_SBIN	= ${BIN_FROM_SBIN}
660INCLUDEDIR	= ${INCLUDEDIR}
661LIBDIR		= ${LIBDIR}
662MANDIR		= ${MANDIR}
663MISCDIR		= ${MISCDIR}
664WWWPREFIX	= ${WWWPREFIX}
665HTDOCDIR	= ${HTDOCDIR}
666CGIBINDIR	= ${CGIBINDIR}
667BINM_APROPOS	= ${BINM_APROPOS}
668BINM_CATMAN	= ${BINM_CATMAN}
669BINM_MAKEWHATIS	= ${BINM_MAKEWHATIS}
670BINM_MAN	= ${BINM_MAN}
671BINM_SOELIM	= ${BINM_SOELIM}
672BINM_WHATIS	= ${BINM_WHATIS}
673MANM_MAN	= ${MANM_MAN}
674MANM_MANCONF	= ${MANM_MANCONF}
675MANM_MDOC	= ${MANM_MDOC}
676MANM_ROFF	= ${MANM_ROFF}
677MANM_EQN	= ${MANM_EQN}
678MANM_TBL	= ${MANM_TBL}
679INSTALL		= ${INSTALL}
680INSTALL_PROGRAM	= ${INSTALL_PROGRAM}
681INSTALL_LIB	= ${INSTALL_LIB}
682INSTALL_MAN	= ${INSTALL_MAN}
683INSTALL_DATA	= ${INSTALL_DATA}
684LN		= ${LN}
685__HEREDOC__
686
687echo "file Makefile.local: written" 1>&2
688echo "file Makefile.local: written" 1>&3
689
690exit 0
691