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