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