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 # Copyright (c) 2022, 2023 Omar Polo <op@omarpolo.com>
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.
19 OCONFIGURE_VERSION="0.3.8"
21 #
22 # This script outputs two files: config.h and Makefile.configure.
23 # It tries to read from configure.local, which contains predefined
24 # values we won't autoconfigure.
25 #
26 # If you want to use configure with your project, have your GNUmakefile
27 # or BSDmakefile---whichever---try to import/include Makefile.configure
28 # at the beginning of the file.
29 #
30 # Like so (note no quotes, no period, etc.):
31 #
32 # include Makefile.configure
33 #
34 # If it exists, configure was run; otherwise, it wasn't.
35 #
36 # You'll probably want to change parts of this file. I've noted the
37 # parts that you'll probably change in the section documentation.
38 #
39 # See https://github.com/kristapsdz/oconfigure for more.
41 set -e
43 # try to be helpful
44 case "$1" in
45 --help|-h)
46 cat <<EOF
47 \`configure' configures amused to adapt to many kinds of systems.
49 Usage: $0 [-h] [--prefix=path] [VAR=VALUE]...
51 The options are as follows:
53 -h, --help print this help message
55 --prefix=path equivalent to specify the PREFIX variable, supported
56 for compatibility with other common "configure" scripts.
58 --backend=name equivalent to specify the BACKEND variable, can be either
59 "sndio" or "alsa".
61 Variables available:
63 BACKEND audio backend to use; can be "sndio" or "alsa"
64 LDADD generic linker flags
65 LDADD_IMSG linker flags for libimsg
66 LDADD_LIBEVENT linker flags for libevent
67 LDADD_LIBEVENT2 linker flags for libevent2
68 LDADD_LIBFLAC linker flags for libflac
69 LDADD_LIBMPG123 linker flags for libmpg123
70 LDADD_LIBOPUSFILE linker flags for libopusfile
71 LDADD_LIBVORBISFILE linker flags for libvorbisfile
72 LDADD_SNDIO linker flags for libsndio
73 LDADD_LIBSOCKET linker flags for libsocket
74 LDFLAGS extra linker flags
75 CPPFLAGS C preprocessors flags
76 DESTDIR destination directory
77 PREFIX where to install files
78 MANDIR where to install man pages (PREFIX/man)
79 LIBDIR where to install libraries (PREFIX/lib)
80 BINDIR where to install executables (PREFIX/bin)
81 SHAREDIR where to install misc files (PREFIX/share)
82 SBINDIR where to install system executables (PREFIX/sbin)
83 INCLUDEDIR where to install header files (PREFIX/include)
84 PKG_CONFIG pkg-config program, \`false' to disable (pkg-config)
86 Additionally, the following environment variables are used if set:
88 CC the C compiler to use (defaults to cc, clang or gcc)
89 CFLAGS generic C compiler flags
91 EOF
92 exit 0 ;;
93 esac
95 #----------------------------------------------------------------------
96 # Prepare for running: move aside previous configure runs.
97 # Output file descriptor usage:
98 # 1 (stdout): config.h or Makefile.configure
99 # 2 (stderr): original stderr, usually to the console
100 # 3: config.log
101 # You DO NOT want to change this.
102 #----------------------------------------------------------------------
104 [ -w config.log ] && mv config.log config.log.old
105 [ -w config.h ] && mv config.h config.h.old
107 exec 3> config.log
108 echo "config.log: writing..."
110 # GNU submake prints different output if invoked recursively, which
111 # messes up CC and CFLAGS detection. Pass --no-print-directory if
112 # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
113 # allowed.
115 MAKE_FLAGS=""
117 if [ -n "${MAKELEVEL}" ]; then
118 if [ "${MAKELEVEL}" -gt 0 ] ; then
119 MAKE_FLAGS="--no-print-directory"
120 echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
121 fi
122 fi
124 if [ -n "$MAKE_FLAGS" ]; then
125 echo "GNU submake detected: using --no-print-directory" 1>&2
126 echo "GNU submake detected: using --no-print-directory" 1>&3
127 fi
129 #----------------------------------------------------------------------
130 # Initialize all variables here such that nothing can leak in from the
131 # environment except for CC and CFLAGS, which we might have passed in.
132 #----------------------------------------------------------------------
134 BACKEND=auto
135 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
136 CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
137 CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes"
138 CFLAGS="${CFLAGS} -Wstrict-prototypes -Wmissing-declarations"
139 CFLAGS="${CFLAGS} -Wno-unused-parameter -Wno-sign-compare"
140 LDADD=
141 LDADD_IMSG=
142 LDADD_LIBEVENT=
143 LDADD_LIBEVENT2=
144 LDADD_LIB_FLAC=
145 LDADD_LIB_MPG123=
146 LDADD_LIB_VORBISFILE=
147 LDADD_LIB_ASOUND=
148 LDADD_LIB_SNDIO=
149 LDADD_LIB_SOCKET=
150 LDADD_STATIC=
151 CPPFLAGS=
152 LDFLAGS=
153 DESTDIR=
154 PREFIX="/usr/local"
155 BINDIR=
156 SBINDIR=
157 INCLUDEDIR=
158 LIBDIR=
159 MANDIR=
160 SHAREDIR=
161 INSTALL="install"
162 INSTALL_PROGRAM=
163 INSTALL_LIB=
164 INSTALL_MAN=
165 INSTALL_DATA=
166 PKG_CONFIG=
168 # SunOS sets "cc", but this doesn't exist.
169 # It does have gcc, so try that instead.
170 # Prefer clang, though.
172 command -v ${CC} 2>/dev/null 1>&2 || {
173 echo "${CC} not found: trying clang" 1>&2
174 echo "${CC} not found: trying clang" 1>&3
175 CC=clang
176 command -v ${CC} 2>/dev/null 1>&2 || {
177 echo "${CC} not found: trying gcc" 1>&2
178 echo "${CC} not found: trying gcc" 1>&3
179 CC=gcc
180 command -v ${CC} 2>/dev/null 1>&2 || {
181 echo "gcc not found: giving up" 1>&2
182 echo "gcc not found: giving up" 1>&3
183 exit 1
188 command -v pkg-config 2>/dev/null 1>&2 && {
189 PKG_CONFIG=pkg-config
190 echo "pkg-config found" 1>&2
191 echo "pkg-config found" 1>&3
192 } || {
193 echo "pkg-config not found" 1>&2
194 echo "pkg-config not found" 1>&3
197 #----------------------------------------------------------------------
198 # Allow certain variables to be overriden on the command line.
199 #----------------------------------------------------------------------
201 while [ $# -gt 0 ]; do
202 key=${1%%=*}
203 val=${1#*=}
205 if [ "$key" = "--prefix" ]; then
206 key=PREFIX
207 if [ "$1" = "--prefix" ]; then
208 if ! shift 2>&1 >/dev/null; then
209 echo "$0: missing value for --prefix" 1>&2
210 exit 1
211 fi
212 val="$1"
213 fi
214 fi
216 if [ "$key" = "--backend" ]; then
217 key=BACKEND
218 if [ "$1" = "--backend" ]; then
219 if ! shift 2>&1 >/dev/null; then
220 echo "$0 missing value for --backend" 1>&2
221 exit 1
222 fi
223 val="$1"
224 fi
225 fi
227 if [ "$1" = "$key" ]; then
228 echo "$0: invalid key-value: $1" 1>&2
229 exit 1
230 fi
232 shift
234 case "$key" in
235 BACKEND)
236 case "$val" in
237 alsa) BACKEND=alsa ;;
238 sndio) BACKEND=sndio ;;
239 *)
240 echo "unknown audio backend: $val" 1>&2
241 exit 1
242 esac ;;
243 LDADD)
244 LDADD="$val" ;;
245 LDADD_IMSG)
246 LDADD_IMSG="$val" ;;
247 LDADD_LIBEVENT)
248 LDADD_LIBEVENT="$val" ;;
249 LDADD_LIBEVENT2)
250 LDADD_LIBEVENT2="$val" ;;
251 LDADD_LIBFLAC)
252 LDADD_LIBFLAC="$val" ;;
253 LDADD_LIBMPG123)
254 LDADD_LIBMPG123="$val" ;;
255 LDADD_LIBOPUSFILE)
256 LDADD_LIBOPUSFILE="$val" ;;
257 LDADD_LIBVORBISFILE)
258 LDADD_LIBVORBISFILE="$val" ;;
259 LDADD_SNDIO)
260 LDADD_SNDIO="$val" ;;
261 LDADD_LIBSOCKET)
262 LDADD_LIBSOCKET="$val" ;;
263 LDFLAGS)
264 LDFLAGS="$val" ;;
265 CPPFLAGS)
266 CPPFLAGS="$val" ;;
267 DESTDIR)
268 DESTDIR="$val" ;;
269 PREFIX)
270 PREFIX="$val" ;;
271 MANDIR)
272 MANDIR="$val" ;;
273 LIBDIR)
274 LIBDIR="$val" ;;
275 BINDIR)
276 BINDIR="$val" ;;
277 SHAREDIR)
278 SHAREDIR="$val" ;;
279 SBINDIR)
280 SBINDIR="$val" ;;
281 INCLUDEDIR)
282 INCLUDEDIR="$val" ;;
283 PKG_CONFIG)
284 PKG_CONFIG="$val" ;;
285 *)
286 echo "$0: invalid key: $key" 1>&2
287 exit 1
288 esac
289 done
292 #----------------------------------------------------------------------
293 # These are the values that will be pushed into config.h after we test
294 # for whether they're supported or not.
295 # Each of these must have a runtest(), below.
296 # Please sort by alpha, for clarity.
297 # You WANT to change this.
298 #----------------------------------------------------------------------
300 HAVE_CAPSICUM=
301 HAVE_ERR=
302 HAVE_EXPLICIT_BZERO=
303 HAVE_FLOCK=
304 HAVE_FREEZERO=
305 HAVE_GETDTABLECOUNT=
306 HAVE_GETEXECNAME=
307 HAVE_GETPROGNAME=
308 HAVE_INFTIM=
309 HAVE_IMSG=
310 HAVE_LANDLOCK=
311 HAVE_LIBEVENT=
312 HAVE_LIBEVENT2=0 # may not be checked, set to zero
313 HAVE_LIB_FLAC=
314 HAVE_LIB_MPG123=
315 HAVE_LIB_OPUSFILE=
316 HAVE_LIB_VORBISFILE=
317 HAVE_LIB_ASOUND=
318 HAVE_LIB_SNDIO=
319 HAVE_LIB_SOCKET=
320 HAVE_MEMMEM=
321 HAVE_MEMRCHR=
322 HAVE_MEMSET_S=
323 HAVE_OPTRESET=
324 HAVE_PATH_MAX=
325 HAVE_PLEDGE=
326 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
327 HAVE_PR_SET_NAME=
328 HAVE_REALLOCARRAY=
329 HAVE_RECALLOCARRAY=
330 HAVE_SANDBOX_INIT=
331 HAVE_SETPROCTITLE=
332 HAVE_SIO_FLUSH=
333 HAVE_SOCK_NONBLOCK=
334 HAVE_STRLCAT=
335 HAVE_STRLCPY=
336 HAVE_STRNDUP=
337 HAVE_STRNLEN=
338 HAVE_STRTONUM=
339 HAVE_SYS_FILE=
340 HAVE_SYS_QUEUE=
341 HAVE_SYSTRACE=0
342 HAVE_UNVEIL=
343 HAVE___PROGNAME=
345 #----------------------------------------------------------------------
346 # Allow configure.local to override all variables, default settings,
347 # command-line arguments, and tested features, above.
348 # You PROBABLY DO NOT want to change this.
349 #----------------------------------------------------------------------
351 if [ -r ./configure.local ]; then
352 echo "configure.local: reading..." 1>&2
353 echo "configure.local: reading..." 1>&3
354 cat ./configure.local 1>&3
355 . ./configure.local
356 else
357 echo "configure.local: no (fully automatic configuration)" 1>&2
358 echo "configure.local: no (fully automatic configuration)" 1>&3
359 fi
361 echo 1>&3
363 #----------------------------------------------------------------------
364 # Infrastructure for running tests.
365 # These consists of a series of functions that will attempt to run the
366 # given test file and record its exit into a HAVE_xxx variable.
367 # You DO NOT want to change this.
368 #----------------------------------------------------------------------
370 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
372 # Check whether this HAVE_ setting is manually overridden.
373 # If yes, use the override, if no, do not decide anything yet.
374 # Arguments: lower-case test name, manual value
376 ismanual() {
377 [ -z "${3}" ] && return 1
378 echo "${1}: manual (HAVE_${2}=${3})" 1>&2
379 echo "${1}: manual (HAVE_${2}=${3})" 1>&3
380 echo 1>&3
381 return 0
384 # Run a single autoconfiguration test.
385 # In case of success, enable the feature.
386 # In case of failure, do not decide anything yet.
387 # Arguments: lower-case test name, upper-case test name, additional
388 # CFLAGS, additional LIBS.
390 singletest() {
391 extralib=""
392 pkgcfs=""
393 pkglib=""
395 cat 1>&3 << __HEREDOC__
396 ${1}: testing...
397 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${4}
398 __HEREDOC__
399 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${4} 1>&3 2>&3; then
400 echo "${1}: ${CC} succeeded" 1>&3
401 else
402 if [ -n "${5}" ] ; then
403 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
404 cat 1>&3 << __HEREDOC__
405 ${1}: testing...
406 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${5}
407 __HEREDOC__
408 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${5} 1>&3 2>&3; then
409 echo "${1}: ${CC} succeeded" 1>&3
410 extralib="(with ${5})"
411 else
412 test -n "${PKG_CONFIG}" -a -n "${6}" && ${PKG_CONFIG} "$6"
413 if [ $? -eq 0 ]; then
414 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
415 pkgcfs=$($PKG_CONFIG --cflags "${6}")
416 pkglib=$($PKG_CONFIG --libs "${6}")
417 cat 1>&3 << __HEREDOC__
418 ${1}: testing...
419 ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib}
420 __HEREDOC__
421 if ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib} 1>&3 2>&3; then
422 echo "${1}: ${CC} succeeded" 1>&3
423 extralib="(with ${pkgcfs} ${pkglib})"
424 else
425 echo "${1}: ${CC} failed with $?" 1>&3
426 echo 1>&3
427 return 1
428 fi
429 else
430 echo "${1}: ${CC} failed with $?" 1>&3
431 echo 1>&3
432 return 1
433 fi
434 fi
435 else
436 echo "${1}: ${CC} failed with $?" 1>&3
437 echo 1>&3
438 return 1
439 fi
440 fi
442 rm -f test-${1}.d
444 if [ -n "${pkgcfs}" -o -n "${pkglib}" ]
445 then
446 CFLAGS="${CFLAGS} ${pkgcfs}"
447 eval "LDADD_${2}=\"${pkglib}\""
448 elif [ -n "${extralib}" ]
449 then
450 eval "LDADD_${2}=\"${5}\""
451 elif [ -n "${4}" ]
452 then
453 eval "LDADD_${2}=\"${4}\""
454 fi
456 echo "${1}: yes ${extralib}" 1>&2
457 echo "${1}: yes ${extralib}" 1>&3
458 echo 1>&3
459 eval HAVE_${2}=1
460 rm "test-${1}"
461 return 0
464 # Run a complete autoconfiguration test, including the check for
465 # a manual override and disabling the feature on failure.
466 # Arguments: lower case name, upper case name, additional CFLAGS,
467 # additional LDADD, alternative LDADD, pkg-config name.
469 runtest() {
470 eval _manual=\${HAVE_${2}}
471 ismanual "${1}" "${2}" "${_manual}" && return 0
472 singletest "${1}" "${2}" "${3}" "${4}" "${5}" "${6}" && return 0
473 echo "${1}: no" 1>&2
474 eval HAVE_${2}=0
475 return 1
478 #----------------------------------------------------------------------
479 # Begin running the tests themselves.
480 # All of your tests must be defined here.
481 # Please sort as the HAVE_xxxx values were defined.
482 # You WANT to change this.
483 # It consists of the following columns:
484 # runtest
485 # (1) test file
486 # (2) macro to set
487 # (3) argument to cc *before* -o
488 # (4) argument to cc *after*
489 # (5) alternative argument to cc *after*
490 # (6) name for pkg-config auto-discovery
491 #----------------------------------------------------------------------
493 if runtest -MMD _MMD -MMD; then
494 CFLAGS="${CFLAGS} -MMD"
495 echo "adding -MMD to CFLAGS" 1>&2
496 echo "adding -MMD to CFLAGS" 1>&3
497 fi
499 runtest capsicum CAPSICUM || true
500 runtest err ERR || true
501 runtest explicit_bzero EXPLICIT_BZERO || true
502 runtest flock FLOCK || true
503 runtest freezero FREEZERO || true
504 runtest getdtablecount GETDTABLECOUNT || true
505 runtest getexecname GETEXECNAME || true
506 runtest getprogname GETPROGNAME || true
507 runtest imsg IMSG "" "" "-lutil" || true
508 runtest INFTIM INFTIM || true
509 runtest landlock LANDLOCK || true
511 runtest libevent LIBEVENT "" "" "-levent" || \
512 runtest libevent2 LIBEVENT2 "" "" "-levent_extra -levent_core" "libevent" || true
514 runtest lib_flac LIB_FLAC "" "" "-lFLAC" "flac" || true
515 runtest lib_mpg123 LIB_MPG123 "" "" "-lmpg123" "libmpg123" || true
516 runtest lib_opusfile LIB_OPUSFILE "" "" "-lopusfile" "opusfile" || true
517 runtest lib_vorbisfile LIB_VORBISFILE "" "" "-lvorbisfile" "vorbisfile" || true
519 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
520 runtest memmem MEMMEM || true
521 runtest memrchr MEMRCHR || true
522 runtest memset_s MEMSET_S || true
523 runtest optreset OPTRESET || true
524 runtest PATH_MAX PATH_MAX || true
525 runtest pledge PLEDGE || true
526 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
527 runtest PR_SET_NAME PR_SET_NAME || true
528 runtest reallocarray REALLOCARRAY || true
529 runtest recallocarray RECALLOCARRAY || true
530 runtest sandbox_init SANDBOX_INIT "-Wno-deprecated" || true
531 runtest setproctitle SETPROCTITLE || true
532 runtest SOCK_NONBLOCK SOCK_NONBLOCK || true
533 runtest static STATIC "" "-static" || true
534 runtest strlcat STRLCAT || true
535 runtest strlcpy STRLCPY || true
536 runtest strndup STRNDUP || true
537 runtest strnlen STRNLEN || true
538 runtest strtonum STRTONUM || true
539 runtest sys_queue SYS_QUEUE || true
540 runtest sys_file SYS_FILE || true
541 runtest unveil UNVEIL || true
542 runtest __progname __PROGNAME || true
544 if [ $BACKEND != alsa ]; then # auto or sndio
545 runtest lib_sndio LIB_SNDIO "" "" "-lsndio" "sndio" || true
546 runtest sio_flush SIO_FLUSH "" "" "${LDADD_LIB_SNDIO}" || true
548 if [ "${HAVE_LIB_SNDIO}" -eq 0 ]; then
549 if [ $BACKEND = sndio ]; then
550 echo "Fatal: missing libsndio" 1>&2
551 echo "Fatal: missing libsndio" 1>&3
552 exit 1
553 fi
554 else
555 BACKEND=sndio
556 fi
557 else
558 HAVE_SIO_FLUSH=0
559 fi
561 if [ $BACKEND != sndio ]; then # auto or alsa
562 runtest lib_asound LIB_ASOUND "" "" "-lasound" "alsa" || true
563 if [ "${HAVE_LIB_ASOUND}" -eq 0 ]; then
564 if [ $BACKEND = alsa ]; then
565 echo "Fatal: missing libasound" 1>&2
566 echo "Fatal: missing libasound" 1>&3
567 else
568 echo "Fatal: missing libasound or libsndio" 1>&2
569 echo "Fatal: missing libasound or libsndio" 1>&3
570 fi
571 exit 1
572 fi
573 BACKEND=alsa
574 fi
576 if [ "${HAVE_LIBEVENT}" -eq 0 -a "${HAVE_LIBEVENT2}" -eq 0 ]; then
577 echo "Fatal: missing libevent" 1>&2
578 echo "Fatal: missing libevent" 1>&3
579 exit 1
580 fi
582 if [ "${HAVE_LIB_FLAC}" -eq 0 -o \
583 "${HAVE_LIB_MPG123}" -eq 0 -o \
584 "${HAVE_LIB_OPUSFILE}" -eq 0 -o \
585 "${HAVE_LIB_VORBISFILE}" -eq 0 ]; then
586 echo "Fatal: missing required audio libraries" 1>&2
587 echo "Fatal: missing required audio libraries" 1>&3
588 exit 1
589 fi
591 #----------------------------------------------------------------------
592 # Output writing: generate the config.h file.
593 # This file contains all of the HAVE_xxxx variables necessary for
594 # compiling your source.
595 # You must include "config.h" BEFORE any other variables.
596 # You WANT to change this.
597 #----------------------------------------------------------------------
599 exec > config.h
601 # Start with prologue.
603 cat << __HEREDOC__
604 #ifndef OCONFIGURE_CONFIG_H
605 #define OCONFIGURE_CONFIG_H
607 #ifdef __cplusplus
608 # error "Do not use C++: this is a C application."
609 #endif
610 #if !defined(__GNUC__) || (__GNUC__ < 4)
611 # define __attribute__(x)
612 #endif
613 #if defined(__linux__) || defined(__MINT__)
614 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
615 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
616 #endif
617 #if defined(__NetBSD__)
618 # define _OPENBSD_SOURCE /* reallocarray, etc. */
619 #endif
620 #if defined(__sun)
621 # ifndef _XOPEN_SOURCE /* SunOS already defines */
622 # define _XOPEN_SOURCE /* XPGx */
623 # endif
624 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
625 # ifndef __EXTENSIONS__ /* SunOS already defines */
626 # define __EXTENSIONS__ /* reallocarray, etc. */
627 # endif
628 #endif
629 #if !defined(__BEGIN_DECLS)
630 # define __BEGIN_DECLS
631 #endif
632 #if !defined(__END_DECLS)
633 # define __END_DECLS
634 #endif
636 __HEREDOC__
638 # This is just for size_t, mode_t, and dev_t.
639 # Most of these functions, in the real world, pull in <string.h> or
640 # someting that pulls in support for size_t.
641 # Our function declarations are standalone, so specify them here.
643 if [ ${HAVE_IMSG} -eq 0 -o \
644 ${HAVE_MEMMEM} -eq 0 -o \
645 ${HAVE_MEMRCHR} -eq 0 -o \
646 ${HAVE_REALLOCARRAY} -eq 0 -o \
647 ${HAVE_RECALLOCARRAY} -eq 0 -o \
648 ${HAVE_STRLCAT} -eq 0 -o \
649 ${HAVE_STRLCPY} -eq 0 -o \
650 ${HAVE_STRNDUP} -eq 0 -o \
651 ${HAVE_STRNLEN} -eq 0 ]
652 then
653 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
654 echo
655 fi
657 if [ ${HAVE_FLOCK} -eq 0 ]; then
658 if [ ${HAVE_SYS_FILE} -eq 0 ]; then
659 HAVE_FLOCK=1
660 echo "#include <sys/file.h>"
661 echo
662 else
663 echo "int flock(int, int);"
664 echo "#define LOCK_SH 0x1"
665 echo "#define LOCK_EX 0x2"
666 echo "#define LOCK_NB 0x4"
667 echo
668 fi
669 fi
671 if [ ${HAVE_ERR} -eq 0 ]; then
672 echo "#include <stdarg.h> /* err(3) */"
673 echo
674 else
675 echo "#include <err.h>"
676 echo
677 fi
679 if [ ${HAVE_PLEDGE} -eq 0 ]; then
680 echo "#define pledge(p, e) (0)"
681 echo
682 else
683 echo "#include <unistd.h>"
684 echo
685 fi
687 # Now we handle our HAVE_xxxx values.
688 # Most will just be defined as 0 or 1.
690 if [ ${HAVE_PATH_MAX} -eq 0 ]
691 then
692 echo "#define PATH_MAX 4096"
693 echo
694 fi
696 if [ ${HAVE_INFTIM} -eq 0 ]
697 then
698 echo "#define INFTIM (-1) /* poll.h */"
699 echo
700 fi
702 cat << __HEREDOC__
703 /*
704 * Results of configuration feature-testing.
705 */
706 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
707 #define HAVE_ERR ${HAVE_ERR}
708 #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
709 #define HAVE_FLOCK ${HAVE_FLOCK}
710 #define HAVE_FREEZERO ${HAVE_FREEZERO}
711 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
712 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
713 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
714 #define HAVE_INFTIM ${HAVE_INFTIM}
715 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
716 #define HAVE_MEMMEM ${HAVE_MEMMEM}
717 #define HAVE_MEMRCHR ${HAVE_MEMRCHR}
718 #define HAVE_MEMSET_S ${HAVE_MEMSET_S}
719 #define HAVE_OPTRESET ${HAVE_OPTRESET}
720 #define HAVE_PATH_MAX ${HAVE_PATH_MAX}
721 #define HAVE_PLEDGE ${HAVE_PLEDGE}
722 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
723 #define HAVE_PR_SET_NAME ${HAVE_PR_SET_NAME}
724 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
725 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
726 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
727 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
728 #define HAVE_SIO_FLUSH ${HAVE_SIO_FLUSH}
729 #define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
730 #define HAVE_STRLCAT ${HAVE_STRLCAT}
731 #define HAVE_STRLCPY ${HAVE_STRLCPY}
732 #define HAVE_STRNDUP ${HAVE_STRNDUP}
733 #define HAVE_STRNLEN ${HAVE_STRNLEN}
734 #define HAVE_STRTONUM ${HAVE_STRTONUM}
735 #define HAVE_SYS_FILE ${HAVE_SYS_FILE}
736 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
737 #define HAVE_SYSTRACE ${HAVE_SYSTRACE}
738 #define HAVE_UNVEIL ${HAVE_UNVEIL}
739 #define HAVE___PROGNAME ${HAVE___PROGNAME}
741 __HEREDOC__
743 # Now we do our function declarations for missing functions.
745 [ ${HAVE_ERR} -eq 0 ] && \
746 cat << __HEREDOC__
747 /*
748 * Compatibility functions for err(3).
749 */
750 extern void err(int, const char *, ...) __attribute__((noreturn));
751 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
752 extern void errx(int, const char *, ...) __attribute__((noreturn));
753 extern void verr(int, const char *, va_list) __attribute__((noreturn));
754 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
755 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
756 extern void warn(const char *, ...);
757 extern void warnx(const char *, ...);
758 extern void warnc(int, const char *, ...);
759 extern void vwarn(const char *, va_list);
760 extern void vwarnc(int, const char *, va_list);
761 extern void vwarnx(const char *, va_list);
762 __HEREDOC__
764 [ ${HAVE_EXPLICIT_BZERO} -eq 0 ] && \
765 cat << __HEREDOC__
766 /*
767 * Compatibility for explicit_bzero(3).
768 */
769 extern void explicit_bzero(void *, size_t);
771 __HEREDOC__
773 [ ${HAVE_FREEZERO} -eq 0 ] && \
774 cat << __HEREDOC__
775 /*
776 * Compatibility for freezero(3).
777 */
778 extern void freezero(void *, size_t);
780 __HEREDOC__
782 [ ${HAVE_MEMMEM} -eq 0 ] && \
783 cat << __HEREDOC__
784 /*
785 * Compatibility for memmem(3).
786 */
787 void *memmem(const void *, size_t, const void *, size_t);
789 __HEREDOC__
791 [ ${HAVE_MEMRCHR} -eq 0 ] && \
792 cat << __HEREDOC__
793 /*
794 * Compatibility for memrchr(3).
795 */
796 void *memrchr(const void *b, int, size_t);
798 __HEREDOC__
800 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
801 cat << __HEREDOC__
802 /*
803 * Compatibility for getprogname(3).
804 */
805 extern const char *getprogname(void);
807 __HEREDOC__
809 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
810 cat << __HEREDOC__
811 /*
812 * Compatibility for reallocarray(3).
813 */
814 extern void *reallocarray(void *, size_t, size_t);
816 __HEREDOC__
818 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
819 cat << __HEREDOC__
820 /*
821 * Compatibility for recallocarray(3).
822 */
823 extern void *recallocarray(void *, size_t, size_t, size_t);
825 __HEREDOC__
827 [ ${HAVE_SETPROCTITLE} -eq 0 ] && \
828 cat << __HEREDOC__
829 /*
830 * Compatibility for setproctitle(3).
831 */
832 extern void setproctitle(const char *, ...);
834 __HEREDOC__
836 [ ${HAVE_STRLCAT} -eq 0 ] && \
837 cat << __HEREDOC__
838 /*
839 * Compatibility for strlcat(3).
840 */
841 extern size_t strlcat(char *, const char *, size_t);
843 __HEREDOC__
845 [ ${HAVE_STRLCPY} -eq 0 ] && \
846 cat << __HEREDOC__
847 /*
848 * Compatibility for strlcpy(3).
849 */
850 extern size_t strlcpy(char *, const char *, size_t);
852 __HEREDOC__
854 [ ${HAVE_STRNDUP} -eq 0 ] && \
855 cat << __HEREDOC__
856 /*
857 * Compatibility for strndup(3).
858 */
859 extern char *strndup(const char *, size_t);
861 __HEREDOC__
863 [ ${HAVE_STRNLEN} -eq 0 ] && \
864 cat << __HEREDOC__
865 /*
866 * Compatibility for strnlen(3).
867 */
868 extern size_t strnlen(const char *, size_t);
870 __HEREDOC__
872 [ ${HAVE_STRTONUM} -eq 0 ] && \
873 cat << __HEREDOC__
874 /*
875 * Compatibility for strotnum(3).
876 */
877 extern long long strtonum(const char *, long long, long long, const char **);
879 __HEREDOC__
881 if [ ${HAVE_SYS_QUEUE} -eq 0 ]; then
882 cat << __HEREDOC__
883 #include "queue.h"
884 __HEREDOC__
885 else
886 echo "#include <sys/queue.h>"
887 echo
888 fi
890 echo "#include <sys/uio.h>"
891 echo "#include <stdint.h>"
892 if [ ${HAVE_IMSG} -eq 0 ]; then
893 echo "#include \"imsg.h\""
894 else
895 echo "#include <imsg.h>"
896 fi
897 echo
899 if [ "${HAVE_LIBEVENT2}" -eq 1 ]; then
900 cat << __HEREDOC__
901 #include <event2/event.h>
902 #include <event2/event_compat.h>
903 #include <event2/event_struct.h>
904 #include <event2/buffer.h>
905 #include <event2/buffer_compat.h>
906 #include <event2/bufferevent.h>
907 #include <event2/bufferevent_struct.h>
908 #include <event2/bufferevent_compat.h>
910 __HEREDOC__
911 elif [ "${HAVE_LIBEVENT}" -eq 1 ]; then
912 cat << __HEREDOC__
913 #include <event.h>
915 __HEREDOC__
916 fi
918 cat << __HEREDOC__
919 #ifndef __dead
920 # define __dead __attribute__((noreturn))
921 #endif
923 #if !HAVE_SIO_FLUSH
924 #define sio_flush(hdl) (sio_stop(hdl))
925 #endif
927 #if !HAVE_GETDTABLECOUNT
928 /* XXX: on linux it should be possible to inspect /proc/self/fd/ */
929 #define getdtablecount() (0)
930 #endif
932 #if !HAVE_OPTRESET
933 /* replace host' getopt with OpenBSD' one */
934 #define opterr BSDopterr
935 #define optind BSDoptind
936 #define optopt BSDoptopt
937 #define optreset BSDoptreset
938 #define optarg BSDoptarg
939 #define getopt BSDgetopt
941 extern int BSDopterr, BSDoptind, BSDoptopt, BSDoptreset;
942 extern char *BSDoptarg;
943 #endif
945 #endif /*!OCONFIGURE_CONFIG_H*/
946 __HEREDOC__
948 echo "config.h: written" 1>&2
949 echo "config.h: written" 1>&3
951 #----------------------------------------------------------------------
952 # Now we go to generate our Makefile.configure.
953 # This file is simply a bunch of Makefile variables.
954 # They'll work in both GNUmakefile and BSDmakefile.
955 # You MIGHT want to change this.
956 #----------------------------------------------------------------------
958 exec > Makefile.configure
960 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
961 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
962 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
963 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
964 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
965 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
967 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
968 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
969 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
970 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
972 cat << __HEREDOC__
973 BACKEND = ${BACKEND}
974 CC = ${CC}
975 CFLAGS = ${CFLAGS}
976 CPPFLAGS = ${CPPFLAGS}
977 LDADD = ${LDADD} ${LDADD_IMSG} ${LDADD_LIB_FLAC} ${LDADD_LIB_MPG123} \
978 ${LDADD_LIB_OPUSFILE} ${LDADD_LIB_VORBISFILE} \
979 ${LDADD_LIB_SOCKET} ${LDADD_LIBEVENT} ${LDADD_LIBEVENT2} \
980 ${LDADD_LIB_SNDIO} ${LDADD_LIB_ASOUND}
981 LDADD_STATIC = ${LDADD_STATIC}
982 LDFLAGS = ${LDFLAGS}
983 STATIC = ${STATIC}
984 PREFIX = ${PREFIX}
985 BINDIR = ${BINDIR}
986 SHAREDIR = ${SHAREDIR}
987 SBINDIR = ${SBINDIR}
988 INCLUDEDIR = ${INCLUDEDIR}
989 LIBDIR = ${LIBDIR}
990 MANDIR = ${MANDIR}
991 INSTALL = ${INSTALL}
992 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
993 INSTALL_LIB = ${INSTALL_LIB}
994 INSTALL_MAN = ${INSTALL_MAN}
995 INSTALL_DATA = ${INSTALL_DATA}
996 __HEREDOC__
998 echo "Makefile.configure: written" 1>&2
999 echo "Makefile.configure: written" 1>&3
1001 exit 0