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