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