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