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