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 if [ -n "${pkgcfs}" -o -n "${pkglib}" ]
411 then
412 CFLAGS="${CFLAGS} ${pkgcfs}"
413 eval "LDADD_${2}=\"${pkglib}\""
414 elif [ -n "${extralib}" ]
415 then
416 eval "LDADD_${2}=\"${5}\""
417 elif [ -n "${4}" ]
418 then
419 eval "LDADD_${2}=\"${4}\""
420 fi
422 echo "${1}: yes ${extralib}" 1>&2
423 echo "${1}: yes ${extralib}" 1>&3
424 echo 1>&3
425 eval HAVE_${2}=1
426 rm "test-${1}"
427 return 0
430 # Run a complete autoconfiguration test, including the check for
431 # a manual override and disabling the feature on failure.
432 # Arguments: lower case name, upper case name, additional CFLAGS,
433 # additional LDADD, alternative LDADD, pkg-config name.
435 runtest() {
436 eval _manual=\${HAVE_${2}}
437 ismanual "${1}" "${2}" "${_manual}" && return 0
438 singletest "${1}" "${2}" "${3}" "${4}" "${5}" "${6}" && return 0
439 echo "${1}: no" 1>&2
440 eval HAVE_${2}=0
441 return 1
444 #----------------------------------------------------------------------
445 # Begin running the tests themselves.
446 # All of your tests must be defined here.
447 # Please sort as the HAVE_xxxx values were defined.
448 # You WANT to change this.
449 # It consists of the following columns:
450 # runtest
451 # (1) test file
452 # (2) macro to set
453 # (3) argument to cc *before* -o
454 # (4) argument to cc *after*
455 # (5) alternative argument to cc *after*
456 # (6) name for pkg-config auto-discovery
457 #----------------------------------------------------------------------
459 if runtest -MMD _MMD -MMD; then
460 CFLAGS="${CFLAGS} -MMD"
461 echo "adding -MMD to CFLAGS" 1>&2
462 echo "adding -MMD to CFLAGS" 1>&3
463 fi
465 runtest capsicum CAPSICUM || true
466 runtest err ERR || true
467 runtest explicit_bzero EXPLICIT_BZERO || true
468 runtest flock FLOCK || true
469 runtest freezero FREEZERO || true
470 runtest getdtablecount GETDTABLECOUNT || true
471 runtest getexecname GETEXECNAME || true
472 runtest getprogname GETPROGNAME || true
473 runtest imsg IMSG "" "" "-lutil" || true
474 runtest INFTIM INFTIM || true
475 runtest landlock LANDLOCK || true
477 runtest libevent LIBEVENT "" "" "-levent" || \
478 runtest libevent2 LIBEVENT2 "" "" "-levent_extra -levent_core" "libevent" || true
480 runtest lib_flac LIB_FLAC "" "" "-lFLAC" "flac" || true
481 runtest lib_mpg123 LIB_MPG123 "" "" "-lmpg123" "libmpg123" || true
482 runtest lib_opusfile LIB_OPUSFILE "" "" "-lopusfile" "opusfile" || true
483 runtest lib_vorbisfile LIB_VORBISFILE "" "" "-lvorbisfile" "vorbisfile" || true
485 runtest lib_sndio LIB_SNDIO "" "" "-lsndio" "sndio" || true
486 runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
487 runtest memmem MEMMEM || true
488 runtest memrchr MEMRCHR || true
489 runtest memset_s MEMSET_S || true
490 runtest optreset OPTRESET || true
491 runtest PATH_MAX PATH_MAX || true
492 runtest pledge PLEDGE || true
493 runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
494 runtest PR_SET_NAME PR_SET_NAME || true
495 runtest reallocarray REALLOCARRAY || true
496 runtest recallocarray RECALLOCARRAY || true
497 runtest sandbox_init SANDBOX_INIT "-Wno-deprecated" || true
498 runtest setproctitle SETPROCTITLE || true
499 runtest sio_flush SIO_FLUSH "" "" "${LDADD_LIB_SNDIO}" || true
500 runtest SOCK_NONBLOCK SOCK_NONBLOCK || true
501 runtest static STATIC "" "-static" || true
502 runtest strlcat STRLCAT || true
503 runtest strlcpy STRLCPY || true
504 runtest strndup STRNDUP || true
505 runtest strnlen STRNLEN || true
506 runtest strtonum STRTONUM || true
507 runtest sys_queue SYS_QUEUE || true
508 runtest sys_file SYS_FILE || true
509 runtest unveil UNVEIL || true
510 runtest __progname __PROGNAME || true
512 if [ "${HAVE_LIBEVENT}" -eq 0 -a "${HAVE_LIBEVENT2}" -eq 0 ]; then
513 echo "Fatal: missing libevent" 1>&2
514 echo "Fatal: missing libevent" 1>&3
515 exit 1
516 fi
518 if [ "${HAVE_LIB_FLAC}" -eq 0 -o \
519 "${HAVE_LIB_MPG123}" -eq 0 -o \
520 "${HAVE_LIB_OPUSFILE}" -eq 0 -o \
521 "${HAVE_LIB_VORBISFILE}" -eq 0 ]; then
522 echo "Fatal: missing required audio libraries" 1>&2
523 echo "Fatal: missing required audio libraries" 1>&3
524 exit 1
525 fi
527 if [ "${HAVE_LIB_SNDIO}" -eq 0 ]; then
528 echo "Fatal: missing libsndio" 1>&2
529 echo "Fatal: missing libsndio" 1>&3
530 exit 1
531 fi
533 #----------------------------------------------------------------------
534 # Output writing: generate the config.h file.
535 # This file contains all of the HAVE_xxxx variables necessary for
536 # compiling your source.
537 # You must include "config.h" BEFORE any other variables.
538 # You WANT to change this.
539 #----------------------------------------------------------------------
541 exec > config.h
543 # Start with prologue.
545 cat << __HEREDOC__
546 #ifndef OCONFIGURE_CONFIG_H
547 #define OCONFIGURE_CONFIG_H
549 #ifdef __cplusplus
550 # error "Do not use C++: this is a C application."
551 #endif
552 #if !defined(__GNUC__) || (__GNUC__ < 4)
553 # define __attribute__(x)
554 #endif
555 #if defined(__linux__) || defined(__MINT__)
556 # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
557 # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
558 #endif
559 #if defined(__NetBSD__)
560 # define _OPENBSD_SOURCE /* reallocarray, etc. */
561 #endif
562 #if defined(__sun)
563 # ifndef _XOPEN_SOURCE /* SunOS already defines */
564 # define _XOPEN_SOURCE /* XPGx */
565 # endif
566 # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
567 # ifndef __EXTENSIONS__ /* SunOS already defines */
568 # define __EXTENSIONS__ /* reallocarray, etc. */
569 # endif
570 #endif
571 #if !defined(__BEGIN_DECLS)
572 # define __BEGIN_DECLS
573 #endif
574 #if !defined(__END_DECLS)
575 # define __END_DECLS
576 #endif
578 __HEREDOC__
580 # This is just for size_t, mode_t, and dev_t.
581 # Most of these functions, in the real world, pull in <string.h> or
582 # someting that pulls in support for size_t.
583 # Our function declarations are standalone, so specify them here.
585 if [ ${HAVE_IMSG} -eq 0 -o \
586 ${HAVE_MEMMEM} -eq 0 -o \
587 ${HAVE_MEMRCHR} -eq 0 -o \
588 ${HAVE_REALLOCARRAY} -eq 0 -o \
589 ${HAVE_RECALLOCARRAY} -eq 0 -o \
590 ${HAVE_STRLCAT} -eq 0 -o \
591 ${HAVE_STRLCPY} -eq 0 -o \
592 ${HAVE_STRNDUP} -eq 0 -o \
593 ${HAVE_STRNLEN} -eq 0 ]
594 then
595 echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
596 echo
597 fi
599 if [ ${HAVE_FLOCK} -eq 0 ]; then
600 if [ ${HAVE_SYS_FILE} -eq 0 ]; then
601 HAVE_FLOCK=1
602 echo "#include <sys/file.h>"
603 echo
604 else
605 echo "int flock(int, int);"
606 echo "#define LOCK_SH 0x1"
607 echo "#define LOCK_EX 0x2"
608 echo "#define LOCK_NB 0x4"
609 echo
610 fi
611 fi
613 if [ ${HAVE_ERR} -eq 0 ]; then
614 echo "#include <stdarg.h> /* err(3) */"
615 echo
616 else
617 echo "#include <err.h>"
618 echo
619 fi
621 if [ ${HAVE_PLEDGE} -eq 0 ]; then
622 echo "#define pledge(p, e) (0)"
623 echo
624 else
625 echo "#include <unistd.h>"
626 echo
627 fi
629 # Now we handle our HAVE_xxxx values.
630 # Most will just be defined as 0 or 1.
632 if [ ${HAVE_PATH_MAX} -eq 0 ]
633 then
634 echo "#define PATH_MAX 4096"
635 echo
636 fi
638 if [ ${HAVE_INFTIM} -eq 0 ]
639 then
640 echo "#define INFTIM (-1) /* poll.h */"
641 echo
642 fi
644 cat << __HEREDOC__
645 /*
646 * Results of configuration feature-testing.
647 */
648 #define HAVE_CAPSICUM ${HAVE_CAPSICUM}
649 #define HAVE_ERR ${HAVE_ERR}
650 #define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
651 #define HAVE_FLOCK ${HAVE_FLOCK}
652 #define HAVE_FREEZERO ${HAVE_FREEZERO}
653 #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
654 #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
655 #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
656 #define HAVE_INFTIM ${HAVE_INFTIM}
657 #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
658 #define HAVE_MEMMEM ${HAVE_MEMMEM}
659 #define HAVE_MEMRCHR ${HAVE_MEMRCHR}
660 #define HAVE_MEMSET_S ${HAVE_MEMSET_S}
661 #define HAVE_OPTRESET ${HAVE_OPTRESET}
662 #define HAVE_PATH_MAX ${HAVE_PATH_MAX}
663 #define HAVE_PLEDGE ${HAVE_PLEDGE}
664 #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
665 #define HAVE_PR_SET_NAME ${HAVE_PR_SET_NAME}
666 #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
667 #define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
668 #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
669 #define HAVE_SETPROCTITLE ${HAVE_SETPROCTITLE}
670 #define HAVE_SIO_FLUSH ${HAVE_SIO_FLUSH}
671 #define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
672 #define HAVE_STRLCAT ${HAVE_STRLCAT}
673 #define HAVE_STRLCPY ${HAVE_STRLCPY}
674 #define HAVE_STRNDUP ${HAVE_STRNDUP}
675 #define HAVE_STRNLEN ${HAVE_STRNLEN}
676 #define HAVE_STRTONUM ${HAVE_STRTONUM}
677 #define HAVE_SYS_FILE ${HAVE_SYS_FILE}
678 #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
679 #define HAVE_SYSTRACE ${HAVE_SYSTRACE}
680 #define HAVE_UNVEIL ${HAVE_UNVEIL}
681 #define HAVE___PROGNAME ${HAVE___PROGNAME}
683 __HEREDOC__
685 # Now we do our function declarations for missing functions.
687 [ ${HAVE_ERR} -eq 0 ] && \
688 cat << __HEREDOC__
689 /*
690 * Compatibility functions for err(3).
691 */
692 extern void err(int, const char *, ...) __attribute__((noreturn));
693 extern void errc(int, int, const char *, ...) __attribute__((noreturn));
694 extern void errx(int, const char *, ...) __attribute__((noreturn));
695 extern void verr(int, const char *, va_list) __attribute__((noreturn));
696 extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
697 extern void verrx(int, const char *, va_list) __attribute__((noreturn));
698 extern void warn(const char *, ...);
699 extern void warnx(const char *, ...);
700 extern void warnc(int, const char *, ...);
701 extern void vwarn(const char *, va_list);
702 extern void vwarnc(int, const char *, va_list);
703 extern void vwarnx(const char *, va_list);
704 __HEREDOC__
706 [ ${HAVE_EXPLICIT_BZERO} -eq 0 ] && \
707 cat << __HEREDOC__
708 /*
709 * Compatibility for explicit_bzero(3).
710 */
711 extern void explicit_bzero(void *, size_t);
713 __HEREDOC__
715 [ ${HAVE_FREEZERO} -eq 0 ] && \
716 cat << __HEREDOC__
717 /*
718 * Compatibility for freezero(3).
719 */
720 extern void freezero(void *, size_t);
722 __HEREDOC__
724 [ ${HAVE_MEMMEM} -eq 0 ] && \
725 cat << __HEREDOC__
726 /*
727 * Compatibility for memmem(3).
728 */
729 void *memmem(const void *, size_t, const void *, size_t);
731 __HEREDOC__
733 [ ${HAVE_MEMRCHR} -eq 0 ] && \
734 cat << __HEREDOC__
735 /*
736 * Compatibility for memrchr(3).
737 */
738 void *memrchr(const void *b, int, size_t);
740 __HEREDOC__
742 [ ${HAVE_GETPROGNAME} -eq 0 ] && \
743 cat << __HEREDOC__
744 /*
745 * Compatibility for getprogname(3).
746 */
747 extern const char *getprogname(void);
749 __HEREDOC__
751 [ ${HAVE_REALLOCARRAY} -eq 0 ] && \
752 cat << __HEREDOC__
753 /*
754 * Compatibility for reallocarray(3).
755 */
756 extern void *reallocarray(void *, size_t, size_t);
758 __HEREDOC__
760 [ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
761 cat << __HEREDOC__
762 /*
763 * Compatibility for recallocarray(3).
764 */
765 extern void *recallocarray(void *, size_t, size_t, size_t);
767 __HEREDOC__
769 [ ${HAVE_SETPROCTITLE} -eq 0 ] && \
770 cat << __HEREDOC__
771 /*
772 * Compatibility for setproctitle(3).
773 */
774 extern void setproctitle(const char *, ...);
776 __HEREDOC__
778 [ ${HAVE_STRLCAT} -eq 0 ] && \
779 cat << __HEREDOC__
780 /*
781 * Compatibility for strlcat(3).
782 */
783 extern size_t strlcat(char *, const char *, size_t);
785 __HEREDOC__
787 [ ${HAVE_STRLCPY} -eq 0 ] && \
788 cat << __HEREDOC__
789 /*
790 * Compatibility for strlcpy(3).
791 */
792 extern size_t strlcpy(char *, const char *, size_t);
794 __HEREDOC__
796 [ ${HAVE_STRNDUP} -eq 0 ] && \
797 cat << __HEREDOC__
798 /*
799 * Compatibility for strndup(3).
800 */
801 extern char *strndup(const char *, size_t);
803 __HEREDOC__
805 [ ${HAVE_STRNLEN} -eq 0 ] && \
806 cat << __HEREDOC__
807 /*
808 * Compatibility for strnlen(3).
809 */
810 extern size_t strnlen(const char *, size_t);
812 __HEREDOC__
814 [ ${HAVE_STRTONUM} -eq 0 ] && \
815 cat << __HEREDOC__
816 /*
817 * Compatibility for strotnum(3).
818 */
819 extern long long strtonum(const char *, long long, long long, const char **);
821 __HEREDOC__
823 if [ ${HAVE_SYS_QUEUE} -eq 0 ]; then
824 cat << __HEREDOC__
825 #include "queue.h"
826 __HEREDOC__
827 else
828 echo "#include <sys/queue.h>"
829 echo
830 fi
832 echo "#include <sys/uio.h>"
833 echo "#include <stdint.h>"
834 if [ ${HAVE_IMSG} -eq 0 ]; then
835 echo "#include \"imsg.h\""
836 else
837 echo "#include <imsg.h>"
838 fi
839 echo
841 if [ "${HAVE_LIBEVENT2}" -eq 1 ]; then
842 cat << __HEREDOC__
843 #include <event2/event.h>
844 #include <event2/event_compat.h>
845 #include <event2/event_struct.h>
846 #include <event2/buffer.h>
847 #include <event2/buffer_compat.h>
848 #include <event2/bufferevent.h>
849 #include <event2/bufferevent_struct.h>
850 #include <event2/bufferevent_compat.h>
852 __HEREDOC__
853 elif [ "${HAVE_LIBEVENT}" -eq 1 ]; then
854 cat << __HEREDOC__
855 #include <event.h>
857 __HEREDOC__
858 fi
860 cat << __HEREDOC__
861 #ifndef __dead
862 # define __dead __attribute__((noreturn))
863 #endif
865 #if !HAVE_SIO_FLUSH
866 #define sio_flush(hdl) (sio_stop(hdl))
867 #endif
869 #if !HAVE_GETDTABLECOUNT
870 /* XXX: on linux it should be possible to inspect /proc/self/fd/ */
871 #define getdtablecount() (0)
872 #endif
874 #if !HAVE_OPTRESET
875 /* replace host' getopt with OpenBSD' one */
876 #define opterr BSDopterr
877 #define optind BSDoptind
878 #define optopt BSDoptopt
879 #define optreset BSDoptreset
880 #define optarg BSDoptarg
881 #define getopt BSDgetopt
883 extern int BSDopterr, BSDoptind, BSDoptopt, BSDoptreset;
884 extern char *BSDoptarg;
885 #endif
887 #endif /*!OCONFIGURE_CONFIG_H*/
888 __HEREDOC__
890 echo "config.h: written" 1>&2
891 echo "config.h: written" 1>&3
893 #----------------------------------------------------------------------
894 # Now we go to generate our Makefile.configure.
895 # This file is simply a bunch of Makefile variables.
896 # They'll work in both GNUmakefile and BSDmakefile.
897 # You MIGHT want to change this.
898 #----------------------------------------------------------------------
900 exec > Makefile.configure
902 [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
903 [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
904 [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
905 [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
906 [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
907 [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
909 [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
910 [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
911 [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
912 [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
914 cat << __HEREDOC__
915 CC = ${CC}
916 CFLAGS = ${CFLAGS}
917 CPPFLAGS = ${CPPFLAGS}
918 LDADD = ${LDADD} ${LDADD_IMSG} ${LDADD_LIB_FLAC} ${LDADD_LIB_MPG123} \
919 ${LDADD_LIB_OPUSFILE} ${LDADD_LIB_VORBISFILE} ${LDADD_LIB_SOCKET} \
920 ${LDADD_LIBEVENT} ${LDADD_LIBEVENT2} ${LDADD_LIB_SNDIO}
921 LDADD_STATIC = ${LDADD_STATIC}
922 LDFLAGS = ${LDFLAGS}
923 STATIC = ${STATIC}
924 PREFIX = ${PREFIX}
925 BINDIR = ${BINDIR}
926 SHAREDIR = ${SHAREDIR}
927 SBINDIR = ${SBINDIR}
928 INCLUDEDIR = ${INCLUDEDIR}
929 LIBDIR = ${LIBDIR}
930 MANDIR = ${MANDIR}
931 INSTALL = ${INSTALL}
932 INSTALL_PROGRAM = ${INSTALL_PROGRAM}
933 INSTALL_LIB = ${INSTALL_LIB}
934 INSTALL_MAN = ${INSTALL_MAN}
935 INSTALL_DATA = ${INSTALL_DATA}
936 __HEREDOC__
938 echo "Makefile.configure: written" 1>&2
939 echo "Makefile.configure: written" 1>&3
941 exit 0