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