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