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