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