]> git.cameronkatri.com Git - mandoc.git/blob - configure
for .Rs, use <cite>
[mandoc.git] / configure
1 #!/bin/sh
2 #
3 # $Id: configure,v 1.56 2017/02/04 12:03:07 schwarze Exp $
4 #
5 # Copyright (c) 2014, 2015, 2016 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
19 set -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
29 exec 3> config.log
30 echo "config.log: writing..."
31
32 # --- default settings -------------------------------------------------
33 # Initialize all variables here,
34 # such that nothing can leak in from the environment.
35
36 MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
37 OSNAME=
38 UTF8_LOCALE=
39
40 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -`
41 CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
42 CFLAGS="${CFLAGS} -Wno-unused-parameter"
43 LDADD=
44 LDFLAGS=
45 LD_NANOSLEEP=
46 LD_OHASH=
47 STATIC="-static"
48
49 BUILD_CGI=0
50 BUILD_CATMAN=0
51 INSTALL_LIBMANDOC=0
52
53 HAVE_DIRENT_NAMLEN=
54 HAVE_EFTYPE=
55 HAVE_ENDIAN=
56 HAVE_ERR=
57 HAVE_FTS=
58 HAVE_FTS_COMPARE_CONST=
59 HAVE_GETLINE=
60 HAVE_GETSUBOPT=
61 HAVE_ISBLANK=
62 HAVE_MKDTEMP=
63 HAVE_NANOSLEEP=
64 HAVE_NTOHL=
65 HAVE_OHASH=
66 HAVE_PATH_MAX=
67 HAVE_PLEDGE=
68 HAVE_PROGNAME=
69 HAVE_REALLOCARRAY=
70 HAVE_REWB_BSD=
71 HAVE_REWB_SYSV=
72 HAVE_SANDBOX_INIT=
73 HAVE_STRCASESTR=
74 HAVE_STRINGLIST=
75 HAVE_STRLCAT=
76 HAVE_STRLCPY=
77 HAVE_STRPTIME=
78 HAVE_STRSEP=
79 HAVE_STRTONUM=
80 HAVE_SYS_ENDIAN=
81 HAVE_VASPRINTF=
82 HAVE_WCHAR=
83
84 PREFIX="/usr/local"
85 BINDIR=
86 SBINDIR=
87 INCLUDEDIR=
88 LIBDIR=
89 MANDIR=
90 HOMEBREWDIR=
91
92 WWWPREFIX="/var/www"
93 HTDOCDIR=
94 CGIBINDIR=
95
96 BINM_APROPOS="apropos"
97 BINM_MAKEWHATIS="makewhatis"
98 BINM_MAN="man"
99 BINM_SOELIM="soelim"
100 BINM_WHATIS="whatis"
101 MANM_MAN="man"
102 MANM_MANCONF="man.conf"
103 MANM_MDOC="mdoc"
104 MANM_ROFF="roff"
105 MANM_EQN="eqn"
106 MANM_TBL="tbl"
107
108 INSTALL="install"
109 INSTALL_PROGRAM=
110 INSTALL_LIB=
111 INSTALL_MAN=
112 INSTALL_DATA=
113
114 # --- manual settings from configure.local -----------------------------
115
116 if [ -r ./configure.local ]; then
117 echo "configure.local: reading..." 1>&2
118 echo "configure.local: reading..." 1>&3
119 cat ./configure.local 1>&3
120 . ./configure.local
121 else
122 echo "configure.local: no (fully automatic configuration)" 1>&2
123 echo "configure.local: no (fully automatic configuration)" 1>&3
124 fi
125 echo 1>&3
126
127 # --- tests for config.h ----------------------------------------------
128
129 COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
130
131 # Check whether this HAVE_ setting is manually overridden.
132 # If yes, use the override, if no, do not decide anything yet.
133 # Arguments: lower-case test name, manual value
134 ismanual() {
135 [ -z "${3}" ] && return 1
136 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
137 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
138 echo 1>&3
139 return 0
140 }
141
142 # Run a single autoconfiguration test.
143 # In case of success, enable the feature.
144 # In case of failure, do not decide anything yet.
145 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
146 singletest() {
147 cat 1>&3 << __HEREDOC__
148 ${1}${3}: testing...
149 ${COMP} -o test-${1} test-${1}.c ${3}
150 __HEREDOC__
151
152 if ${COMP} -o "test-${1}" "test-${1}.c" ${3} 1>&3 2>&3; then
153 echo "${1}${3}: ${CC} succeeded" 1>&3
154 else
155 echo "${1}${3}: ${CC} failed with $?" 1>&3
156 echo 1>&3
157 return 1
158 fi
159
160 if ./test-${1} 1>&3 2>&3; then
161 echo "${1}${3}: yes" 1>&2
162 echo "${1}${3}: yes" 1>&3
163 echo 1>&3
164 eval HAVE_${2}=1
165 rm "test-${1}"
166 return 0
167 else
168 echo "${1}${3}: execution failed with $?" 1>&3
169 echo 1>&3
170 rm "test-${1}"
171 return 1
172 fi
173 }
174
175 # Run a complete autoconfiguration test, including the check for
176 # a manual override and disabling the feature on failure.
177 # Arguments: lower case name, upper case name, additional CFLAGS
178 runtest() {
179 eval _manual=\${HAVE_${2}}
180 ismanual "${1}" "${2}" "${_manual}" && return 0
181 singletest "${1}" "${2}" "${3}" && return 0
182 echo "${1}${3}: no" 1>&2
183 eval HAVE_${2}=0
184 return 1
185 }
186
187 # Select a UTF-8 locale.
188 get_locale() {
189 [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0
190 ismanual UTF8_LOCALE UTF8_LOCALE "$UTF8_LOCALE" && return 0
191 echo "UTF8_LOCALE: testing..." 1>&3
192 UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1`
193 if [ -z "${UTF8_LOCALE}" ]; then
194 UTF8_LOCALE=`locale -a | grep -i '\.UTF-*8' | head -n 1`
195 [ -n "${UTF8_LOCALE}" ] || return 1
196 fi
197 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2
198 echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3
199 echo 1>&3
200 return 0;
201 }
202
203
204 # --- library functions ---
205 runtest dirent-namlen DIRENT_NAMLEN || true
206 runtest be32toh ENDIAN || true
207 runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true
208 runtest EFTYPE EFTYPE || true
209 runtest err ERR || true
210 runtest getline GETLINE || true
211 runtest getsubopt GETSUBOPT || true
212 runtest isblank ISBLANK || true
213 runtest mkdtemp MKDTEMP || true
214 runtest ntohl NTOHL || true
215 runtest PATH_MAX PATH_MAX || true
216 runtest pledge PLEDGE || true
217 runtest sandbox_init SANDBOX_INIT || true
218 runtest progname PROGNAME || true
219 runtest reallocarray REALLOCARRAY || true
220 runtest rewb-bsd REWB_BSD || true
221 runtest rewb-sysv REWB_SYSV || true
222 runtest strcasestr STRCASESTR || true
223 runtest stringlist STRINGLIST || true
224 runtest strlcat STRLCAT || true
225 runtest strlcpy STRLCPY || true
226 runtest strptime STRPTIME || true
227 runtest strsep STRSEP || true
228 runtest strtonum STRTONUM || true
229 runtest vasprintf VASPRINTF || true
230
231 if [ ${HAVE_ENDIAN} -eq 0 -a \
232 ${HAVE_SYS_ENDIAN} -eq 0 -a \
233 ${HAVE_NTOHL} -eq 0 ]; then
234 echo "FATAL: no endian conversion functions found" 1>&2
235 echo "FATAL: no endian conversion functions found" 1>&3
236 exit 1
237 fi
238
239 if ismanual fts FTS ${HAVE_FTS}; then
240 HAVE_FTS_COMPARE_CONST=0
241 elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then
242 HAVE_FTS=1
243 else
244 runtest fts FTS || true
245 fi
246
247 # --- wide character and locale support ---
248 if get_locale; then
249 runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true
250 else
251 HAVE_WCHAR=0
252 echo "wchar: no (no UTF8_LOCALE)" 1>&2
253 echo "wchar: no (no UTF8_LOCALE)" 1>&3
254 fi
255
256 # --- nanosleep ---
257 if [ -n "${LD_NANOSLEEP}" ]; then
258 runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true
259 elif singletest nanosleep NANOSLEEP; then
260 :
261 elif runtest nanosleep NANOSLEEP "-lrt"; then
262 LD_NANOSLEEP="-lrt"
263 fi
264 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
265 echo "FATAL: nanosleep: no" 1>&2
266 echo "FATAL: nanosleep: no" 1>&3
267 exit 1
268 fi
269
270 # --- ohash ---
271 if ismanual ohash OHASH "${HAVE_OHASH}"; then
272 :
273 elif [ -n "${LD_OHASH}" ]; then
274 runtest ohash OHASH "${LD_OHASH}" || true
275 elif singletest ohash OHASH; then
276 :
277 elif runtest ohash OHASH "-lutil"; then
278 LD_OHASH="-lutil"
279 fi
280 if [ "${HAVE_OHASH}" -eq 0 ]; then
281 LD_OHASH=
282 fi
283
284 # --- LDADD ---
285 LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
286 echo "LDADD=\"${LDADD}\"" 1>&2
287 echo "LDADD=\"${LDADD}\"" 1>&3
288 echo 1>&3
289
290 # --- write config.h ---
291
292 exec > config.h
293
294 cat << __HEREDOC__
295 #ifdef __cplusplus
296 #error "Do not use C++. See the INSTALL file."
297 #endif
298
299 #if !defined(__GNUC__) || (__GNUC__ < 4)
300 #define __attribute__(x)
301 #endif
302
303 #if defined(__linux__) || defined(__MINT__)
304 #define _GNU_SOURCE /* See test-*.c what needs this. */
305 #endif
306
307 __HEREDOC__
308
309 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
310 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
311 && echo "#include <sys/types.h>"
312 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
313 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
314
315 echo
316 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
317 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
318 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
319 [ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\""
320 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
321 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
322 [ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096"
323 if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then
324 echo "#define be32toh ntohl"
325 echo "#define htobe32 htonl"
326 fi
327
328 cat << __HEREDOC__
329 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
330 #define HAVE_ENDIAN ${HAVE_ENDIAN}
331 #define HAVE_ERR ${HAVE_ERR}
332 #define HAVE_FTS ${HAVE_FTS}
333 #define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST}
334 #define HAVE_GETLINE ${HAVE_GETLINE}
335 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
336 #define HAVE_ISBLANK ${HAVE_ISBLANK}
337 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
338 #define HAVE_NTOHL ${HAVE_NTOHL}
339 #define HAVE_PLEDGE ${HAVE_PLEDGE}
340 #define HAVE_PROGNAME ${HAVE_PROGNAME}
341 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
342 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
343 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
344 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
345 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
346 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
347 #define HAVE_STRLCAT ${HAVE_STRLCAT}
348 #define HAVE_STRLCPY ${HAVE_STRLCPY}
349 #define HAVE_STRPTIME ${HAVE_STRPTIME}
350 #define HAVE_STRSEP ${HAVE_STRSEP}
351 #define HAVE_STRTONUM ${HAVE_STRTONUM}
352 #define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN}
353 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
354 #define HAVE_WCHAR ${HAVE_WCHAR}
355 #define HAVE_OHASH ${HAVE_OHASH}
356
357 #define BINM_APROPOS "${BINM_APROPOS}"
358 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
359 #define BINM_MAN "${BINM_MAN}"
360 #define BINM_SOELIM "${BINM_SOELIM}"
361 #define BINM_WHATIS "${BINM_WHATIS}"
362
363 __HEREDOC__
364
365 if [ ${HAVE_ERR} -eq 0 ]; then
366 echo "extern void err(int, const char *, ...);"
367 echo "extern void errx(int, const char *, ...);"
368 echo "extern void warn(const char *, ...);"
369 echo "extern void warnx(const char *, ...);"
370 fi
371
372 [ ${HAVE_GETLINE} -eq 0 ] && \
373 echo "extern ssize_t getline(char **, size_t *, FILE *);"
374
375 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
376 echo "extern int getsubopt(char **, char * const *, char **);"
377
378 [ ${HAVE_ISBLANK} -eq 0 ] && \
379 echo "extern int isblank(int);"
380
381 [ ${HAVE_MKDTEMP} -eq 0 ] && \
382 echo "extern char *mkdtemp(char *);"
383
384 if [ ${HAVE_PROGNAME} -eq 0 ]; then
385 echo "extern const char *getprogname(void);"
386 echo "extern void setprogname(const char *);"
387 fi
388
389 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
390 echo "extern void *reallocarray(void *, size_t, size_t);"
391
392 [ ${HAVE_STRCASESTR} -eq 0 ] && \
393 echo "extern char *strcasestr(const char *, const char *);"
394
395 [ ${HAVE_STRLCAT} -eq 0 ] && \
396 echo "extern size_t strlcat(char *, const char *, size_t);"
397
398 [ ${HAVE_STRLCPY} -eq 0 ] && \
399 echo "extern size_t strlcpy(char *, const char *, size_t);"
400
401 [ ${HAVE_STRSEP} -eq 0 ] && \
402 echo "extern char *strsep(char **, const char *);"
403
404 [ ${HAVE_STRTONUM} -eq 0 ] && \
405 echo "extern long long strtonum(const char *, long long, long long, const char **);"
406
407 [ ${HAVE_VASPRINTF} -eq 0 ] && \
408 echo "extern int vasprintf(char **, const char *, va_list);"
409
410 echo "config.h: written" 1>&2
411 echo "config.h: written" 1>&3
412
413 # --- tests for Makefile.local -----------------------------------------
414
415 exec > Makefile.local
416
417 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
418 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
419 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc"
420 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib/mandoc"
421 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
422
423 [ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs"
424 [ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
425
426 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
427 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
428 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
429 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
430
431 BUILD_TARGETS=
432 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="man.cgi"
433 [ ${BUILD_CATMAN} -gt 0 ] && \
434 BUILD_TARGETS="${BUILD_TARGETS} mandocd catman"
435 INSTALL_TARGETS=
436 [ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS="lib-install"
437 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
438 [ ${BUILD_CATMAN} -gt 0 ] && \
439 INSTALL_TARGETS="${INSTALL_TARGETS} catman-install"
440
441 cat << __HEREDOC__
442 BUILD_TARGETS = ${BUILD_TARGETS}
443 INSTALL_TARGETS = ${INSTALL_TARGETS}
444 CC = ${CC}
445 CFLAGS = ${CFLAGS}
446 LDADD = ${LDADD}
447 LDFLAGS = ${LDFLAGS}
448 STATIC = ${STATIC}
449 PREFIX = ${PREFIX}
450 BINDIR = ${BINDIR}
451 SBINDIR = ${SBINDIR}
452 INCLUDEDIR = ${INCLUDEDIR}
453 LIBDIR = ${LIBDIR}
454 MANDIR = ${MANDIR}
455 WWWPREFIX = ${WWWPREFIX}
456 HTDOCDIR = ${HTDOCDIR}
457 CGIBINDIR = ${CGIBINDIR}
458 BINM_APROPOS = ${BINM_APROPOS}
459 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
460 BINM_MAN = ${BINM_MAN}
461 BINM_SOELIM = ${BINM_SOELIM}
462 BINM_WHATIS = ${BINM_WHATIS}
463 MANM_MAN = ${MANM_MAN}
464 MANM_MANCONF = ${MANM_MANCONF}
465 MANM_MDOC = ${MANM_MDOC}
466 MANM_ROFF = ${MANM_ROFF}
467 MANM_EQN = ${MANM_EQN}
468 MANM_TBL = ${MANM_TBL}
469 INSTALL = ${INSTALL}
470 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
471 INSTALL_LIB = ${INSTALL_LIB}
472 INSTALL_MAN = ${INSTALL_MAN}
473 INSTALL_DATA = ${INSTALL_DATA}
474 __HEREDOC__
475
476 echo "Makefile.local: written" 1>&2
477 echo "Makefile.local: written" 1>&3
478
479 exit 0