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