]> git.cameronkatri.com Git - mandoc.git/blob - configure
In ./configure, select a RE syntax for word boundaries supported by libc;
[mandoc.git] / configure
1 #!/bin/sh
2 #
3 # Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 set -e
18
19 [ -e config.log ] && mv config.log config.log.old
20 [ -e config.h ] && mv config.h config.h.old
21
22 # Output file descriptor usage:
23 # 1 (stdout): config.h, Makefile.local
24 # 2 (stderr): original stderr, usually to the console
25 # 3: config.log
26
27 exec 3> config.log
28 echo "config.log: writing..."
29
30 # --- default settings -------------------------------------------------
31 # Initialize all variables here,
32 # such that nothing can leak in from the environment.
33
34 MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
35 OSNAME=
36
37 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
38 CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
39 DBLIB=
40 STATIC="-static"
41
42 BUILD_DB=1
43 BUILD_CGI=0
44
45 HAVE_DIRENT_NAMLEN=
46 HAVE_ERR=
47 HAVE_FGETLN=
48 HAVE_FTS=
49 HAVE_GETSUBOPT=
50 HAVE_ISBLANK=
51 HAVE_MKDTEMP=
52 HAVE_MMAP=
53 HAVE_PLEDGE=
54 HAVE_PROGNAME=
55 HAVE_REALLOCARRAY=
56 HAVE_REWB_BSD=
57 HAVE_REWB_SYSV=
58 HAVE_STRCASESTR=
59 HAVE_STRINGLIST=
60 HAVE_STRLCAT=
61 HAVE_STRLCPY=
62 HAVE_STRPTIME=
63 HAVE_STRSEP=
64 HAVE_STRTONUM=
65 HAVE_VASPRINTF=
66 HAVE_WCHAR=
67
68 HAVE_SQLITE3=
69 HAVE_SQLITE3_ERRSTR=
70 HAVE_OHASH=
71 HAVE_MANPATH=
72
73 PREFIX="/usr/local"
74 BINDIR=
75 SBINDIR=
76 INCLUDEDIR=
77 LIBDIR=
78 MANDIR=
79 EXAMPLEDIR=
80 HOMEBREWDIR=
81
82 WWWPREFIX="/var/www"
83 HTDOCDIR=
84 CGIBINDIR=
85
86 BINM_APROPOS="apropos"
87 BINM_MAKEWHATIS="makewhatis"
88 BINM_MAN="man"
89 BINM_SOELIM="soelim"
90 BINM_WHATIS="whatis"
91 MANM_MAN="man"
92 MANM_MANCONF="man.conf"
93 MANM_MDOC="mdoc"
94 MANM_ROFF="roff"
95 MANM_EQN="eqn"
96 MANM_TBL="tbl"
97
98 INSTALL="install"
99 INSTALL_PROGRAM=
100 INSTALL_LIB=
101 INSTALL_MAN=
102 INSTALL_DATA=
103
104 # --- manual settings from configure.local -----------------------------
105
106 if [ -e ./configure.local ]; then
107 echo "configure.local: reading..." 1>&2
108 echo "configure.local: reading..." 1>&3
109 cat ./configure.local 1>&3
110 . ./configure.local
111 else
112 echo "configure.local: no (fully automatic configuration)" 1>&2
113 echo "configure.local: no (fully automatic configuration)" 1>&3
114 fi
115 echo 1>&3
116
117 # --- tests for config.h ----------------------------------------------
118
119 COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
120
121 # Check whether this HAVE_ setting is manually overridden.
122 # If yes, use the override, if no, do not decide anything yet.
123 # Arguments: lower-case test name, manual value
124 ismanual() {
125 [ -z "${2}" ] && return 1
126 echo "${1}: manual (${2})" 1>&2
127 echo "${1}: manual (${2})" 1>&3
128 echo 1>&3
129 return 0
130 }
131
132 # Run a single autoconfiguration test.
133 # In case of success, enable the feature.
134 # In case of failure, do not decide anything yet.
135 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
136 singletest() {
137 cat 1>&3 << __HEREDOC__
138 ${1}: testing...
139 ${COMP} ${3} -o test-${1} test-${1}.c
140 __HEREDOC__
141
142 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
143 echo "${1}: ${CC} succeeded" 1>&3
144 else
145 echo "${1}: ${CC} failed with $?" 1>&3
146 echo 1>&3
147 return 1
148 fi
149
150 if ./test-${1} 1>&3 2>&3; then
151 echo "${1}: yes" 1>&2
152 echo "${1}: yes" 1>&3
153 echo 1>&3
154 eval HAVE_${2}=1
155 rm "test-${1}"
156 return 0
157 else
158 echo "${1}: execution failed with $?" 1>&3
159 echo 1>&3
160 rm "test-${1}"
161 return 1
162 fi
163 }
164
165 # Run a complete autoconfiguration test, including the check for
166 # a manual override and disabling the feature on failure.
167 # Arguments: lower case name, upper case name, additional CFLAGS
168 runtest() {
169 eval _manual=\${HAVE_${2}}
170 ismanual "${1}" "${_manual}" && return 0
171 singletest "${1}" "${2}" "${3}" && return 0
172 echo "${1}: no" 1>&2
173 eval HAVE_${2}=0
174 return 1
175 }
176
177 # --- library functions ---
178 runtest dirent-namlen DIRENT_NAMLEN || true
179 runtest err ERR || true
180 runtest fgetln FGETLN || true
181 runtest fts FTS || true
182 runtest getsubopt GETSUBOPT || true
183 runtest isblank ISBLANK || true
184 runtest mkdtemp MKDTEMP || true
185 runtest mmap MMAP || true
186 runtest pledge PLEDGE || true
187 runtest progname PROGNAME || true
188 runtest reallocarray REALLOCARRAY || true
189 runtest rewb-bsd REWB_BSD || true
190 runtest rewb-sysv REWB_SYSV || true
191 runtest strcasestr STRCASESTR || true
192 runtest stringlist STRINGLIST || true
193 runtest strlcat STRLCAT || true
194 runtest strlcpy STRLCPY || true
195 runtest strptime STRPTIME || true
196 runtest strsep STRSEP || true
197 runtest strtonum STRTONUM || true
198 runtest vasprintf VASPRINTF || true
199 runtest wchar WCHAR || true
200
201 # --- sqlite3 ---
202 DETECTLIB=
203 if [ ${BUILD_DB} -eq 0 ]; then
204 echo "BUILD_DB=0 (manual)" 1>&2
205 echo "BUILD_DB=0 (manual)" 1>&3
206 echo 1>&3
207 HAVE_SQLITE3=0
208 elif ismanual sqlite3 "${HAVE_SQLITE3}"; then
209 DETECTLIB="-lsqlite3"
210 elif [ -n "${DBLIB}" ]; then
211 runtest sqlite3 SQLITE3 "${DBLIB}" || true
212 elif singletest sqlite3 SQLITE3 "-lsqlite3"; then
213 DETECTLIB="-lsqlite3"
214 elif runtest sqlite3 SQLITE3 \
215 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
216 DETECTLIB="-L/usr/local/lib -lsqlite3"
217 CFLAGS="${CFLAGS} -I/usr/local/include"
218 fi
219 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
220 echo "BUILD_DB=0 (no sqlite3)" 1>&2
221 echo "BUILD_DB=0 (no sqlite3)" 1>&3
222 echo 1>&3
223 BUILD_DB=0
224 fi
225
226 # --- sqlite3_errstr ---
227 if [ ${BUILD_DB} -eq 0 ]; then
228 HAVE_SQLITE3_ERRSTR=1
229 elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then
230 :
231 elif [ -n "${DBLIB}" ]; then
232 runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" || true
233 else
234 runtest sqlite3_errstr SQLITE3_ERRSTR "${DETECTLIB}" || true
235 fi
236
237 # --- ohash ---
238 if [ ${BUILD_DB} -eq 0 ]; then
239 HAVE_OHASH=1
240 elif ismanual ohash "${HAVE_OHASH}"; then
241 :
242 elif [ -n "${DBLIB}" ]; then
243 runtest ohash OHASH "${DBLIB}" || true
244 elif singletest ohash OHASH; then
245 :
246 elif runtest ohash OHASH "-lutil"; then
247 DETECTLIB="${DETECTLIB} -lutil"
248 fi
249
250 # --- DBLIB ---
251 if [ ${BUILD_DB} -eq 0 ]; then
252 DBLIB="-lz"
253 elif [ -z "${DBLIB}" ]; then
254 DBLIB="${DETECTLIB} -lz"
255 echo "DBLIB=\"${DBLIB}\"" 1>&2
256 echo "DBLIB=\"${DBLIB}\"" 1>&3
257 echo 1>&3
258 fi
259
260 # --- manpath ---
261 if ismanual manpath "${HAVE_MANPATH}"; then
262 :
263 elif manpath 1>&3 2>&3; then
264 echo "manpath: yes" 1>&2
265 echo "manpath: yes" 1>&3
266 echo 1>&3
267 HAVE_MANPATH=1
268 else
269 echo "manpath: no" 1>&2
270 echo "manpath: no" 1>&3
271 echo 1>&3
272 HAVE_MANPATH=0
273 fi
274
275 # --- write config.h ---
276
277 exec > config.h
278
279 cat << __HEREDOC__
280 #ifndef MANDOC_CONFIG_H
281 #define MANDOC_CONFIG_H
282
283 #if defined(__linux__) || defined(__MINT__)
284 #define _GNU_SOURCE /* See test-*.c what needs this. */
285 #endif
286
287 __HEREDOC__
288
289 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
290 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
291 && echo "#include <sys/types.h>"
292 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
293 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
294
295 echo
296 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
297 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
298 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
299 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
300
301 cat << __HEREDOC__
302 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
303 #define HAVE_ERR ${HAVE_ERR}
304 #define HAVE_FGETLN ${HAVE_FGETLN}
305 #define HAVE_FTS ${HAVE_FTS}
306 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
307 #define HAVE_ISBLANK ${HAVE_ISBLANK}
308 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
309 #define HAVE_MMAP ${HAVE_MMAP}
310 #define HAVE_PLEDGE ${HAVE_PLEDGE}
311 #define HAVE_PROGNAME ${HAVE_PROGNAME}
312 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
313 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
314 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
315 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
316 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
317 #define HAVE_STRLCAT ${HAVE_STRLCAT}
318 #define HAVE_STRLCPY ${HAVE_STRLCPY}
319 #define HAVE_STRPTIME ${HAVE_STRPTIME}
320 #define HAVE_STRSEP ${HAVE_STRSEP}
321 #define HAVE_STRTONUM ${HAVE_STRTONUM}
322 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
323 #define HAVE_WCHAR ${HAVE_WCHAR}
324 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
325 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
326 #define HAVE_OHASH ${HAVE_OHASH}
327 #define HAVE_MANPATH ${HAVE_MANPATH}
328
329 #define BINM_APROPOS "${BINM_APROPOS}"
330 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
331 #define BINM_MAN "${BINM_MAN}"
332 #define BINM_SOELIM "${BINM_SOELIM}"
333 #define BINM_WHATIS "${BINM_WHATIS}"
334
335 #if !defined(__BEGIN_DECLS)
336 # ifdef __cplusplus
337 # define __BEGIN_DECLS extern "C" {
338 # else
339 # define __BEGIN_DECLS
340 # endif
341 #endif
342 #if !defined(__END_DECLS)
343 # ifdef __cplusplus
344 # define __END_DECLS }
345 # else
346 # define __END_DECLS
347 # endif
348 #endif
349
350 __HEREDOC__
351
352 if [ ${HAVE_ERR} -eq 0 ]; then
353 echo "extern void err(int, const char *, ...);"
354 echo "extern void warn(const char *, ...);"
355 echo "extern void warnx(const char *, ...);"
356 fi
357
358 [ ${HAVE_FGETLN} -eq 0 ] && \
359 echo "extern char *fgetln(FILE *, size_t *);"
360
361 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
362 echo "extern int getsubopt(char **, char * const *, char **);"
363
364 [ ${HAVE_ISBLANK} -eq 0 ] && \
365 echo "extern int isblank(int);"
366
367 [ ${HAVE_MKDTEMP} -eq 0 ] && \
368 echo "extern char *mkdtemp(char *);"
369
370 if [ ${HAVE_PROGNAME} -eq 0 ]; then
371 echo "extern const char *getprogname(void);"
372 echo "extern void setprogname(const char *);"
373 fi
374
375 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
376 echo "extern void *reallocarray(void *, size_t, size_t);"
377
378 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
379 echo "extern const char *sqlite3_errstr(int);"
380
381 [ ${HAVE_STRCASESTR} -eq 0 ] && \
382 echo "extern char *strcasestr(const char *, const char *);"
383
384 [ ${HAVE_STRLCAT} -eq 0 ] && \
385 echo "extern size_t strlcat(char *, const char *, size_t);"
386
387 [ ${HAVE_STRLCPY} -eq 0 ] && \
388 echo "extern size_t strlcpy(char *, const char *, size_t);"
389
390 [ ${HAVE_STRSEP} -eq 0 ] && \
391 echo "extern char *strsep(char **, const char *);"
392
393 [ ${HAVE_STRTONUM} -eq 0 ] && \
394 echo "extern long long strtonum(const char *, long long, long long, const char **);"
395
396 [ ${HAVE_VASPRINTF} -eq 0 ] && \
397 echo "extern int vasprintf(char **, const char *, va_list);"
398
399 echo
400 echo "#endif /* MANDOC_CONFIG_H */"
401
402 echo "config.h: written" 1>&2
403 echo "config.h: written" 1>&3
404
405 # --- tests for Makefile.local -----------------------------------------
406
407 exec > Makefile.local
408
409 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
410 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
411 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc"
412 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib/mandoc"
413 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
414 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR="${PREFIX}/share/examples/mandoc"
415
416 [ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs"
417 [ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
418
419 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
420 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
421 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
422 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
423
424 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
425 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
426 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
427 BUILD_CGI=0
428 fi
429
430 BUILD_TARGETS="base-build"
431 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build"
432 INSTALL_TARGETS="base-install"
433 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} db-install"
434 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
435
436 cat << __HEREDOC__
437 BUILD_TARGETS = ${BUILD_TARGETS}
438 INSTALL_TARGETS = ${INSTALL_TARGETS}
439 CC = ${CC}
440 CFLAGS = ${CFLAGS}
441 DBLIB = ${DBLIB}
442 STATIC = ${STATIC}
443 PREFIX = ${PREFIX}
444 BINDIR = ${BINDIR}
445 SBINDIR = ${SBINDIR}
446 INCLUDEDIR = ${INCLUDEDIR}
447 LIBDIR = ${LIBDIR}
448 MANDIR = ${MANDIR}
449 EXAMPLEDIR = ${EXAMPLEDIR}
450 WWWPREFIX = ${WWWPREFIX}
451 HTDOCDIR = ${HTDOCDIR}
452 CGIBINDIR = ${CGIBINDIR}
453 BINM_APROPOS = ${BINM_APROPOS}
454 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
455 BINM_MAN = ${BINM_MAN}
456 BINM_SOELIM = ${BINM_SOELIM}
457 BINM_WHATIS = ${BINM_WHATIS}
458 MANM_MAN = ${MANM_MAN}
459 MANM_MANCONF = ${MANM_MANCONF}
460 MANM_MDOC = ${MANM_MDOC}
461 MANM_ROFF = ${MANM_ROFF}
462 MANM_EQN = ${MANM_EQN}
463 MANM_TBL = ${MANM_TBL}
464 INSTALL = ${INSTALL}
465 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
466 INSTALL_LIB = ${INSTALL_LIB}
467 INSTALL_MAN = ${INSTALL_MAN}
468 INSTALL_DATA = ${INSTALL_DATA}
469 __HEREDOC__
470
471 [ ${BUILD_DB} -gt 0 ] && \
472 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
473
474 echo "Makefile.local: written" 1>&2
475 echo "Makefile.local: written" 1>&3
476
477 exit 0