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", "ao" or "alsa"
64 CC C compiler
65 CFLAGS generic C compiler flags
66 CPPFLAGS C preprocessors flags
67 LDADD generic linker flags
68 LDADD_LIB_AO linker flags for libao
69 LDADD_LIB_ASOUND linker flags for libasound
70 LDADD_LIB_FLAC linker flags for libflac
71 LDADD_LIB_IMSG linker flags for libimsg
72 LDADD_LIB_MD linker flags for libmd
73 LDADD_LIB_MPG123 linker flags for libmpg123
74 LDADD_LIB_PTHREAD linker flags for pthread
75 LDADD_LIB_OPUSFILE linker flags for libopusfile
76 LDADD_LIB_SNDIO linker flags for libsndio
77 LDADD_LIB_SOCKET linker flags for libsocket
78 LDADD_LIB_VORBISFILE linker flags for libvorbisfile
79 LDFLAGS extra linker flags
80 DESTDIR destination directory
81 PREFIX where to install files
82 MANDIR where to install man pages (PREFIX/man)
83 LIBDIR where to install libraries (PREFIX/lib)
84 BINDIR where to install executables (PREFIX/bin)
85 SHAREDIR where to install misc files (PREFIX/share)
86 SBINDIR where to install system executables (PREFIX/sbin)
87 INCLUDEDIR where to install header files (PREFIX/include)
88 PKG_CONFIG pkg-config program, \`false' to disable (pkg-config)
90 Additionally, the following environment variables are used if set:
92 CC the C compiler to use (defaults to cc, clang or gcc)
93 CFLAGS generic C compiler flags
95 EOF
96 exit 0 ;;
97 esac
99 #----------------------------------------------------------------------
100 # Prepare for running: move aside previous configure runs.
101 # Output file descriptor usage:
102 # 1 (stdout): config.h or Makefile.configure
103 # 2 (stderr): original stderr, usually to the console
104 # 3: config.log
105 # You DO NOT want to change this.
106 #----------------------------------------------------------------------
108 [ -w config.log ] && mv config.log config.log.old
109 [ -w config.h ] && mv config.h config.h.old
111 exec 3> config.log
112 echo "config.log: writing..."
114 # GNU submake prints different output if invoked recursively, which
115 # messes up CC and CFLAGS detection. Pass --no-print-directory if
116 # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
117 # allowed.
119 MAKE_FLAGS=""
121 if [ -n "${MAKELEVEL}" ]; then
122 if [ "${MAKELEVEL}" -gt 0 ] ; then
123 MAKE_FLAGS="--no-print-directory"
124 echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
125 fi
126 fi
128 if [ -n "$MAKE_FLAGS" ]; then
129 echo "GNU submake detected: using --no-print-directory" 1>&2
130 echo "GNU submake detected: using --no-print-directory" 1>&3
131 fi
133 #----------------------------------------------------------------------
134 # Initialize all variables here such that nothing can leak in from the
135 # environment except for CC and CFLAGS, which we might have passed in.
136 #----------------------------------------------------------------------
138 BACKEND=auto
139 CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
140 CXX=`printf "all:\\n\\t@echo \\\$(CXX)\\n" | make ${MAKE_FLAGS} -sf -`
141 CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
142 CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes"
143 CFLAGS="${CFLAGS} -Wstrict-prototypes -Wmissing-declarations"
144 CFLAGS="${CFLAGS} -Wno-unused-parameter -Wno-sign-compare -Wno-pointer-sign"
145 CXXFLAGS=`printf "all:\\n\\t@echo \\\$(CXXFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
146 CXXFLAGS="${CXXFLAGS} -g -W -Wall -Wextra -Wno-unused-parameter"
147 LDADD=
148 LDADD_LIB_AO=
149 LDADD_LIB_ASOUND=
150 LDADD_LIB_FLAC=
151 LDADD_LIB_IMSG=
152 LDADD_LIB_MD=
153 LDADD_LIB_MPG123=
154 LDADD_LIB_PTHREAD=
155 LDADD_LIB_OPUSFILE=
156 LDADD_LIB_SNDIO=
157 LDADD_LIB_SOCKET=
158 LDADD_LIB_VORBISFILE=
159 LDADD_STATIC=
160 CPPFLAGS=
161 LDFLAGS=
162 DESTDIR=
163 PREFIX="/usr/local"
164 BINDIR=
165 SBINDIR=
166 INCLUDEDIR=
167 LIBDIR=
168 MANDIR=
169 SHAREDIR=
170 INSTALL="install"
171 INSTALL_PROGRAM=
172 INSTALL_LIB=
173 INSTALL_MAN=
174 INSTALL_DATA=
175 PKG_CONFIG=
177 # SunOS sets "cc", but this doesn't exist.
178 # It does have gcc, so try that instead.
179 # Prefer clang, though.
181 command -v ${CC} 2>/dev/null 1>&2 || {
182 echo "${CC} not found: trying clang" 1>&2
183 echo "${CC} not found: trying clang" 1>&3
184 CC=clang
185 command -v ${CC} 2>/dev/null 1>&2 || {
186 echo "${CC} not found: trying gcc" 1>&2
187 echo "${CC} not found: trying gcc" 1>&3
188 CC=gcc
189 command -v ${CC} 2>/dev/null 1>&2 || {
190 echo "gcc not found: giving up" 1>&2
191 echo "gcc not found: giving up" 1>&3
192 exit 1
197 command -v pkg-config 2>/dev/null 1>&2 && {
198 PKG_CONFIG=pkg-config
199 echo "pkg-config found" 1>&2
200 echo "pkg-config found" 1>&3
201 } || {
202 echo "pkg-config not found" 1>&2
203 echo "pkg-config not found" 1>&3
206 #----------------------------------------------------------------------
207 # These are the values that will be pushed into config.h after we test
208 # for whether they're supported or not.
209 # Each of these must have a runtest(), below.
210 # Please sort by alpha, for clarity.
211 # You WANT to change this.
212 #----------------------------------------------------------------------
214 HAVE_CAPSICUM=
215 HAVE_ENDIAN_H=
216 HAVE_ERR=
217 HAVE_EXPLICIT_BZERO=
218 HAVE_FLOCK=
219 HAVE_FREEZERO=
220 HAVE_GETDTABLECOUNT=
221 HAVE_GETDTABLESIZE=
222 HAVE_GETEXECNAME=
223 HAVE_GETPROGNAME=
224 HAVE_INFTIM=
225 HAVE_LANDLOCK=
226 HAVE_LIB_ASOUND=
227 HAVE_LIB_FLAC=
228 HAVE_LIB_IMSG=
229 HAVE_LIB_MD=
230 HAVE_LIB_MPG123=
231 HAVE_LIB_OPUSFILE=
232 HAVE_LIB_SNDIO=
233 HAVE_LIB_SOCKET=
234 HAVE_LIB_VORBISFILE=
235 HAVE_MEMMEM=
236 HAVE_MEMRCHR=
237 HAVE_MEMSET_S=
238 HAVE_OPTRESET=
239 HAVE_PATH_MAX=
240 HAVE_PLEDGE=
241 HAVE_PROGRAM_INVOCATION_SHORT_NAME=
242 HAVE_PR_SET_NAME=
243 HAVE_REALLOCARRAY=
244 HAVE_RECALLOCARRAY=
245 HAVE_SANDBOX_INIT=
246 HAVE_SETPROCTITLE=
247 HAVE_SIO_FLUSH=
248 HAVE_SOCK_NONBLOCK=
249 HAVE_STRLCAT=
250 HAVE_STRLCPY=
251 HAVE_STRNDUP=
252 HAVE_STRNLEN=
253 HAVE_STRTONUM=
254 HAVE_SYS_ENDIAN_H=
255 HAVE_SYS_FILE=
256 HAVE_SYS_QUEUE=
257 HAVE_SYSTRACE=0
258 HAVE_TIMESPECSUB=
259 HAVE_UNVEIL=
260 HAVE___PROGNAME=
262 #----------------------------------------------------------------------
263 # Allow certain variables to be overriden on the command line.
264 #----------------------------------------------------------------------
266 while [ $# -gt 0 ]; do
267 key=${1%%=*}
268 val=${1#*=}
270 if [ "$key" = "--prefix" ]; then
271 key=PREFIX
272 if [ "$1" = "--prefix" ]; then
273 if ! shift 2>&1 >/dev/null; then
274 echo "$0: missing value for --prefix" 1>&2
275 exit 1
276 fi
277 val="$1"
278 fi
279 fi
281 if [ "$key" = "--backend" ]; then
282 key=BACKEND
283 if [ "$1" = "--backend" ]; then
284 if ! shift 2>&1 >/dev/null; then
285 echo "$0 missing value for --backend" 1>&2
286 exit 1
287 fi
288 val="$1"
289 fi
290 fi
292 if [ "$1" = "$key" ]; then
293 echo "$0: invalid key-value: $1" 1>&2
294 exit 1
295 fi
297 shift
299 case "$key" in
300 BACKEND)
301 case "$val" in
302 alsa) BACKEND=alsa ;;
303 ao) BACKEND=ao ;;
304 oboe) BACKEND=oboe ;;
305 sndio) BACKEND=sndio ;;
306 *)
307 echo "unknown audio backend: $val" 1>&2
308 exit 1
309 esac ;;
310 CC)
311 CC="$val" ;;
312 CFLAGS)
313 CFLAGS="$val" ;;
314 CXXFLAGS)
315 CXXFLAGS="$val" ;;
316 LDADD)
317 LDADD="$val" ;;
318 LDADD_LIB_AO)
319 LDADD_LIB_AO="$val"
320 HAVE_LIB_AO=1
321 BACKEND=ao
322 ;;
323 LDADD_LIB_ASOUND)
324 LDADD_LIB_ASOUND="$val"
325 HAVE_LIB_ASOUND=1
326 BACKEND=alsa
327 ;;
328 LDADD_LIB_FLAC)
329 LDADD_LIB_FLAC="$val"
330 HAVE_LIB_FLAC=1
331 ;;
332 LDADD_LIB_IMSG)
333 LDADD_LIB_IMSG="$val"
334 HAVE_LIB_IMSG=1
335 ;;
336 LDADD_LIB_MD)
337 LDADD_LIB_MD="$val"
338 HAVE_LIB_MD=1
339 ;;
340 LDADD_LIB_MPG123)
341 LDADD_LIB_MPG123="$val"
342 HAVE_LIB_MPG123=1
343 ;;
344 LDADD_LIB_PTHREAD)
345 LDADD_LIB_PTHREAD="$val"
346 HAVE_LIB_PTHREAD=1
347 ;;
348 LDADD_LIB_OPUSFILE)
349 LDADD_LIB_OPUSFILE="$val"
350 HAVE_LIB_OPUSFILE=1
351 ;;
352 LDADD_LIB_SNDIO)
353 LDADD_LIB_SNDIO="$val"
354 HAVE_LIB_SNDIO=1
355 BACKEND=sndio
356 ;;
357 LDADD_LIB_SOCKET)
358 LDADD_LIB_SOCKET="$val"
359 HAVE_LIB_SOCKET=1
360 ;;
361 LDADD_LIB_VORBISFILE)
362 LDADD_LIB_VORBISFILE="$val"
363 HAVE_LIB_VORBISFILE=1
364 ;;
365 LDFLAGS)
366 LDFLAGS="$val" ;;
367 CPPFLAGS)
368 CPPFLAGS="$val" ;;
369 DESTDIR)
370 DESTDIR="$val" ;;
371 PREFIX)
372 PREFIX="$val" ;;
373 MANDIR)
374 MANDIR="$val" ;;
375 LIBDIR)
376 LIBDIR="$val" ;;
377 BINDIR)
378 BINDIR="$val" ;;
379 SHAREDIR)
380 SHAREDIR="$val" ;;
381 SBINDIR)
382 SBINDIR="$val" ;;
383 INCLUDEDIR)
384 INCLUDEDIR="$val" ;;
385 PKG_CONFIG)
386 PKG_CONFIG="$val" ;;
387 *)
388 echo "$0: invalid key: $key" 1>&2
389 exit 1
390 esac
391 done
393 #----------------------------------------------------------------------
394 # Allow configure.local to override all variables, default settings,
395 # command-line arguments, and tested features, above.
396 # You PROBABLY DO NOT want to change this.
397 #----------------------------------------------------------------------
399 if [ -r ./configure.local ]; then
400 echo "configure.local: reading..." 1>&2
401 echo "configure.local: reading..." 1>&3
402 cat ./configure.local 1>&3
403 . ./configure.local
404 else
405 echo "configure.local: no (fully automatic configuration)" 1>&2
406 echo "configure.local: no (fully automatic configuration)" 1>&3
407 fi
409 echo 1>&3
411 #----------------------------------------------------------------------
412 # Infrastructure for running tests.
413 # These consists of a series of functions that will attempt to run the
414 # given test file and record its exit into a HAVE_xxx variable.
415 # You DO NOT want to change this.
416 #----------------------------------------------------------------------
418 COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
420 # Check whether this HAVE_ setting is manually overridden.
421 # If yes, use the override, if no, do not decide anything yet.
422 # Arguments: lower-case test name, manual value
424 ismanual() {
425 eval _manual=\${LDADD_${2}}
426 if [ -z "$_manual" ]; then
427 eval _manual=\${HAVE_${2}}
428 fi
430 [ -z "${_manual}" ] && return 1
431 echo "${1}: manual (${_manual})" 1>&2
432 echo "${1}: manual (${_manual})" 1>&3
433 echo 1>&3
434 return 0
437 # Run a single autoconfiguration test.
438 # In case of success, enable the feature.
439 # In case of failure, do not decide anything yet.
440 # Arguments: lower-case test name, upper-case test name, additional
441 # CFLAGS, additional LIBS.
443 singletest() {
444 extralib=""
445 pkgcfs=""
446 pkglib=""
448 cat 1>&3 << __HEREDOC__
449 ${1}: testing...
450 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${4}
451 __HEREDOC__
452 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${4} 1>&3 2>&3; then
453 echo "${1}: ${CC} succeeded" 1>&3
454 else
455 if [ -n "${5}" ] ; then
456 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
457 cat 1>&3 << __HEREDOC__
458 ${1}: testing...
459 ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${5}
460 __HEREDOC__
461 if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${5} 1>&3 2>&3; then
462 echo "${1}: ${CC} succeeded" 1>&3
463 extralib="(with ${5})"
464 else
465 test -n "${PKG_CONFIG}" -a -n "${6}" && ${PKG_CONFIG} "$6"
466 if [ $? -eq 0 ]; then
467 echo "${1}: ${CC} failed with $? (retrying)" 1>&3
468 pkgcfs=$($PKG_CONFIG --cflags "${6}")
469 pkglib=$($PKG_CONFIG --libs "${6}")
470 cat 1>&3 << __HEREDOC__
471 ${1}: testing...
472 ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib}
473 __HEREDOC__
474 if ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib} 1>&3 2>&3; then
475 echo "${1}: ${CC} succeeded" 1>&3
476 extralib="(with ${pkgcfs} ${pkglib})"
477 else
478 echo "${1}: ${CC} failed with $?" 1>&3
479 echo 1>&3
480 return 1
481 fi
482 else
483 echo "${1}: ${CC} failed with $?" 1>&3
484 echo 1>&3
485 return 1
486 fi
487 fi
488 else
489 echo "${1}: ${CC} failed with $?" 1>&3
490 echo 1>&3
491 return 1
492 fi
493 fi
495 rm -f test-${1}.d
497 if [ -n "${pkgcfs}" -o -n "${pkglib}" ]; then
498 CFLAGS="${CFLAGS} ${pkgcfs}"
499 eval "LDADD_${2}=\"${pkglib}\""
500 elif [ -n "${extralib}" ]; then
501 eval "LDADD_${2}=\"${5}\""
502 elif [ -n "${4}" ]; then
503 eval "LDADD_${2}=\"${4}\""
504 fi
506 echo "${1}: yes ${extralib}" 1>&2
507 echo "${1}: yes ${extralib}" 1>&3
508 echo 1>&3
509 eval HAVE_${2}=1
510 rm "test-${1}"
511 return 0
514 # Run a complete autoconfiguration test, including the check for
515 # a manual override and disabling the feature on failure.
516 # Arguments: lower case name, upper case name, additional CFLAGS,
517 # additional LDADD, alternative LDADD, pkg-config name.
519 runtest() {
520 ismanual "${1}" "${2}" && return 0
521 singletest "${1}" "${2}" "${3}" "${4}" "${5}" "${6}" && return 0
522 echo "${1}: no" 1>&2
523 eval HAVE_${2}=0
524 return 1
527 #----------------------------------------------------------------------
528 # Begin running the tests themselves.
529 # All of your tests must be defined here.
530 # Please sort as the HAVE_xxxx values were defined.
531 # You WANT to change this.
532 # It consists of the following columns:
533 # runtest
534 # (1) test file
535 # (2) macro to set
536 # (3) argument to cc *before* -o
537 # (4) argument to cc *after*
538 # (5) alternative argument to cc *after*
539 # (6) name for pkg-config auto-discovery
540 #----------------------------------------------------------------------
542 if runtest -MMD _MMD -MMD; then
543 CFLAGS="${CFLAGS} -MMD"
544 CXXFLAGS="${CXXFLAGS} -MMD"
545 echo "adding -MMD to CFLAGS and CXXFLAGS" 1>&2
546 echo "adding -MMD to CFLAGS and CXXFLAGS" 1>&3
547 fi
549 runtest capsicum CAPSICUM || true
550 runtest endian_h ENDIAN_H || true
551 runtest err ERR || true
552 runtest explicit_bzero EXPLICIT_BZERO || true
553 runtest flock FLOCK || true
554 runtest freezero FREEZERO || true
555 runtest getdtablecount GETDTABLECOUNT || true
556 runtest getdtablesize GETDTABLESIZE || true
557 runtest getexecname GETEXECNAME || true
558 runtest getprogname GETPROGNAME || true
559 runtest INFTIM INFTIM || true
560 runtest landlock LANDLOCK || true
562 runtest lib_imsg LIB_IMSG "" "" "-lutil" || true
563 runtest lib_md LIB_MD "" "" "-lmd" "libmd" || true
564 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
566 runtest lib_flac LIB_FLAC "" "" "-lFLAC" "flac" || true
567 runtest lib_mpg123 LIB_MPG123 "" "" "-lmpg123" "libmpg123" || true
568 runtest lib_opusfile LIB_OPUSFILE "" "" "-lopusfile" "opusfile" || true
569 runtest lib_vorbisfile LIB_VORBISFILE "" "" "-lvorbisfile" "vorbisfile" || true
571 runtest memmem MEMMEM || true
572 runtest memrchr MEMRCHR || true
573 runtest memset_s MEMSET_S || true
574 runtest optreset OPTRESET || true
575 runtest PATH_MAX PATH_MAX || true
576 runtest pledge PLEDGE || true
577 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
578 runtest PR_SET_NAME PR_SET_NAME || true
579 runtest reallocarray REALLOCARRAY || true
580 runtest recallocarray RECALLOCARRAY || true
581 runtest sandbox_init SANDBOX_INIT "-Wno-deprecated" || true
582 runtest setproctitle SETPROCTITLE || true
583 runtest SOCK_NONBLOCK SOCK_NONBLOCK || true
584 runtest static STATIC "" "-static" || true
585 runtest strlcat STRLCAT || true
586 runtest strlcpy STRLCPY || true
587 runtest strndup STRNDUP || true
588 runtest strnlen STRNLEN || true
589 runtest strtonum STRTONUM || true
590 runtest sys_queue SYS_QUEUE || true
591 runtest sys_endian_h SYS_ENDIAN_H || true
592 runtest sys_file SYS_FILE || true
593 runtest timespecsub TIMESPECSUB || true
594 runtest unveil UNVEIL || true
595 runtest __progname __PROGNAME || true
597 if [ $BACKEND = auto -o $BACKEND = sndio ]; then
598 runtest lib_sndio LIB_SNDIO "" "" "-lsndio" "sndio" || true
599 runtest sio_flush SIO_FLUSH "" "" "${LDADD_LIB_SNDIO}" || true
601 if [ "${HAVE_LIB_SNDIO}" -eq 0 ]; then
602 if [ $BACKEND = sndio ]; then
603 echo "Fatal: missing libsndio" 1>&2
604 echo "Fatal: missing libsndio" 1>&3
605 exit 1
606 fi
607 else
608 BACKEND=sndio
609 fi
610 else
611 HAVE_SIO_FLUSH=0
612 fi
614 if [ $BACKEND = auto -o $BACKEND = alsa ]; then
615 runtest lib_asound LIB_ASOUND "" "" "-lasound" "alsa" || true
616 if [ "${HAVE_LIB_ASOUND}" -eq 0 ]; then
617 if [ $BACKEND = alsa ]; then
618 echo "Fatal: missing libasound" 1>&2
619 echo "Fatal: missing libasound" 1>&3
620 exit 1
621 fi
622 fi
623 BACKEND=alsa
624 fi
626 if [ $BACKEND = auto -o $BACKEND = ao ]; then
627 runtest lib_ao LIB_AO "" "" "-lao" "ao" || true
628 if [ "${HAVE_LIB_AO}" -eq 0 ]; then
629 if [ $BACKEND = ao ]; then
630 echo "Fatal: missing libao" 1>&2
631 echo "Fatal: missing libao" 1>&3
632 else
633 echo "Fatal: missing libasound, libao or libsndio" 1>&2
634 echo "Fatal: missing libasound, libao or libsndio" 1>&3
635 fi
636 exit 1
637 fi
638 BACKEND=ao
640 runtest pthread LIB_PTHREAD "" "-pthread" || true
641 if [ "${HAVE_LIB_PTHREAD}" -eq 0 ]; then
642 echo "Fatal: missing pthread" 1>&2
643 echo "Fatal: missing pthread" 1>&3
644 exit 1
645 fi
646 CFLAGS="${CFLAGS} -pthread"
647 fi
649 if [ $BACKEND = auto -o $BACKEND = oboe ]; then
650 runtest pthread LIB_PTHREAD "" "-pthread" || true
651 if [ "${HAVE_LIB_PTHREAD}" -eq 0 ]; then
652 echo "Fatal: missing pthread" 1>&2
653 echo "Fatal: missing pthread" 1>&3
654 exit 1
655 fi
656 CFLAGS="${CFLAGS} -pthread"
658 LDADD="${LDADD} -lstdc++ -lm -llog -lOpenSLES"
659 fi
661 if [ "${HAVE_ENDIAN_H}" -eq 0 ]; then
662 CFLAGS="${CFLAGS} -I."
663 fi
665 if [ "${HAVE_LIB_FLAC}" -eq 0 -o \
666 "${HAVE_LIB_MPG123}" -eq 0 -o \
667 "${HAVE_LIB_OPUSFILE}" -eq 0 -o \
668 "${HAVE_LIB_VORBISFILE}" -eq 0 ]; then
669 echo "Fatal: missing required audio libraries" 1>&2
670 echo "Fatal: missing required audio libraries" 1>&3
671 exit 1
672 fi
674 #----------------------------------------------------------------------
675 # Output writing: generate the config.h file.
676 # This file contains all of the HAVE_xxxx variables necessary for
677 # compiling your source.
678 # You must include "config.h" BEFORE any other variables.
679 # You WANT to change this.
680 #----------------------------------------------------------------------
682 exec > config.h
684 # Start with prologue.
686 cat << __HEREDOC__
687 #ifndef OCONFIGURE_CONFIG_H
688 #define OCONFIGURE_CONFIG_H
690 /* the oboe (android) backend uses c++ */
691 #ifndef __ANDROID__
692 #ifdef __cplusplus
693 # error "Do not use C++: this is a C application."
694 #endif
695 #endif /* __ANDROID__ */
696 #if !defined(__GNUC__) || (__GNUC__ < 4)
697 # define __attribute__(x)
698 #endif
699 #if defined(__linux__) || defined(__MINT__)
700 # ifndef __ANDROID__
701 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
702 # endif
703 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
704 #endif
705 #if defined(__NetBSD__)
706 # define _OPENBSD_SOURCE /* reallocarray, etc. */
707 #endif
708 #if defined(__sun)
709 # ifndef _XOPEN_SOURCE /* SunOS already defines */
710 # define _XOPEN_SOURCE /* XPGx */
711 # endif
712 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
713 # ifndef __EXTENSIONS__ /* SunOS already defines */
714 # define __EXTENSIONS__ /* reallocarray, etc. */
715 # endif
716 #endif
717 #if !defined(__BEGIN_DECLS)
718 # define __BEGIN_DECLS
719 #endif
720 #if !defined(__END_DECLS)
721 # define __END_DECLS
722 #endif
724 __HEREDOC__
726 cat << __HEREDOC__
727 /*
728 * Results of configuration feature-testing.
729 */
730 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
731 #define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
732 #define HAVE_ERR ${HAVE_ERR}
733 #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
734 #define HAVE_FLOCK ${HAVE_FLOCK}
735 #define HAVE_FREEZERO ${HAVE_FREEZERO}
736 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
737 #define HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}
738 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
739 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
740 #define HAVE_LIB_IMSG ${HAVE_LIB_IMSG}
741 #define HAVE_INFTIM ${HAVE_INFTIM}
742 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
743 #define HAVE_MEMMEM ${HAVE_MEMMEM}
744 #define HAVE_MEMRCHR ${HAVE_MEMRCHR}
745 #define HAVE_MEMSET_S ${HAVE_MEMSET_S}
746 #define HAVE_OPTRESET ${HAVE_OPTRESET}
747 #define HAVE_PATH_MAX ${HAVE_PATH_MAX}
748 #define HAVE_PLEDGE ${HAVE_PLEDGE}
749 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
750 #define HAVE_PR_SET_NAME ${HAVE_PR_SET_NAME}
751 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
752 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
753 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
754 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
755 #define HAVE_SIO_FLUSH ${HAVE_SIO_FLUSH}
756 #define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
757 #define HAVE_STRLCAT ${HAVE_STRLCAT}
758 #define HAVE_STRLCPY ${HAVE_STRLCPY}
759 #define HAVE_STRNDUP ${HAVE_STRNDUP}
760 #define HAVE_STRNLEN ${HAVE_STRNLEN}
761 #define HAVE_STRTONUM ${HAVE_STRTONUM}
762 #define HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H}
763 #define HAVE_SYS_FILE ${HAVE_SYS_FILE}
764 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
765 #define HAVE_SYSTRACE ${HAVE_SYSTRACE}
766 #define HAVE_TIMESPECSUB ${HAVE_TIMESPECSUB}
767 #define HAVE_UNVEIL ${HAVE_UNVEIL}
768 #define HAVE___PROGNAME ${HAVE___PROGNAME}
770 __HEREDOC__
772 # This is just for size_t, mode_t, and dev_t.
773 # Most of these functions, in the real world, pull in <string.h> or
774 # someting that pulls in support for size_t.
775 # Our function declarations are standalone, so specify them here.
777 if [ ${HAVE_LIB_IMSG} -eq 0 -o \
778 ${HAVE_MEMMEM} -eq 0 -o \
779 ${HAVE_MEMRCHR} -eq 0 -o \
780 ${HAVE_REALLOCARRAY} -eq 0 -o \
781 ${HAVE_RECALLOCARRAY} -eq 0 -o \
782 ${HAVE_STRLCAT} -eq 0 -o \
783 ${HAVE_STRLCPY} -eq 0 -o \
784 ${HAVE_STRNDUP} -eq 0 -o \
785 ${HAVE_STRNLEN} -eq 0 ]
786 then
787 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
788 echo
789 fi
791 if [ ${HAVE_FLOCK} -eq 0 ]; then
792 if [ ${HAVE_SYS_FILE} -eq 0 ]; then
793 HAVE_FLOCK=1
794 echo "#include <sys/file.h>"
795 echo
796 else
797 echo "int flock(int, int);"
798 echo "#define LOCK_SH 0x1"
799 echo "#define LOCK_EX 0x2"
800 echo "#define LOCK_NB 0x4"
801 echo
802 fi
803 fi
805 if [ ${HAVE_ERR} -eq 0 ]; then
806 echo "#include <stdarg.h> /* err(3) */"
807 echo
808 else
809 echo "#include <err.h>"
810 echo
811 fi
813 if [ ${HAVE_PLEDGE} -eq 0 ]; then
814 echo "#define pledge(p, e) (0)"
815 echo
816 else
817 echo "#include <unistd.h>"
818 echo
819 fi
821 if [ ${HAVE_PATH_MAX} -eq 0 ]
822 then
823 echo "#define PATH_MAX 4096"
824 echo
825 fi
827 if [ ${HAVE_INFTIM} -eq 0 ]
828 then
829 echo "#define INFTIM (-1) /* poll.h */"
830 echo
831 fi
833 # Now we do our function declarations for missing functions.
835 [ ${HAVE_ERR} -eq 0 ] && \
836 cat << __HEREDOC__
837 /*
838 * Compatibility functions for err(3).
839 */
840 extern void err(int, const char *, ...) __attribute__((noreturn));
841 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
842 extern void errx(int, const char *, ...) __attribute__((noreturn));
843 extern void verr(int, const char *, va_list) __attribute__((noreturn));
844 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
845 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
846 extern void warn(const char *, ...);
847 extern void warnx(const char *, ...);
848 extern void warnc(int, const char *, ...);
849 extern void vwarn(const char *, va_list);
850 extern void vwarnc(int, const char *, va_list);
851 extern void vwarnx(const char *, va_list);
852 __HEREDOC__
854 [ ${HAVE_EXPLICIT_BZERO} -eq 0 ] && \
855 cat << __HEREDOC__
856 /*
857 * Compatibility for explicit_bzero(3).
858 */
859 extern void explicit_bzero(void *, size_t);
861 __HEREDOC__
863 [ ${HAVE_FREEZERO} -eq 0 ] && \
864 cat << __HEREDOC__
865 /*
866 * Compatibility for freezero(3).
867 */
868 extern void freezero(void *, size_t);
870 __HEREDOC__
872 [ ${HAVE_MEMMEM} -eq 0 ] && \
873 cat << __HEREDOC__
874 /*
875 * Compatibility for memmem(3).
876 */
877 void *memmem(const void *, size_t, const void *, size_t);
879 __HEREDOC__
881 [ ${HAVE_MEMRCHR} -eq 0 ] && \
882 cat << __HEREDOC__
883 /*
884 * Compatibility for memrchr(3).
885 */
886 void *memrchr(const void *b, int, size_t);
888 __HEREDOC__
890 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
891 cat << __HEREDOC__
892 /*
893 * Compatibility for getprogname(3).
894 */
895 extern const char *getprogname(void);
897 __HEREDOC__
899 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
900 cat << __HEREDOC__
901 /*
902 * Compatibility for reallocarray(3).
903 */
904 extern void *reallocarray(void *, size_t, size_t);
906 __HEREDOC__
908 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
909 cat << __HEREDOC__
910 /*
911 * Compatibility for recallocarray(3).
912 */
913 extern void *recallocarray(void *, size_t, size_t, size_t);
915 __HEREDOC__
917 [ ${HAVE_SETPROCTITLE} -eq 0 ] && \
918 cat << __HEREDOC__
919 /*
920 * Compatibility for setproctitle(3).
921 */
922 extern void setproctitle(const char *, ...);
924 __HEREDOC__
926 [ ${HAVE_STRLCAT} -eq 0 ] && \
927 cat << __HEREDOC__
928 /*
929 * Compatibility for strlcat(3).
930 */
931 extern size_t strlcat(char *, const char *, size_t);
933 __HEREDOC__
935 [ ${HAVE_STRLCPY} -eq 0 ] && \
936 cat << __HEREDOC__
937 /*
938 * Compatibility for strlcpy(3).
939 */
940 extern size_t strlcpy(char *, const char *, size_t);
942 __HEREDOC__
944 [ ${HAVE_STRNDUP} -eq 0 ] && \
945 cat << __HEREDOC__
946 /*
947 * Compatibility for strndup(3).
948 */
949 extern char *strndup(const char *, size_t);
951 __HEREDOC__
953 [ ${HAVE_STRNLEN} -eq 0 ] && \
954 cat << __HEREDOC__
955 /*
956 * Compatibility for strnlen(3).
957 */
958 extern size_t strnlen(const char *, size_t);
960 __HEREDOC__
962 [ ${HAVE_STRTONUM} -eq 0 ] && \
963 cat << __HEREDOC__
964 /*
965 * Compatibility for strotnum(3).
966 */
967 extern long long strtonum(const char *, long long, long long, const char **);
969 __HEREDOC__
971 if [ ${HAVE_SYS_QUEUE} -eq 0 ]; then
972 cat << __HEREDOC__
973 #include "queue.h"
974 __HEREDOC__
975 else
976 echo "#include <sys/queue.h>"
977 echo
978 fi
980 echo "#include <sys/uio.h>"
981 echo "#include <stdint.h>"
982 if [ ${HAVE_LIB_IMSG} -eq 0 ]; then
983 echo "#include \"imsg.h\""
984 else
985 echo "#include <imsg.h>"
986 fi
987 echo
989 cat << __HEREDOC__
990 #ifndef __dead
991 # define __dead __attribute__((noreturn))
992 #endif
994 #if !HAVE_SIO_FLUSH
995 #define sio_flush(hdl) (sio_stop(hdl))
996 #endif
998 #if !HAVE_GETDTABLECOUNT
999 /* XXX: on linux it should be possible to inspect /proc/self/fd/ */
1000 #define getdtablecount() (0)
1001 #endif
1003 #if !HAVE_GETDTABLESIZE
1004 int getdtablesize(void);
1005 #endif
1007 #if !HAVE_OPTRESET
1008 /* replace host' getopt with OpenBSD' one */
1009 #define opterr BSDopterr
1010 #define optind BSDoptind
1011 #define optopt BSDoptopt
1012 #define optreset BSDoptreset
1013 #define optarg BSDoptarg
1014 #define getopt BSDgetopt
1016 extern int BSDopterr, BSDoptind, BSDoptopt, BSDoptreset;
1017 extern char *BSDoptarg;
1018 #endif
1020 #if !HAVE_TIMESPECSUB
1021 struct timespec;
1022 void timespecsub(struct timespec *, struct timespec *, struct timespec *);
1023 #endif
1025 #endif /*!OCONFIGURE_CONFIG_H*/
1026 __HEREDOC__
1028 echo "config.h: written" 1>&2
1029 echo "config.h: written" 1>&3
1031 #----------------------------------------------------------------------
1032 # Now we go to generate our Makefile.configure.
1033 # This file is simply a bunch of Makefile variables.
1034 # They'll work in both GNUmakefile and BSDmakefile.
1035 # You MIGHT want to change this.
1036 #----------------------------------------------------------------------
1038 exec > Makefile.configure
1040 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
1041 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
1042 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
1043 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
1044 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
1045 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
1047 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
1048 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
1049 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
1050 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
1052 cat << __HEREDOC__
1053 BACKEND = ${BACKEND}
1054 CC = ${CC}
1055 CFLAGS = ${CFLAGS}
1056 CXXFLAGS = ${CXXFLAGS}
1057 CPPFLAGS = ${CPPFLAGS}
1058 LDADD = ${LDADD}
1059 LDADD_LIB_IMSG = ${LDADD_LIB_IMSG}
1060 LDADD_DECODERS = ${LDADD_LIB_FLAC} ${LDADD_LIB_MPG123} ${LDADD_LIB_OPUSFILE} \
1061 ${LDADD_LIB_VORBISFILE}
1062 LDADD_LIB_MD = ${LDADD_LIB_MD}
1063 LDADD_LIB_SOCKET = ${LDADD_LIB_SOCKET}
1064 LDADD_BACKEND = ${LDADD_LIB_SNDIO} ${LDADD_LIB_ASOUND} ${LDADD_LIB_AO} \
1065 ${LDADD_LIB_PTHREAD}
1066 LDADD_STATIC = ${LDADD_STATIC}
1067 LDFLAGS = ${LDFLAGS}
1068 STATIC = ${STATIC}
1069 PREFIX = ${PREFIX}
1070 BINDIR = ${BINDIR}
1071 SHAREDIR = ${SHAREDIR}
1072 SBINDIR = ${SBINDIR}
1073 INCLUDEDIR = ${INCLUDEDIR}
1074 LIBDIR = ${LIBDIR}
1075 MANDIR = ${MANDIR}
1076 INSTALL = ${INSTALL}
1077 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
1078 INSTALL_LIB = ${INSTALL_LIB}
1079 INSTALL_MAN = ${INSTALL_MAN}
1080 INSTALL_DATA = ${INSTALL_DATA}
1081 __HEREDOC__
1083 echo "Makefile.configure: written" 1>&2
1084 echo "Makefile.configure: written" 1>&3
1086 exit 0