]> git.cameronkatri.com Git - mandoc.git/blob - configure
On a new RS nesting level, the saved width starts from the default
[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_FGETLN=
47 HAVE_FTS=
48 HAVE_GETSUBOPT=
49 HAVE_ISBLANK=
50 HAVE_MKDTEMP=
51 HAVE_MMAP=
52 HAVE_REALLOCARRAY=
53 HAVE_STRCASESTR=
54 HAVE_STRLCAT=
55 HAVE_STRLCPY=
56 HAVE_STRPTIME=
57 HAVE_STRSEP=
58 HAVE_STRTONUM=
59 HAVE_VASPRINTF=
60 HAVE_WCHAR=
61
62 HAVE_SQLITE3=
63 HAVE_SQLITE3_ERRSTR=
64 HAVE_OHASH=
65 HAVE_MANPATH=
66
67 PREFIX="/usr/local"
68 BINDIR=
69 SBINDIR=
70 INCLUDEDIR=
71 LIBDIR=
72 MANDIR=
73 EXAMPLEDIR=
74 HOMEBREWDIR=
75
76 WWWPREFIX="/var/www"
77 HTDOCDIR=
78 CGIBINDIR=
79
80 BINM_APROPOS="apropos"
81 BINM_MAN="man"
82 BINM_WHATIS="whatis"
83 BINM_MAKEWHATIS="makewhatis"
84 MANM_MAN="man"
85 MANM_MANCONF="man.conf"
86 MANM_MDOC="mdoc"
87 MANM_ROFF="roff"
88 MANM_EQN="eqn"
89 MANM_TBL="tbl"
90
91 INSTALL="install"
92 INSTALL_PROGRAM=
93 INSTALL_LIB=
94 INSTALL_MAN=
95 INSTALL_DATA=
96
97 # --- manual settings from configure.local -----------------------------
98
99 if [ -e ./configure.local ]; then
100 echo "configure.local: reading..." 1>&2
101 echo "configure.local: reading..." 1>&3
102 cat ./configure.local 1>&3
103 . ./configure.local
104 else
105 echo "configure.local: no (fully automatic configuration)" 1>&2
106 echo "configure.local: no (fully automatic configuration)" 1>&3
107 fi
108 echo 1>&3
109
110 # --- tests for config.h ----------------------------------------------
111
112 COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
113
114 # Check whether this HAVE_ setting is manually overridden.
115 # If yes, use the override, if no, do not decide anything yet.
116 # Arguments: lower-case test name, manual value
117 ismanual() {
118 [ -z "${2}" ] && return 1
119 echo "${1}: manual (${2})" 1>&2
120 echo "${1}: manual (${2})" 1>&3
121 echo 1>&3
122 return 0
123 }
124
125 # Run a single autoconfiguration test.
126 # In case of success, enable the feature.
127 # In case of failure, do not decide anything yet.
128 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
129 singletest() {
130 cat 1>&3 << __HEREDOC__
131 ${1}: testing...
132 ${COMP} ${3} -o test-${1} test-${1}.c
133 __HEREDOC__
134
135 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
136 echo "${1}: ${CC} succeeded" 1>&3
137 else
138 echo "${1}: ${CC} failed with $?" 1>&3
139 echo 1>&3
140 return 1
141 fi
142
143 if ./test-${1} 1>&3 2>&3; then
144 echo "${1}: yes" 1>&2
145 echo "${1}: yes" 1>&3
146 echo 1>&3
147 eval HAVE_${2}=1
148 rm "test-${1}"
149 return 0
150 else
151 echo "${1}: execution failed with $?" 1>&3
152 echo 1>&3
153 rm "test-${1}"
154 return 1
155 fi
156 }
157
158 # Run a complete autoconfiguration test, including the check for
159 # a manual override and disabling the feature on failure.
160 # Arguments: lower case name, upper case name, additional CFLAGS
161 runtest() {
162 eval _manual=\${HAVE_${2}}
163 ismanual "${1}" "${_manual}" && return 0
164 singletest "${1}" "${2}" "${3}" && return 0
165 echo "${1}: no" 1>&2
166 eval HAVE_${2}=0
167 return 1
168 }
169
170 # --- library functions ---
171 runtest dirent-namlen DIRENT_NAMLEN || true
172 runtest fgetln FGETLN || true
173 runtest fts FTS || true
174 runtest getsubopt GETSUBOPT || true
175 runtest isblank ISBLANK || true
176 runtest mkdtemp MKDTEMP || true
177 runtest mmap MMAP || true
178 runtest reallocarray REALLOCARRAY || true
179 runtest strcasestr STRCASESTR || true
180 runtest strlcat STRLCAT || true
181 runtest strlcpy STRLCPY || true
182 runtest strptime STRPTIME || true
183 runtest strsep STRSEP || true
184 runtest strtonum STRTONUM || true
185 runtest vasprintf VASPRINTF || true
186 runtest wchar WCHAR || true
187
188 # --- sqlite3 ---
189 DETECTLIB=
190 if [ ${BUILD_DB} -eq 0 ]; then
191 echo "BUILD_DB=0 (manual)" 1>&2
192 echo "BUILD_DB=0 (manual)" 1>&3
193 echo 1>&3
194 HAVE_SQLITE3=0
195 elif ismanual sqlite3 "${HAVE_SQLITE3}"; then
196 DETECTLIB="-lsqlite3"
197 elif [ -n "${DBLIB}" ]; then
198 runtest sqlite3 SQLITE3 "${DBLIB}" || true
199 elif singletest sqlite3 SQLITE3 "-lsqlite3"; then
200 DETECTLIB="-lsqlite3"
201 elif runtest sqlite3 SQLITE3 \
202 "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then
203 DETECTLIB="-L/usr/local/lib -lsqlite3"
204 CFLAGS="${CFLAGS} -I/usr/local/include"
205 fi
206 if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then
207 echo "BUILD_DB=0 (no sqlite3)" 1>&2
208 echo "BUILD_DB=0 (no sqlite3)" 1>&3
209 echo 1>&3
210 BUILD_DB=0
211 fi
212
213 # --- sqlite3_errstr ---
214 if [ ${BUILD_DB} -eq 0 ]; then
215 HAVE_SQLITE3_ERRSTR=1
216 elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then
217 :
218 elif [ -n "${DBLIB}" ]; then
219 runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" || true
220 else
221 runtest sqlite3_errstr SQLITE3_ERRSTR "${DETECTLIB}" || true
222 fi
223
224 # --- ohash ---
225 if [ ${BUILD_DB} -eq 0 ]; then
226 HAVE_OHASH=1
227 elif ismanual ohash "${HAVE_OHASH}"; then
228 :
229 elif [ -n "${DBLIB}" ]; then
230 runtest ohash OHASH "${DBLIB}" || true
231 elif singletest ohash OHASH; then
232 :
233 elif runtest ohash OHASH "-lutil"; then
234 DETECTLIB="${DETECTLIB} -lutil"
235 fi
236
237 # --- DBLIB ---
238 if [ ${BUILD_DB} -eq 0 ]; then
239 DBLIB=
240 elif [ -z "${DBLIB}" ]; then
241 DBLIB="${DETECTLIB}"
242 echo "DBLIB=\"${DBLIB}\"" 1>&2
243 echo "DBLIB=\"${DBLIB}\"" 1>&3
244 echo 1>&3
245 fi
246
247 # --- manpath ---
248 if ismanual manpath "${HAVE_MANPATH}"; then
249 :
250 elif manpath 1>&3 2>&3; then
251 echo "manpath: yes" 1>&2
252 echo "manpath: yes" 1>&3
253 echo 1>&3
254 HAVE_MANPATH=1
255 else
256 echo "manpath: no" 1>&2
257 echo "manpath: no" 1>&3
258 echo 1>&3
259 HAVE_MANPATH=0
260 fi
261
262 # --- write config.h ---
263
264 exec > config.h
265
266 cat << __HEREDOC__
267 #ifndef MANDOC_CONFIG_H
268 #define MANDOC_CONFIG_H
269
270 #if defined(__linux__) || defined(__MINT__)
271 #define _GNU_SOURCE /* See test-*.c what needs this. */
272 #endif
273
274 __HEREDOC__
275
276 [ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
277 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
278 && echo "#include <sys/types.h>"
279 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
280 [ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>"
281
282 echo
283 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
284 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
285 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
286 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
287
288 cat << __HEREDOC__
289 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
290 #define HAVE_FGETLN ${HAVE_FGETLN}
291 #define HAVE_FTS ${HAVE_FTS}
292 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
293 #define HAVE_ISBLANK ${HAVE_ISBLANK}
294 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
295 #define HAVE_MMAP ${HAVE_MMAP}
296 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
297 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
298 #define HAVE_STRLCAT ${HAVE_STRLCAT}
299 #define HAVE_STRLCPY ${HAVE_STRLCPY}
300 #define HAVE_STRPTIME ${HAVE_STRPTIME}
301 #define HAVE_STRSEP ${HAVE_STRSEP}
302 #define HAVE_STRTONUM ${HAVE_STRTONUM}
303 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
304 #define HAVE_WCHAR ${HAVE_WCHAR}
305 #define HAVE_SQLITE3 ${HAVE_SQLITE3}
306 #define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR}
307 #define HAVE_OHASH ${HAVE_OHASH}
308 #define HAVE_MANPATH ${HAVE_MANPATH}
309
310 #define BINM_APROPOS "${BINM_APROPOS}"
311 #define BINM_MAN "${BINM_MAN}"
312 #define BINM_WHATIS "${BINM_WHATIS}"
313 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
314
315 #if !defined(__BEGIN_DECLS)
316 # ifdef __cplusplus
317 # define __BEGIN_DECLS extern "C" {
318 # else
319 # define __BEGIN_DECLS
320 # endif
321 #endif
322 #if !defined(__END_DECLS)
323 # ifdef __cplusplus
324 # define __END_DECLS }
325 # else
326 # define __END_DECLS
327 # endif
328 #endif
329
330 __HEREDOC__
331
332 [ ${HAVE_FGETLN} -eq 0 ] && \
333 echo "extern char *fgetln(FILE *, size_t *);"
334
335 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
336 echo "extern int getsubopt(char **, char * const *, char **);"
337
338 [ ${HAVE_ISBLANK} -eq 0 ] && \
339 echo "extern int isblank(int);"
340
341 [ ${HAVE_MKDTEMP} -eq 0 ] && \
342 echo "extern char *mkdtemp(char *);"
343
344 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
345 echo "extern void *reallocarray(void *, size_t, size_t);"
346
347 [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] &&
348 echo "extern const char *sqlite3_errstr(int);"
349
350 [ ${HAVE_STRCASESTR} -eq 0 ] && \
351 echo "extern char *strcasestr(const char *, const char *);"
352
353 [ ${HAVE_STRLCAT} -eq 0 ] && \
354 echo "extern size_t strlcat(char *, const char *, size_t);"
355
356 [ ${HAVE_STRLCPY} -eq 0 ] && \
357 echo "extern size_t strlcpy(char *, const char *, size_t);"
358
359 [ ${HAVE_STRSEP} -eq 0 ] && \
360 echo "extern char *strsep(char **, const char *);"
361
362 [ ${HAVE_STRTONUM} -eq 0 ] && \
363 echo "extern long long strtonum(const char *, long long, long long, const char **);"
364
365 [ ${HAVE_VASPRINTF} -eq 0 ] && \
366 echo "extern int vasprintf(char **, const char *, va_list);"
367
368 echo
369 echo "#endif /* MANDOC_CONFIG_H */"
370
371 echo "config.h: written" 1>&2
372 echo "config.h: written" 1>&3
373
374 # --- tests for Makefile.local -----------------------------------------
375
376 exec > Makefile.local
377
378 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
379 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
380 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc"
381 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib/mandoc"
382 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
383 [ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR="${PREFIX}/share/examples/mandoc"
384
385 [ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs"
386 [ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
387
388 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
389 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
390 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
391 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
392
393 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
394 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
395 echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3
396 BUILD_CGI=0
397 fi
398
399 BUILD_TARGETS="base-build"
400 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build"
401 INSTALL_TARGETS="base-install"
402 [ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} db-install"
403 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install"
404
405 cat << __HEREDOC__
406 BUILD_TARGETS = ${BUILD_TARGETS}
407 INSTALL_TARGETS = ${INSTALL_TARGETS}
408 CC = ${CC}
409 CFLAGS = ${CFLAGS}
410 DBLIB = ${DBLIB}
411 STATIC = ${STATIC}
412 PREFIX = ${PREFIX}
413 BINDIR = ${BINDIR}
414 SBINDIR = ${SBINDIR}
415 INCLUDEDIR = ${INCLUDEDIR}
416 LIBDIR = ${LIBDIR}
417 MANDIR = ${MANDIR}
418 EXAMPLEDIR = ${EXAMPLEDIR}
419 WWWPREFIX = ${WWWPREFIX}
420 HTDOCDIR = ${HTDOCDIR}
421 CGIBINDIR = ${CGIBINDIR}
422 BINM_APROPOS = ${BINM_APROPOS}
423 BINM_MAN = ${BINM_MAN}
424 BINM_WHATIS = ${BINM_WHATIS}
425 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
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 [ ${BUILD_DB} -gt 0 ] && \
440 echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)"
441
442 echo "Makefile.local: written" 1>&2
443 echo "Makefile.local: written" 1>&3
444
445 exit 0