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