Blob


1 #! /bin/sh
2 #
3 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
5 #
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 OCONFIGURE_VERSION="0.3.8"
20 #
21 # This script outputs two files: config.h and Makefile.configure.
22 # It tries to read from configure.local, which contains predefined
23 # values we won't autoconfigure.
24 #
25 # If you want to use configure with your project, have your GNUmakefile
26 # or BSDmakefile---whichever---try to import/include Makefile.configure
27 # at the beginning of the file.
28 #
29 # Like so (note no quotes, no period, etc.):
30 #
31 # include Makefile.configure
32 #
33 # If it exists, configure was run; otherwise, it wasn't.
34 #
35 # You'll probably want to change parts of this file. I've noted the
36 # parts that you'll probably change in the section documentation.
37 #
38 # See https://github.com/kristapsdz/oconfigure for more.
40 set -e
42 # try to be helpful
43 case "$1" in
44 --help|-h)
45 cat <<EOF
46 \`configure' configures amused to adapt to many kinds of systems.
48 Usage: $0 [-h] [--prefix=path] [VAR=VALUE]...
50 The options are as follows:
52 -h, --help print this help message
54 --prefix=path equivalent to specifying the PREFIX variable, supported
55 for compatibility with other common "configure" scripts.
57 Variables available:
59 LDADD generic linker flags
60 LDADD_IMSG linker flags for libimsg
61 LDADD_LIBEVENT linker flags for libevent
62 LDADD_LIBEVENT2 linker flags for libevent2
63 LDADD_LIBFLAC linker flags for libflac
64 LDADD_LIBMPG123 linker flags for libmpg123
65 LDADD_LIBOPUSFILE linker flags for libopusfile
66 LDADD_LIBVORBISFILE linker flags for libvorbisfile
67 LDADD_SNDIO linker flags for libsndio
68 LDADD_LIBSOCKET linker flags for libsocket
69 LDFLAGS extra linker flags
70 CPPFLAGS C preprocessors flags
71 DESTDIR destination directory
72 PREFIX where to install files
73 MANDIR where to install man pages (PREFIX/man)
74 LIBDIR where to install libraries (PREFIX/lib)
75 BINDIR where to install executables (PREFIX/bin)
76 SHAREDIR where to install misc files (PREFIX/share)
77 SBINDIR where to install system executables (PREFIX/sbin)
78 INCLUDEDIR where to install header files (PREFIX/include)
79 PKG_CONFIG path to the pkg-config program or empty to disable
81 Additionally, the following environment variables are used if set:
83 CC the C compiler to use (defaults to cc, clang or gcc)
84 CFLAGS generic C compiler flags
86 EOF
87 exit 0 ;;
88 esac
90 #----------------------------------------------------------------------
91 # Prepare for running: move aside previous configure runs.
92 # Output file descriptor usage:
93 # 1 (stdout): config.h or Makefile.configure
94 # 2 (stderr): original stderr, usually to the console
95 # 3: config.log
96 # You DO NOT want to change this.
97 #----------------------------------------------------------------------
99 [ -w config.log ] && mv config.log config.log.old
100 [ -w config.h ] && mv config.h config.h.old
102 exec 3> config.log
103 echo "config.log: writing..."
105 # GNU submake prints different output if invoked recursively, which
106 # messes up CC and CFLAGS detection. Pass --no-print-directory if
107 # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
108 # allowed.
110 MAKE_FLAGS=""
112 if [ -n "${MAKELEVEL}" ]; then
113 if [ "${MAKELEVEL}" -gt 0 ] ; then
114 MAKE_FLAGS="--no-print-directory"
115 echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
116 fi
117 fi
119 if [ -n "$MAKE_FLAGS" ]; then
120 echo "GNU submake detected: using --no-print-directory" 1>&2
121 echo "GNU submake detected: using --no-print-directory" 1>&3
122 fi
124 #----------------------------------------------------------------------
125 # Initialize all variables here such that nothing can leak in from the
126 # environment except for CC and CFLAGS, which we might have passed in.
127 #----------------------------------------------------------------------
129 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
130 CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
131 CFLAGS="${CFLAGS} -g -W -Wall -Wmissing-prototypes -Wstrict-prototypes"
132 CFLAGS="${CFLAGS} -Wmissing-declarations -Wno-unused-parameter"
133 CFLAGS="${CFLAGS} -Wno-sign-compare"
134 LDADD=
135 LDADD_IMSG=
136 LDADD_LIBEVENT=
137 LDADD_LIBEVENT2=
138 LDADD_LIB_FLAC=
139 LDADD_LIB_MPG123=
140 LDADD_LIB_VORBISFILE=
141 LDADD_LIB_SNDIO=
142 LDADD_LIB_SOCKET=
143 LDADD_STATIC=
144 CPPFLAGS=
145 LDFLAGS=
146 DESTDIR=
147 PREFIX="/usr/local"
148 BINDIR=
149 SBINDIR=
150 INCLUDEDIR=
151 LIBDIR=
152 MANDIR=
153 SHAREDIR=
154 INSTALL="install"
155 INSTALL_PROGRAM=
156 INSTALL_LIB=
157 INSTALL_MAN=
158 INSTALL_DATA=
159 PKG_CONFIG=
161 # SunOS sets "cc", but this doesn't exist.
162 # It does have gcc, so try that instead.
163 # Prefer clang, though.
165 command -v ${CC} 2>/dev/null 1>&2 || {
166 echo "${CC} not found: trying clang" 1>&2
167 echo "${CC} not found: trying clang" 1>&3
168 CC=clang
169 command -v ${CC} 2>/dev/null 1>&2 || {
170 echo "${CC} not found: trying gcc" 1>&2
171 echo "${CC} not found: trying gcc" 1>&3
172 CC=gcc
173 command -v ${CC} 2>/dev/null 1>&2 || {
174 echo "gcc not found: giving up" 1>&2
175 echo "gcc not found: giving up" 1>&3
176 exit 1
181 command -v pkg-config 2>/dev/null 1>&2 && {
182 PKG_CONFIG=pkg-config
183 echo "pkg-config found" 1>&2
184 echo "pkg-config found" 1>&3
185 } || {
186 echo "pkg-config not found" 1>&2
187 echo "pkg-config not found" 1>&3
190 #----------------------------------------------------------------------
191 # Allow certain variables to be overriden on the command line.
192 #----------------------------------------------------------------------
194 while [ $# -gt 0 ]; do
195 key=${1%%=*}
196 val=${1#*=}
198 if [ "$key" = "--prefix" ]; then
199 key=PREFIX
200 if [ "$1" = "--prefix" ]; then
201 if ! shift 2>&1 >/dev/null; then
202 echo "$0: missing value for --prefix" 1>&2
203 exit 1
204 fi
205 val="$1"
206 fi
207 fi
209 if [ "$1" = "$key" ]; then
210 echo "$0: invalid key-value: $1" 1>&2
211 exit 1
212 fi
214 shift
216 case "$key" in
217 LDADD)
218 LDADD="$val" ;;
219 LDADD_IMSG)
220 LDADD_IMSG="$val" ;;
221 LDADD_LIBEVENT)
222 LDADD_LIBEVENT="$val" ;;
223 LDADD_LIBEVENT2)
224 LDADD_LIBEVENT2="$val" ;;
225 LDADD_LIBFLAC)
226 LDADD_LIBFLAC="$val" ;;
227 LDADD_LIBMPG123)
228 LDADD_LIBMPG123="$val" ;;
229 LDADD_LIBOPUSFILE)
230 LDADD_LIBOPUSFILE="$val" ;;
231 LDADD_LIBVORBISFILE)
232 LDADD_LIBVORBISFILE="$val" ;;
233 LDADD_SNDIO)
234 LDADD_SNDIO="$val" ;;
235 LDADD_LIBSOCKET)
236 LDADD_LIBSOCKET="$val" ;;
237 LDFLAGS)
238 LDFLAGS="$val" ;;
239 CPPFLAGS)
240 CPPFLAGS="$val" ;;
241 DESTDIR)
242 DESTDIR="$val" ;;
243 PREFIX)
244 PREFIX="$val" ;;
245 MANDIR)
246 MANDIR="$val" ;;
247 LIBDIR)
248 LIBDIR="$val" ;;
249 BINDIR)
250 BINDIR="$val" ;;
251 SHAREDIR)
252 SHAREDIR="$val" ;;
253 SBINDIR)
254 SBINDIR="$val" ;;
255 INCLUDEDIR)
256 INCLUDEDIR="$val" ;;
257 PKG_CONFIG)
258 PKG_CONFIG="$val" ;;
259 *)
260 echo "$0: invalid key: $key" 1>&2
261 exit 1
262 esac
263 done
266 #----------------------------------------------------------------------
267 # These are the values that will be pushed into config.h after we test
268 # for whether they're supported or not.
269 # Each of these must have a runtest(), below.
270 # Please sort by alpha, for clarity.
271 # You WANT to change this.
272 #----------------------------------------------------------------------
274 HAVE_CAPSICUM=
275 HAVE_ERR=
276 HAVE_EXPLICIT_BZERO=
277 HAVE_FLOCK=
278 HAVE_FREEZERO=
279 HAVE_GETDTABLECOUNT=
280 HAVE_GETEXECNAME=
281 HAVE_GETPROGNAME=
282 HAVE_INFTIM=
283 HAVE_IMSG=
284 HAVE_LANDLOCK=
285 HAVE_LIBEVENT=
286 HAVE_LIBEVENT2=0 # may not be checked, set to zero
287 HAVE_LIB_FLAC=
288 HAVE_LIB_MPG123=
289 HAVE_LIB_OPUSFILE=
290 HAVE_LIB_VORBISFILE=
291 HAVE_LIB_SNDIO=
292 HAVE_LIB_SOCKET=
293 HAVE_MEMMEM=
294 HAVE_MEMRCHR=
295 HAVE_MEMSET_S=
296 HAVE_OPTRESET=
297 HAVE_PATH_MAX=
298 HAVE_PLEDGE=
299 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
300 HAVE_PR_SET_NAME=
301 HAVE_REALLOCARRAY=
302 HAVE_RECALLOCARRAY=
303 HAVE_SANDBOX_INIT=
304 HAVE_SETPROCTITLE=
305 HAVE_SIO_FLUSH=
306 HAVE_SOCK_NONBLOCK=
307 HAVE_STRLCAT=
308 HAVE_STRLCPY=
309 HAVE_STRNDUP=
310 HAVE_STRNLEN=
311 HAVE_STRTONUM=
312 HAVE_SYS_FILE=
313 HAVE_SYS_QUEUE=
314 HAVE_SYSTRACE=0
315 HAVE_UNVEIL=
316 HAVE___PROGNAME=
318 #----------------------------------------------------------------------
319 # Allow configure.local to override all variables, default settings,
320 # command-line arguments, and tested features, above.
321 # You PROBABLY DO NOT want to change this.
322 #----------------------------------------------------------------------
324 if [ -r ./configure.local ]; then
325 echo "configure.local: reading..." 1>&2
326 echo "configure.local: reading..." 1>&3
327 cat ./configure.local 1>&3
328 . ./configure.local
329 else
330 echo "configure.local: no (fully automatic configuration)" 1>&2
331 echo "configure.local: no (fully automatic configuration)" 1>&3
332 fi
334 echo 1>&3
336 #----------------------------------------------------------------------
337 # Infrastructure for running tests.
338 # These consists of a series of functions that will attempt to run the
339 # given test file and record its exit into a HAVE_xxx variable.
340 # You DO NOT want to change this.
341 #----------------------------------------------------------------------
343 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
345 # Check whether this HAVE_ setting is manually overridden.
346 # If yes, use the override, if no, do not decide anything yet.
347 # Arguments: lower-case test name, manual value
349 ismanual() {
350 [ -z "${3}" ] && return 1
351 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
352 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
353 echo 1>&3
354 return 0
357 # Run a single autoconfiguration test.
358 # In case of success, enable the feature.
359 # In case of failure, do not decide anything yet.
360 # Arguments: lower-case test name, upper-case test name, additional
361 # CFLAGS, additional LIBS.
363 singletest() {
364 extralib=""
365 pkgcfs=""
366 pkglib=""
368 cat 1>&3 << __HEREDOC__
369 ${1}: testing...
370 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${4}
371 __HEREDOC__
372 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${4} 1>&3 2>&3; then
373 echo "${1}: ${CC} succeeded" 1>&3
374 else
375 if [ -n "${5}" ] ; then
376 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
377 cat 1>&3 << __HEREDOC__
378 ${1}: testing...
379 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${5}
380 __HEREDOC__
381 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${5} 1>&3 2>&3; then
382 echo "${1}: ${CC} succeeded" 1>&3
383 extralib="(with ${5})"
384 else
385 test -n "${PKG_CONFIG}" -a -n "${6}" && ${PKG_CONFIG} "$6"
386 if [ $? -eq 0 ]; then
387 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
388 pkgcfs=$($PKG_CONFIG --cflags "${6}")
389 pkglib=$($PKG_CONFIG --libs "${6}")
390 cat 1>&3 << __HEREDOC__
391 ${1}: testing...
392 ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib}
393 __HEREDOC__
394 if ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib} 1>&3 2>&3; then
395 echo "${1}: ${CC} succeeded" 1>&3
396 extralib="(with ${pkgcfs} ${pkglib})"
397 else
398 echo "${1}: ${CC} failed with $?" 1>&3
399 echo 1>&3
400 return 1
401 fi
402 else
403 echo "${1}: ${CC} failed with $?" 1>&3
404 echo 1>&3
405 return 1
406 fi
407 fi
408 else
409 echo "${1}: ${CC} failed with $?" 1>&3
410 echo 1>&3
411 return 1
412 fi
413 fi
415 rm -f test-${1}.d
417 if [ -n "${pkgcfs}" -o -n "${pkglib}" ]
418 then
419 CFLAGS="${CFLAGS} ${pkgcfs}"
420 eval "LDADD_${2}=\"${pkglib}\""
421 elif [ -n "${extralib}" ]
422 then
423 eval "LDADD_${2}=\"${5}\""
424 elif [ -n "${4}" ]
425 then
426 eval "LDADD_${2}=\"${4}\""
427 fi
429 echo "${1}: yes ${extralib}" 1>&2
430 echo "${1}: yes ${extralib}" 1>&3
431 echo 1>&3
432 eval HAVE_${2}=1
433 rm "test-${1}"
434 return 0
437 # Run a complete autoconfiguration test, including the check for
438 # a manual override and disabling the feature on failure.
439 # Arguments: lower case name, upper case name, additional CFLAGS,
440 # additional LDADD, alternative LDADD, pkg-config name.
442 runtest() {
443 eval _manual=\${HAVE_${2}}
444 ismanual "${1}" "${2}" "${_manual}" && return 0
445 singletest "${1}" "${2}" "${3}" "${4}" "${5}" "${6}" && return 0
446 echo "${1}: no" 1>&2
447 eval HAVE_${2}=0
448 return 1
451 #----------------------------------------------------------------------
452 # Begin running the tests themselves.
453 # All of your tests must be defined here.
454 # Please sort as the HAVE_xxxx values were defined.
455 # You WANT to change this.
456 # It consists of the following columns:
457 # runtest
458 # (1) test file
459 # (2) macro to set
460 # (3) argument to cc *before* -o
461 # (4) argument to cc *after*
462 # (5) alternative argument to cc *after*
463 # (6) name for pkg-config auto-discovery
464 #----------------------------------------------------------------------
466 if runtest -MMD _MMD -MMD; then
467 CFLAGS="${CFLAGS} -MMD"
468 echo "adding -MMD to CFLAGS" 1>&2
469 echo "adding -MMD to CFLAGS" 1>&3
470 fi
472 runtest capsicum CAPSICUM || true
473 runtest err ERR || true
474 runtest explicit_bzero EXPLICIT_BZERO || true
475 runtest flock FLOCK || true
476 runtest freezero FREEZERO || true
477 runtest getdtablecount GETDTABLECOUNT || true
478 runtest getexecname GETEXECNAME || true
479 runtest getprogname GETPROGNAME || true
480 runtest imsg IMSG "" "" "-lutil" || true
481 runtest INFTIM INFTIM || true
482 runtest landlock LANDLOCK || true
484 runtest libevent LIBEVENT "" "" "-levent" || \
485 runtest libevent2 LIBEVENT2 "" "" "-levent_extra -levent_core" "libevent" || true
487 runtest lib_flac LIB_FLAC "" "" "-lFLAC" "flac" || true
488 runtest lib_mpg123 LIB_MPG123 "" "" "-lmpg123" "libmpg123" || true
489 runtest lib_opusfile LIB_OPUSFILE "" "" "-lopusfile" "opusfile" || true
490 runtest lib_vorbisfile LIB_VORBISFILE "" "" "-lvorbisfile" "vorbisfile" || true
492 runtest lib_sndio LIB_SNDIO "" "" "-lsndio" "sndio" || true
493 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
494 runtest memmem MEMMEM || true
495 runtest memrchr MEMRCHR || true
496 runtest memset_s MEMSET_S || true
497 runtest optreset OPTRESET || true
498 runtest PATH_MAX PATH_MAX || true
499 runtest pledge PLEDGE || true
500 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
501 runtest PR_SET_NAME PR_SET_NAME || true
502 runtest reallocarray REALLOCARRAY || true
503 runtest recallocarray RECALLOCARRAY || true
504 runtest sandbox_init SANDBOX_INIT "-Wno-deprecated" || true
505 runtest setproctitle SETPROCTITLE || true
506 runtest sio_flush SIO_FLUSH "" "" "${LDADD_LIB_SNDIO}" || true
507 runtest SOCK_NONBLOCK SOCK_NONBLOCK || true
508 runtest static STATIC "" "-static" || true
509 runtest strlcat STRLCAT || true
510 runtest strlcpy STRLCPY || true
511 runtest strndup STRNDUP || true
512 runtest strnlen STRNLEN || true
513 runtest strtonum STRTONUM || true
514 runtest sys_queue SYS_QUEUE || true
515 runtest sys_file SYS_FILE || true
516 runtest unveil UNVEIL || true
517 runtest __progname __PROGNAME || true
519 if [ "${HAVE_LIBEVENT}" -eq 0 -a "${HAVE_LIBEVENT2}" -eq 0 ]; then
520 echo "Fatal: missing libevent" 1>&2
521 echo "Fatal: missing libevent" 1>&3
522 exit 1
523 fi
525 if [ "${HAVE_LIB_FLAC}" -eq 0 -o \
526 "${HAVE_LIB_MPG123}" -eq 0 -o \
527 "${HAVE_LIB_OPUSFILE}" -eq 0 -o \
528 "${HAVE_LIB_VORBISFILE}" -eq 0 ]; then
529 echo "Fatal: missing required audio libraries" 1>&2
530 echo "Fatal: missing required audio libraries" 1>&3
531 exit 1
532 fi
534 if [ "${HAVE_LIB_SNDIO}" -eq 0 ]; then
535 echo "Fatal: missing libsndio" 1>&2
536 echo "Fatal: missing libsndio" 1>&3
537 exit 1
538 fi
540 #----------------------------------------------------------------------
541 # Output writing: generate the config.h file.
542 # This file contains all of the HAVE_xxxx variables necessary for
543 # compiling your source.
544 # You must include "config.h" BEFORE any other variables.
545 # You WANT to change this.
546 #----------------------------------------------------------------------
548 exec > config.h
550 # Start with prologue.
552 cat << __HEREDOC__
553 #ifndef OCONFIGURE_CONFIG_H
554 #define OCONFIGURE_CONFIG_H
556 #ifdef __cplusplus
557 # error "Do not use C++: this is a C application."
558 #endif
559 #if !defined(__GNUC__) || (__GNUC__ < 4)
560 # define __attribute__(x)
561 #endif
562 #if defined(__linux__) || defined(__MINT__)
563 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
564 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
565 #endif
566 #if defined(__NetBSD__)
567 # define _OPENBSD_SOURCE /* reallocarray, etc. */
568 #endif
569 #if defined(__sun)
570 # ifndef _XOPEN_SOURCE /* SunOS already defines */
571 # define _XOPEN_SOURCE /* XPGx */
572 # endif
573 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
574 # ifndef __EXTENSIONS__ /* SunOS already defines */
575 # define __EXTENSIONS__ /* reallocarray, etc. */
576 # endif
577 #endif
578 #if !defined(__BEGIN_DECLS)
579 # define __BEGIN_DECLS
580 #endif
581 #if !defined(__END_DECLS)
582 # define __END_DECLS
583 #endif
585 __HEREDOC__
587 # This is just for size_t, mode_t, and dev_t.
588 # Most of these functions, in the real world, pull in <string.h> or
589 # someting that pulls in support for size_t.
590 # Our function declarations are standalone, so specify them here.
592 if [ ${HAVE_IMSG} -eq 0 -o \
593 ${HAVE_MEMMEM} -eq 0 -o \
594 ${HAVE_MEMRCHR} -eq 0 -o \
595 ${HAVE_REALLOCARRAY} -eq 0 -o \
596 ${HAVE_RECALLOCARRAY} -eq 0 -o \
597 ${HAVE_STRLCAT} -eq 0 -o \
598 ${HAVE_STRLCPY} -eq 0 -o \
599 ${HAVE_STRNDUP} -eq 0 -o \
600 ${HAVE_STRNLEN} -eq 0 ]
601 then
602 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
603 echo
604 fi
606 if [ ${HAVE_FLOCK} -eq 0 ]; then
607 if [ ${HAVE_SYS_FILE} -eq 0 ]; then
608 HAVE_FLOCK=1
609 echo "#include <sys/file.h>"
610 echo
611 else
612 echo "int flock(int, int);"
613 echo "#define LOCK_SH 0x1"
614 echo "#define LOCK_EX 0x2"
615 echo "#define LOCK_NB 0x4"
616 echo
617 fi
618 fi
620 if [ ${HAVE_ERR} -eq 0 ]; then
621 echo "#include <stdarg.h> /* err(3) */"
622 echo
623 else
624 echo "#include <err.h>"
625 echo
626 fi
628 if [ ${HAVE_PLEDGE} -eq 0 ]; then
629 echo "#define pledge(p, e) (0)"
630 echo
631 else
632 echo "#include <unistd.h>"
633 echo
634 fi
636 # Now we handle our HAVE_xxxx values.
637 # Most will just be defined as 0 or 1.
639 if [ ${HAVE_PATH_MAX} -eq 0 ]
640 then
641 echo "#define PATH_MAX 4096"
642 echo
643 fi
645 if [ ${HAVE_INFTIM} -eq 0 ]
646 then
647 echo "#define INFTIM (-1) /* poll.h */"
648 echo
649 fi
651 cat << __HEREDOC__
652 /*
653 * Results of configuration feature-testing.
654 */
655 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
656 #define HAVE_ERR ${HAVE_ERR}
657 #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
658 #define HAVE_FLOCK ${HAVE_FLOCK}
659 #define HAVE_FREEZERO ${HAVE_FREEZERO}
660 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
661 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
662 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
663 #define HAVE_INFTIM ${HAVE_INFTIM}
664 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
665 #define HAVE_MEMMEM ${HAVE_MEMMEM}
666 #define HAVE_MEMRCHR ${HAVE_MEMRCHR}
667 #define HAVE_MEMSET_S ${HAVE_MEMSET_S}
668 #define HAVE_OPTRESET ${HAVE_OPTRESET}
669 #define HAVE_PATH_MAX ${HAVE_PATH_MAX}
670 #define HAVE_PLEDGE ${HAVE_PLEDGE}
671 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
672 #define HAVE_PR_SET_NAME ${HAVE_PR_SET_NAME}
673 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
674 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
675 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
676 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
677 #define HAVE_SIO_FLUSH ${HAVE_SIO_FLUSH}
678 #define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
679 #define HAVE_STRLCAT ${HAVE_STRLCAT}
680 #define HAVE_STRLCPY ${HAVE_STRLCPY}
681 #define HAVE_STRNDUP ${HAVE_STRNDUP}
682 #define HAVE_STRNLEN ${HAVE_STRNLEN}
683 #define HAVE_STRTONUM ${HAVE_STRTONUM}
684 #define HAVE_SYS_FILE ${HAVE_SYS_FILE}
685 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
686 #define HAVE_SYSTRACE ${HAVE_SYSTRACE}
687 #define HAVE_UNVEIL ${HAVE_UNVEIL}
688 #define HAVE___PROGNAME ${HAVE___PROGNAME}
690 __HEREDOC__
692 # Now we do our function declarations for missing functions.
694 [ ${HAVE_ERR} -eq 0 ] && \
695 cat << __HEREDOC__
696 /*
697 * Compatibility functions for err(3).
698 */
699 extern void err(int, const char *, ...) __attribute__((noreturn));
700 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
701 extern void errx(int, const char *, ...) __attribute__((noreturn));
702 extern void verr(int, const char *, va_list) __attribute__((noreturn));
703 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
704 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
705 extern void warn(const char *, ...);
706 extern void warnx(const char *, ...);
707 extern void warnc(int, const char *, ...);
708 extern void vwarn(const char *, va_list);
709 extern void vwarnc(int, const char *, va_list);
710 extern void vwarnx(const char *, va_list);
711 __HEREDOC__
713 [ ${HAVE_EXPLICIT_BZERO} -eq 0 ] && \
714 cat << __HEREDOC__
715 /*
716 * Compatibility for explicit_bzero(3).
717 */
718 extern void explicit_bzero(void *, size_t);
720 __HEREDOC__
722 [ ${HAVE_FREEZERO} -eq 0 ] && \
723 cat << __HEREDOC__
724 /*
725 * Compatibility for freezero(3).
726 */
727 extern void freezero(void *, size_t);
729 __HEREDOC__
731 [ ${HAVE_MEMMEM} -eq 0 ] && \
732 cat << __HEREDOC__
733 /*
734 * Compatibility for memmem(3).
735 */
736 void *memmem(const void *, size_t, const void *, size_t);
738 __HEREDOC__
740 [ ${HAVE_MEMRCHR} -eq 0 ] && \
741 cat << __HEREDOC__
742 /*
743 * Compatibility for memrchr(3).
744 */
745 void *memrchr(const void *b, int, size_t);
747 __HEREDOC__
749 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
750 cat << __HEREDOC__
751 /*
752 * Compatibility for getprogname(3).
753 */
754 extern const char *getprogname(void);
756 __HEREDOC__
758 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
759 cat << __HEREDOC__
760 /*
761 * Compatibility for reallocarray(3).
762 */
763 extern void *reallocarray(void *, size_t, size_t);
765 __HEREDOC__
767 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
768 cat << __HEREDOC__
769 /*
770 * Compatibility for recallocarray(3).
771 */
772 extern void *recallocarray(void *, size_t, size_t, size_t);
774 __HEREDOC__
776 [ ${HAVE_SETPROCTITLE} -eq 0 ] && \
777 cat << __HEREDOC__
778 /*
779 * Compatibility for setproctitle(3).
780 */
781 extern void setproctitle(const char *, ...);
783 __HEREDOC__
785 [ ${HAVE_STRLCAT} -eq 0 ] && \
786 cat << __HEREDOC__
787 /*
788 * Compatibility for strlcat(3).
789 */
790 extern size_t strlcat(char *, const char *, size_t);
792 __HEREDOC__
794 [ ${HAVE_STRLCPY} -eq 0 ] && \
795 cat << __HEREDOC__
796 /*
797 * Compatibility for strlcpy(3).
798 */
799 extern size_t strlcpy(char *, const char *, size_t);
801 __HEREDOC__
803 [ ${HAVE_STRNDUP} -eq 0 ] && \
804 cat << __HEREDOC__
805 /*
806 * Compatibility for strndup(3).
807 */
808 extern char *strndup(const char *, size_t);
810 __HEREDOC__
812 [ ${HAVE_STRNLEN} -eq 0 ] && \
813 cat << __HEREDOC__
814 /*
815 * Compatibility for strnlen(3).
816 */
817 extern size_t strnlen(const char *, size_t);
819 __HEREDOC__
821 [ ${HAVE_STRTONUM} -eq 0 ] && \
822 cat << __HEREDOC__
823 /*
824 * Compatibility for strotnum(3).
825 */
826 extern long long strtonum(const char *, long long, long long, const char **);
828 __HEREDOC__
830 if [ ${HAVE_SYS_QUEUE} -eq 0 ]; then
831 cat << __HEREDOC__
832 #include "queue.h"
833 __HEREDOC__
834 else
835 echo "#include <sys/queue.h>"
836 echo
837 fi
839 echo "#include <sys/uio.h>"
840 echo "#include <stdint.h>"
841 if [ ${HAVE_IMSG} -eq 0 ]; then
842 echo "#include \"imsg.h\""
843 else
844 echo "#include <imsg.h>"
845 fi
846 echo
848 if [ "${HAVE_LIBEVENT2}" -eq 1 ]; then
849 cat << __HEREDOC__
850 #include <event2/event.h>
851 #include <event2/event_compat.h>
852 #include <event2/event_struct.h>
853 #include <event2/buffer.h>
854 #include <event2/buffer_compat.h>
855 #include <event2/bufferevent.h>
856 #include <event2/bufferevent_struct.h>
857 #include <event2/bufferevent_compat.h>
859 __HEREDOC__
860 elif [ "${HAVE_LIBEVENT}" -eq 1 ]; then
861 cat << __HEREDOC__
862 #include <event.h>
864 __HEREDOC__
865 fi
867 cat << __HEREDOC__
868 #ifndef __dead
869 # define __dead __attribute__((noreturn))
870 #endif
872 #if !HAVE_SIO_FLUSH
873 #define sio_flush(hdl) (sio_stop(hdl))
874 #endif
876 #if !HAVE_GETDTABLECOUNT
877 /* XXX: on linux it should be possible to inspect /proc/self/fd/ */
878 #define getdtablecount() (0)
879 #endif
881 #if !HAVE_OPTRESET
882 /* replace host' getopt with OpenBSD' one */
883 #define opterr BSDopterr
884 #define optind BSDoptind
885 #define optopt BSDoptopt
886 #define optreset BSDoptreset
887 #define optarg BSDoptarg
888 #define getopt BSDgetopt
890 extern int BSDopterr, BSDoptind, BSDoptopt, BSDoptreset;
891 extern char *BSDoptarg;
892 #endif
894 #endif /*!OCONFIGURE_CONFIG_H*/
895 __HEREDOC__
897 echo "config.h: written" 1>&2
898 echo "config.h: written" 1>&3
900 #----------------------------------------------------------------------
901 # Now we go to generate our Makefile.configure.
902 # This file is simply a bunch of Makefile variables.
903 # They'll work in both GNUmakefile and BSDmakefile.
904 # You MIGHT want to change this.
905 #----------------------------------------------------------------------
907 exec > Makefile.configure
909 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
910 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
911 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
912 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
913 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
914 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
916 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
917 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
918 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
919 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
921 cat << __HEREDOC__
922 CC = ${CC}
923 CFLAGS = ${CFLAGS}
924 CPPFLAGS = ${CPPFLAGS}
925 LDADD = ${LDADD} ${LDADD_IMSG} ${LDADD_LIB_FLAC} ${LDADD_LIB_MPG123} \
926 ${LDADD_LIB_OPUSFILE} ${LDADD_LIB_VORBISFILE} ${LDADD_LIB_SOCKET} \
927 ${LDADD_LIBEVENT} ${LDADD_LIBEVENT2} ${LDADD_LIB_SNDIO}
928 LDADD_STATIC = ${LDADD_STATIC}
929 LDFLAGS = ${LDFLAGS}
930 STATIC = ${STATIC}
931 PREFIX = ${PREFIX}
932 BINDIR = ${BINDIR}
933 SHAREDIR = ${SHAREDIR}
934 SBINDIR = ${SBINDIR}
935 INCLUDEDIR = ${INCLUDEDIR}
936 LIBDIR = ${LIBDIR}
937 MANDIR = ${MANDIR}
938 INSTALL = ${INSTALL}
939 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
940 INSTALL_LIB = ${INSTALL_LIB}
941 INSTALL_MAN = ${INSTALL_MAN}
942 INSTALL_DATA = ${INSTALL_DATA}
943 __HEREDOC__
945 echo "Makefile.configure: written" 1>&2
946 echo "Makefile.configure: written" 1>&3
948 exit 0