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