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