]> git.cameronkatri.com Git - mandoc.git/blob - configure
Autodetect if -lrt is needed for nanosleep(3).
[mandoc.git] / configure
1 #!/bin/sh
2 #
3 # $Id: configure,v 1.47 2016/07/20 14:03:06 schwarze Exp $
4 #
5 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
6 #
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19 set -e
20
21 [ -w config.log ] && mv config.log config.log.old
22 [ -w config.h ] && mv config.h config.h.old
23
24 # Output file descriptor usage:
25 # 1 (stdout): config.h, Makefile.local
26 # 2 (stderr): original stderr, usually to the console
27 # 3: config.log
28
29 exec 3> config.log
30 echo "config.log: writing..."
31
32 # --- default settings -------------------------------------------------
33 # Initialize all variables here,
34 # such that nothing can leak in from the environment.
35
36 MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man"
37 OSNAME=
38
39 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -f -`
40 CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings"
41 CFLAGS="${CFLAGS} -Wno-unused-parameter"
42 LDADD=
43 LDFLAGS=
44 LD_NANOSLEEP=
45 LD_OHASH=
46 STATIC="-static"
47
48 BUILD_CGI=0
49
50 HAVE_DIRENT_NAMLEN=
51 HAVE_EFTYPE=
52 HAVE_ERR=
53 HAVE_FTS=
54 HAVE_GETLINE=
55 HAVE_GETSUBOPT=
56 HAVE_ISBLANK=
57 HAVE_MKDTEMP=
58 HAVE_NANOSLEEP=
59 HAVE_OHASH=
60 HAVE_PLEDGE=
61 HAVE_PROGNAME=
62 HAVE_REALLOCARRAY=
63 HAVE_REWB_BSD=
64 HAVE_REWB_SYSV=
65 HAVE_SANDBOX_INIT=
66 HAVE_STRCASESTR=
67 HAVE_STRINGLIST=
68 HAVE_STRLCAT=
69 HAVE_STRLCPY=
70 HAVE_STRPTIME=
71 HAVE_STRSEP=
72 HAVE_STRTONUM=
73 HAVE_VASPRINTF=
74 HAVE_WCHAR=
75
76 PREFIX="/usr/local"
77 BINDIR=
78 SBINDIR=
79 INCLUDEDIR=
80 LIBDIR=
81 MANDIR=
82 HOMEBREWDIR=
83
84 WWWPREFIX="/var/www"
85 HTDOCDIR=
86 CGIBINDIR=
87
88 BINM_APROPOS="apropos"
89 BINM_MAKEWHATIS="makewhatis"
90 BINM_MAN="man"
91 BINM_SOELIM="soelim"
92 BINM_WHATIS="whatis"
93 MANM_MAN="man"
94 MANM_MANCONF="man.conf"
95 MANM_MDOC="mdoc"
96 MANM_ROFF="roff"
97 MANM_EQN="eqn"
98 MANM_TBL="tbl"
99
100 INSTALL="install"
101 INSTALL_PROGRAM=
102 INSTALL_LIB=
103 INSTALL_MAN=
104 INSTALL_DATA=
105
106 # --- manual settings from configure.local -----------------------------
107
108 if [ -r ./configure.local ]; then
109 echo "configure.local: reading..." 1>&2
110 echo "configure.local: reading..." 1>&3
111 cat ./configure.local 1>&3
112 . ./configure.local
113 else
114 echo "configure.local: no (fully automatic configuration)" 1>&2
115 echo "configure.local: no (fully automatic configuration)" 1>&3
116 fi
117 echo 1>&3
118
119 # --- tests for config.h ----------------------------------------------
120
121 COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
122
123 # Check whether this HAVE_ setting is manually overridden.
124 # If yes, use the override, if no, do not decide anything yet.
125 # Arguments: lower-case test name, manual value
126 ismanual() {
127 [ -z "${2}" ] && return 1
128 echo "${1}: manual (${2})" 1>&2
129 echo "${1}: manual (${2})" 1>&3
130 echo 1>&3
131 return 0
132 }
133
134 # Run a single autoconfiguration test.
135 # In case of success, enable the feature.
136 # In case of failure, do not decide anything yet.
137 # Arguments: lower-case test name, upper-case test name, additional CFLAGS
138 singletest() {
139 cat 1>&3 << __HEREDOC__
140 ${1}: testing...
141 ${COMP} ${3} -o test-${1} test-${1}.c
142 __HEREDOC__
143
144 if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then
145 echo "${1}: ${CC} succeeded" 1>&3
146 else
147 echo "${1}: ${CC} failed with $?" 1>&3
148 echo 1>&3
149 return 1
150 fi
151
152 if ./test-${1} 1>&3 2>&3; then
153 echo "${1}: yes" 1>&2
154 echo "${1}: yes" 1>&3
155 echo 1>&3
156 eval HAVE_${2}=1
157 rm "test-${1}"
158 return 0
159 else
160 echo "${1}: execution failed with $?" 1>&3
161 echo 1>&3
162 rm "test-${1}"
163 return 1
164 fi
165 }
166
167 # Run a complete autoconfiguration test, including the check for
168 # a manual override and disabling the feature on failure.
169 # Arguments: lower case name, upper case name, additional CFLAGS
170 runtest() {
171 eval _manual=\${HAVE_${2}}
172 ismanual "${1}" "${_manual}" && return 0
173 singletest "${1}" "${2}" "${3}" && return 0
174 echo "${1}: no" 1>&2
175 eval HAVE_${2}=0
176 return 1
177 }
178
179 # --- library functions ---
180 runtest dirent-namlen DIRENT_NAMLEN || true
181 runtest EFTYPE EFTYPE || true
182 runtest err ERR || true
183 runtest fts FTS || true
184 runtest getline GETLINE || true
185 runtest getsubopt GETSUBOPT || true
186 runtest isblank ISBLANK || true
187 runtest mkdtemp MKDTEMP || true
188 runtest pledge PLEDGE || true
189 runtest sandbox_init SANDBOX_INIT || true
190 runtest progname PROGNAME || true
191 runtest reallocarray REALLOCARRAY || true
192 runtest rewb-bsd REWB_BSD || true
193 runtest rewb-sysv REWB_SYSV || true
194 runtest strcasestr STRCASESTR || true
195 runtest stringlist STRINGLIST || true
196 runtest strlcat STRLCAT || true
197 runtest strlcpy STRLCPY || true
198 runtest strptime STRPTIME || true
199 runtest strsep STRSEP || true
200 runtest strtonum STRTONUM || true
201 runtest vasprintf VASPRINTF || true
202 runtest wchar WCHAR || true
203
204 # --- nanosleep ---
205 if [ -n "${LD_NANOSLEEP}" ]; then
206 runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true
207 elif singletest nanosleep NANOSLEEP; then
208 :
209 elif runtest nanosleep NANOSLEEP "-lrt"; then
210 LD_NANOSLEEP="-lrt"
211 fi
212 if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
213 echo "FATAL: nanosleep: no" 1>&2
214 echo "FATAL: nanosleep: no" 1>&3
215 exit 1
216 fi
217
218 # --- ohash ---
219 if ismanual ohash "${HAVE_OHASH}"; then
220 :
221 elif [ -n "${LD_OHASH}" ]; then
222 runtest ohash OHASH "${LD_OHASH}" || true
223 elif singletest ohash OHASH; then
224 :
225 elif runtest ohash OHASH "-lutil"; then
226 LD_OHASH="-lutil"
227 fi
228 if [ "${HAVE_OHASH}" -eq 0 ]; then
229 LD_OHASH=
230 fi
231
232 # --- LDADD ---
233 LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
234 echo "LDADD=\"${LDADD}\"" 1>&2
235 echo "LDADD=\"${LDADD}\"" 1>&3
236 echo 1>&3
237
238 # --- write config.h ---
239
240 exec > config.h
241
242 cat << __HEREDOC__
243 #ifdef __cplusplus
244 #error "Do not use C++. See the INSTALL file."
245 #endif
246
247 #if !defined(__GNUC__) || (__GNUC__ < 4)
248 #define __attribute__(x)
249 #endif
250
251 #if defined(__linux__) || defined(__MINT__)
252 #define _GNU_SOURCE /* See test-*.c what needs this. */
253 #endif
254
255 __HEREDOC__
256
257 [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \
258 ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \
259 && echo "#include <sys/types.h>"
260 [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
261 [ ${HAVE_GETLINE} -eq 0 ] && echo "#include <stdio.h>"
262
263 echo
264 echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\""
265 echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\""
266 [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\""
267 [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\""
268 [ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL"
269
270 cat << __HEREDOC__
271 #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN}
272 #define HAVE_ERR ${HAVE_ERR}
273 #define HAVE_FTS ${HAVE_FTS}
274 #define HAVE_GETLINE ${HAVE_GETLINE}
275 #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT}
276 #define HAVE_ISBLANK ${HAVE_ISBLANK}
277 #define HAVE_MKDTEMP ${HAVE_MKDTEMP}
278 #define HAVE_PLEDGE ${HAVE_PLEDGE}
279 #define HAVE_PROGNAME ${HAVE_PROGNAME}
280 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
281 #define HAVE_REWB_BSD ${HAVE_REWB_BSD}
282 #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV}
283 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
284 #define HAVE_STRCASESTR ${HAVE_STRCASESTR}
285 #define HAVE_STRINGLIST ${HAVE_STRINGLIST}
286 #define HAVE_STRLCAT ${HAVE_STRLCAT}
287 #define HAVE_STRLCPY ${HAVE_STRLCPY}
288 #define HAVE_STRPTIME ${HAVE_STRPTIME}
289 #define HAVE_STRSEP ${HAVE_STRSEP}
290 #define HAVE_STRTONUM ${HAVE_STRTONUM}
291 #define HAVE_VASPRINTF ${HAVE_VASPRINTF}
292 #define HAVE_WCHAR ${HAVE_WCHAR}
293 #define HAVE_OHASH ${HAVE_OHASH}
294
295 #define BINM_APROPOS "${BINM_APROPOS}"
296 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
297 #define BINM_MAN "${BINM_MAN}"
298 #define BINM_SOELIM "${BINM_SOELIM}"
299 #define BINM_WHATIS "${BINM_WHATIS}"
300
301 __HEREDOC__
302
303 if [ ${HAVE_ERR} -eq 0 ]; then
304 echo "extern void err(int, const char *, ...);"
305 echo "extern void errx(int, const char *, ...);"
306 echo "extern void warn(const char *, ...);"
307 echo "extern void warnx(const char *, ...);"
308 fi
309
310 [ ${HAVE_GETLINE} -eq 0 ] && \
311 echo "extern ssize_t getline(char **, size_t *, FILE *);"
312
313 [ ${HAVE_GETSUBOPT} -eq 0 ] && \
314 echo "extern int getsubopt(char **, char * const *, char **);"
315
316 [ ${HAVE_ISBLANK} -eq 0 ] && \
317 echo "extern int isblank(int);"
318
319 [ ${HAVE_MKDTEMP} -eq 0 ] && \
320 echo "extern char *mkdtemp(char *);"
321
322 if [ ${HAVE_PROGNAME} -eq 0 ]; then
323 echo "extern const char *getprogname(void);"
324 echo "extern void setprogname(const char *);"
325 fi
326
327 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
328 echo "extern void *reallocarray(void *, size_t, size_t);"
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 [ ${HAVE_VASPRINTF} -eq 0 ] && \
346 echo "extern int vasprintf(char **, const char *, va_list);"
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
361 [ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs"
362 [ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
363
364 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
365 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
366 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
367 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
368
369 BUILD_TARGETS=
370 [ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="cgi-build"
371 INSTALL_TARGETS=
372 [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="cgi-install"
373
374 cat << __HEREDOC__
375 BUILD_TARGETS = ${BUILD_TARGETS}
376 INSTALL_TARGETS = ${INSTALL_TARGETS}
377 CC = ${CC}
378 CFLAGS = ${CFLAGS}
379 LDADD = ${LDADD}
380 LDFLAGS = ${LDFLAGS}
381 STATIC = ${STATIC}
382 PREFIX = ${PREFIX}
383 BINDIR = ${BINDIR}
384 SBINDIR = ${SBINDIR}
385 INCLUDEDIR = ${INCLUDEDIR}
386 LIBDIR = ${LIBDIR}
387 MANDIR = ${MANDIR}
388 WWWPREFIX = ${WWWPREFIX}
389 HTDOCDIR = ${HTDOCDIR}
390 CGIBINDIR = ${CGIBINDIR}
391 BINM_APROPOS = ${BINM_APROPOS}
392 BINM_MAKEWHATIS = ${BINM_MAKEWHATIS}
393 BINM_MAN = ${BINM_MAN}
394 BINM_SOELIM = ${BINM_SOELIM}
395 BINM_WHATIS = ${BINM_WHATIS}
396 MANM_MAN = ${MANM_MAN}
397 MANM_MANCONF = ${MANM_MANCONF}
398 MANM_MDOC = ${MANM_MDOC}
399 MANM_ROFF = ${MANM_ROFF}
400 MANM_EQN = ${MANM_EQN}
401 MANM_TBL = ${MANM_TBL}
402 INSTALL = ${INSTALL}
403 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
404 INSTALL_LIB = ${INSTALL_LIB}
405 INSTALL_MAN = ${INSTALL_MAN}
406 INSTALL_DATA = ${INSTALL_DATA}
407 __HEREDOC__
408
409 echo "Makefile.local: written" 1>&2
410 echo "Makefile.local: written" 1>&3
411
412 exit 0