Blob


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