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