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