3 1610f954 2023-06-13 op # Copyright (c) 2021, 2022, 2023 Omar Polo <op@omarpolo.com>
4 cb2b8551 2022-07-04 op # Copyright (c) 2011, 2013-2022 Ingo Schwarze <schwarze@openbsd.org>
5 cb2b8551 2022-07-04 op # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
7 12042ad7 2021-01-21 op # Permission to use, copy, modify, and distribute this software for any
8 12042ad7 2021-01-21 op # purpose with or without fee is hereby granted, provided that the above
9 12042ad7 2021-01-21 op # copyright notice and this permission notice appear in all copies.
11 12042ad7 2021-01-21 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 12042ad7 2021-01-21 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 12042ad7 2021-01-21 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 12042ad7 2021-01-21 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 12042ad7 2021-01-21 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 12042ad7 2021-01-21 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 12042ad7 2021-01-21 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 33a54252 2024-01-24 op VERSION=2.0.1-current
26 1610f954 2023-06-13 op echo "usage: $0 [--help] [--prefix=prefix] [OPTION=VALUE...]" >&2
30 1610f954 2023-06-13 op if command -v yacc 2>/dev/null >&2; then
32 1610f954 2023-06-13 op elif command -v bison 2>/dev/null >&2; then
35 1610f954 2023-06-13 op # assume yacc by default. Make will fail building parse.y if
36 1610f954 2023-06-13 op # not from a release tarball, but at least it'll have a decent
37 1610f954 2023-06-13 op # error message.
45 1610f954 2023-06-13 op if [ "$RELEASE" = no ]; then
46 1610f954 2023-06-13 op CFLAGS=${CFLAGS:--O0 -g3}
48 1610f954 2023-06-13 op CFLAGS=${CFLAGS:--O2 -pipe}
51 f5dc7edd 2023-08-13 op INSTALL=${INSTALL-install}
52 1610f954 2023-06-13 op PREFIX=${PREFIX-/usr/local}
53 0d5282b6 2024-01-11 op SYSCONFDIR=${SYSCONFDIR-/etc}
56 1610f954 2023-06-13 op CDIAGFLAGS="${CDIAGFLAGS} -W -Wall -Wextra -Wpointer-arith -Wuninitialized"
57 1610f954 2023-06-13 op CDIAGFLAGS="${CDIAGFLAGS} -Wstrict-prototypes -Wmissing-prototypes -Wunused"
58 1610f954 2023-06-13 op CDIAGFLAGS="${CDIAGFLAGS} -Wsign-compare -Wno-unused-parameter" # -Wshadow
59 1610f954 2023-06-13 op CDIAGFLAGS="${CDIAGFLAGS} -Wno-missing-field-initializers"
60 f9ab77a8 2023-08-23 op CDIAGFLAGS="${CDIAGFLAGS} -Wno-pointer-sign"
62 8f543d94 2024-02-02 op # On all OSes except OpenBSD use the bundled one. It may crash at
63 8f543d94 2024-02-02 op # runtime otherwise since we depend on the libtls internals for the
64 8f543d94 2024-02-02 op # privsep crypto engine.
65 8f543d94 2024-02-02 op # See <https://codeberg.org/op/gmid/issues/2>.
66 f9ab77a8 2023-08-23 op LIBTLS=bundled # or system
67 f9ab77a8 2023-08-23 op if [ "$(uname || true)" = OpenBSD ]; then
71 1610f954 2023-06-13 op while [ $# -gt 0 ]; do
72 1610f954 2023-06-13 op key="${1%%=*}"
75 1610f954 2023-06-13 op if [ "$key" = --help ]; then
79 1610f954 2023-06-13 op if [ "$key" = -Werror ]; then
80 1610f954 2023-06-13 op CDIAGFLAGS="$CDIAGFLAGS -Werror"
85 1610f954 2023-06-13 op if [ "$key" = --enable-sandbox ]; then
86 1610f954 2023-06-13 op key=DISABLE_SANDBOX
90 1610f954 2023-06-13 op if [ "$key" = --disable-sandbox ]; then
91 1610f954 2023-06-13 op key=DISABLE_SANDBOX
95 1610f954 2023-06-13 op if [ "$key" = "$1" ]; then
96 1610f954 2023-06-13 op # if no --xy=, look at the next arg
97 1610f954 2023-06-13 op if ! shift 2>/dev/null; then
98 1610f954 2023-06-13 op echo "$0: missing value for $key" >&2
104 1610f954 2023-06-13 op case "$key" in
105 1610f954 2023-06-13 op --bindir) key=BINDIR ;;
106 1610f954 2023-06-13 op --mandir) key=MANDIR ;;
107 1610f954 2023-06-13 op --prefix) key=PREFIX ;;
108 0d5282b6 2024-01-11 op --sysconfdir) key=SYSCONFDIR ;;
109 f9ab77a8 2023-08-23 op --with-libtls) key=LIBTLS ;;
112 1610f954 2023-06-13 op case "$key" in
114 f9ab77a8 2023-08-23 op case "$val" in
115 f9ab77a8 2023-08-23 op bundled) LIBTLS=bundled ;;
116 f9ab77a8 2023-08-23 op system) LIBTLS=system ;;
120 1610f954 2023-06-13 op BINDIR) BINDIR="$val" ;;
121 1610f954 2023-06-13 op CC) CC="$val" ;;
122 1610f954 2023-06-13 op CFLAGS) CFLAGS="$val" ;;
123 1610f954 2023-06-13 op CDIAGFLAGS) CDIAGFLAGS="$val" ;;
124 1610f954 2023-06-13 op DISABLE_SANDBOX) DISABLE_SANDBOX="$val" ;;
125 f5dc7edd 2023-08-13 op INSTALL) INSTALL="$val" ;;
126 1610f954 2023-06-13 op LDFLAGS) LDFLAGS="$val" ;;
127 6bce8180 2024-01-14 op MANDIR) MANDIR="$val" ;;
128 1610f954 2023-06-13 op PKG_CONFIG) PKG_CONFIG="$val" ;;
129 1610f954 2023-06-13 op PREFIX) PREFIX="$val" ;;
130 0d5282b6 2024-01-11 op SYSCONFDIR) SYSCONFDIR="$val" ;;
131 1610f954 2023-06-13 op YACC) YACC="$val" ;;
138 1610f954 2023-06-13 op [ -w config.log ] && mv config.log config.log.old
139 1610f954 2023-06-13 op [ -w config.h ] && mv config.h config.h.old
141 1610f954 2023-06-13 op exec 3> config.log
142 1610f954 2023-06-13 op echo "file config.log: writing..."
144 1610f954 2023-06-13 op NEED_GNU_SOURCE=0
145 1610f954 2023-06-13 op NEED_OPENBSD_SOURCE=0
146 d13b044d 2023-08-07 op NEED_LIBBSD_OPENBSD_VIS=0
149 1610f954 2023-06-13 op COMP="${CC} ${CFLAGS} -Wno-unused -Werror"
151 1610f954 2023-06-13 op # singletest name var extra-cflags extra-libs msg
152 1610f954 2023-06-13 op singletest() {
154 1610f954 2023-06-13 op if [ -z "$msg" ]; then
155 1610f954 2023-06-13 op if [ -n "$3" ]; then
157 1610f954 2023-06-13 op elif [ -n "$4" ]; then
160 1610f954 2023-06-13 op elif [ "$msg" = no ]; then
164 1610f954 2023-06-13 op cat >&3 <<EOF
165 1610f954 2023-06-13 op ${1}: testing...
166 1610f954 2023-06-13 op $COMP have/${1}.c $3 -o test-$1 $LDFLAGS $4
168 1610f954 2023-06-13 op if $COMP have/${1}.c $3 -o test-$1 $LDFLAGS $4 >&3 2>&3; then
169 1610f954 2023-06-13 op rm -f test-${1} test-${1}.d
171 1610f954 2023-06-13 op echo "${1}: $CC$msg succeeded" >&3
172 1610f954 2023-06-13 op echo "${1}$msg: yes"
178 1610f954 2023-06-13 op echo "${1}: $CC$msg failed $?" >&3
179 1610f954 2023-06-13 op echo "${1}$msg: no"
185 1610f954 2023-06-13 op # deptest name var
187 1610f954 2023-06-13 op if singletest "$1" "$2" "${CFLAGS}" "${LIBS}" no; then
188 1610f954 2023-06-13 op eval HAVE_${2}=1
192 1610f954 2023-06-13 op if [ -f compat/${1}.c ]; then
193 1610f954 2023-06-13 op COMPATS="compat/$1.c $COMPATS"
196 12042ad7 2021-01-21 op eval HAVE_${2}=0
200 1610f954 2023-06-13 op # runtest name var extra-cflags extra-libs pkgconfig-name
202 1610f954 2023-06-13 op if singletest "$1" "$2" "" ""; then
203 1610f954 2023-06-13 op eval HAVE_${2}=1
207 1610f954 2023-06-13 op if [ -n "$3" -o -n "$4" ]; then
208 1610f954 2023-06-13 op echo "retrying with ${3+$3 }$4" >&3
209 1610f954 2023-06-13 op if singletest "$1" "$2" "$3" "$4"; then
210 1610f954 2023-06-13 op eval HAVE_${2}=1
211 1610f954 2023-06-13 op if [ "$3" = -D_GNU_SOURCE ]; then
212 1610f954 2023-06-13 op NEED_GNU_SOURCE=1
215 1610f954 2023-06-13 op if [ "$4" = -D_OPENBSD_SOURCE ]; then
216 1610f954 2023-06-13 op NEED_OPENBSD_SOURCE=1
219 d13b044d 2023-08-07 op if [ "$4" = -DLIBBSD_OPENBSD_VIS ]; then
220 d13b044d 2023-08-07 op NEED_LIBBSD_OPENBSD_VIS=1
223 1610f954 2023-06-13 op if [ -n "$3" ]; then
224 1610f954 2023-06-13 op CFLAGS="$CFLAGS $3"
226 1610f954 2023-06-13 op if [ -n "$4" ]; then
227 1610f954 2023-06-13 op LIBS="$LIBS $4"
233 1610f954 2023-06-13 op if [ -n "$5" -a -n "$pkgconfig" ]; then
234 1610f954 2023-06-13 op if $pkgconfig $5; then
235 3d0204e7 2023-06-23 op cflags="$($pkgconfig --cflags $5)"
236 3d0204e7 2023-06-23 op ldflags="$($pkgconfig --libs $5)"
237 1610f954 2023-06-13 op echo "retrying with pkg-config" >&3
238 1610f954 2023-06-13 op if singletest "$1" "$2" "$cflags" "$ldflags"; then
239 1610f954 2023-06-13 op CFLAGS="$CFLAGS $cflags"
240 1610f954 2023-06-13 op LIBS="$LIBS $ldflags"
241 1610f954 2023-06-13 op eval HAVE_$2=1
247 1610f954 2023-06-13 op if [ -f compat/$1.c ]; then
248 1610f954 2023-06-13 op COMPATS="compat/$1.c $COMPATS"
251 1610f954 2023-06-13 op eval HAVE_$2=0
255 1610f954 2023-06-13 op if [ "$PKG_CONFIG" = no ]; then
256 1610f954 2023-06-13 op echo "pkg-config: disabled"
257 1610f954 2023-06-13 op elif [ -n "$PKG_CONFIG" ]; then
258 1610f954 2023-06-13 op pkgconfig="$PKG_CONFIG"
259 1610f954 2023-06-13 op echo "pkg-config: (manual) $PKG_CONFIG"
260 1610f954 2023-06-13 op elif command -v pkg-config 2>/dev/null >&2; then
261 1610f954 2023-06-13 op pkgconfig="pkg-config"
262 1610f954 2023-06-13 op echo "pkg-config: (auto) pkg-config"
264 1610f954 2023-06-13 op echo "pkg-config: not found"
267 1610f954 2023-06-13 op if singletest noop MMD -MMD; then
268 68e38f49 2023-06-08 op CFLAGS="${CFLAGS} -MMD"
271 c144b1b6 2023-06-08 op if ! runtest wait_any WAIT_ANY; then
272 c144b1b6 2023-06-08 op CFLAGS="${CFLAGS} -DWAIT_ANY=-1"
275 5d2f4b16 2023-07-02 op HAVE_ENDIAN_H=0
276 5d2f4b16 2023-07-02 op HAVE_SYS_ENDIAN_H=0
277 5d2f4b16 2023-07-02 op HAVE_MACHINE_ENDIAN=0
279 5d2f4b16 2023-07-02 op runtest endian_h ENDIAN_H || \
280 5d2f4b16 2023-07-02 op runtest sys_endian_h SYS_ENDIAN_H || \
281 5d2f4b16 2023-07-02 op runtest machine_endian MACHINE_ENDIAN || true
283 5d2f4b16 2023-07-02 op if [ ${HAVE_ENDIAN_H} -eq 0 -a \
284 5d2f4b16 2023-07-02 op ${HAVE_SYS_ENDIAN_H} -eq 0 -a \
285 5d2f4b16 2023-07-02 op ${HAVE_MACHINE_ENDIAN} -eq 0 ]; then
286 5d2f4b16 2023-07-02 op echo "FATAL: no endian header found" 1>&2
287 5d2f4b16 2023-07-02 op echo "FATAL: no endian header found" 1>&3
291 f9ab77a8 2023-08-23 op runtest arc4random ARC4RANDOM || true
292 f9ab77a8 2023-08-23 op runtest arc4random_buf ARC4RANDOM_BUF || true
293 12042ad7 2021-01-21 op runtest err ERR || true
294 5c342d05 2021-01-21 op runtest explicit_bzero EXPLICIT_BZERO || true
295 aa627c91 2021-02-23 op runtest freezero FREEZERO || true
296 aa627c91 2021-02-23 op runtest getdtablecount GETDTABLECOUNT || true
297 e30e5385 2021-09-18 op runtest getdtablesize GETDTABLESIZE || true
298 2d7abb70 2021-01-21 op runtest getprogname GETPROGNAME || true
299 1610f954 2023-06-13 op runtest imsg IMSG "" -lutil libimsg || true
300 4d9d3093 2023-08-23 op runtest landlock LANDLOCK || true
301 1610f954 2023-06-13 op runtest libevent LIBEVENT "" -levent libevent_core|| true
302 1610f954 2023-06-13 op runtest memmem MEMMEM -D_GNU_SOURCE || true
303 1610f954 2023-06-13 op runtest openssl OPENSSL "" '-lcrypto -lssl' 'libcrypto libssl' || true
304 fe90d24f 2021-02-04 op runtest pr_set_name PR_SET_NAME || true
305 1610f954 2023-06-13 op runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME -D_GNU_SOURCE || true
306 6b191ed5 2021-02-23 op runtest queue_h QUEUE_H || true
307 1610f954 2023-06-13 op runtest reallocarray REALLOCARRAY -D_OPENBSD_SOURCE || true
308 5c342d05 2021-01-21 op runtest recallocarray RECALLOCARRAY || true
309 fe90d24f 2021-02-04 op runtest setproctitle SETPROCTITLE || true
310 1610f954 2023-06-13 op runtest setresgid SETRESGID -D_GNU_SOURCE || true
311 1610f954 2023-06-13 op runtest setresuid SETRESUID -D_GNU_SOURCE || true
312 12042ad7 2021-01-21 op runtest strlcat STRLCAT || true
313 12042ad7 2021-01-21 op runtest strlcpy STRLCPY || true
314 1610f954 2023-06-13 op runtest strtonum STRTONUM -D_OPENBSD_SOURCE || true
315 f9ab77a8 2023-08-23 op runtest timingsafe_memcmp TIMINGSAFE_MEMCMP || true
316 492a274f 2021-10-07 op runtest tree_h TREE_H || true
317 1610f954 2023-06-13 op runtest vasprintf VASPRINTF -D_GNU_SOURCE || true
318 d13b044d 2023-08-07 op runtest vis VIS -DLIBBSD_OPENBSD_VIS || true
320 f9ab77a8 2023-08-23 op if [ ${HAVE_ARC4RANDOM} -eq 1 -a ${HAVE_ARC4RANDOM_BUF} -eq 0 ]; then
321 f9ab77a8 2023-08-23 op COMPATS="compat/arc4random.c ${COMPATS}"
324 74c6900c 2023-08-23 op if [ ${HAVE_ARC4RANDOM} -eq 0 ]; then
325 74c6900c 2023-08-23 op runtest getentropy GETENTROPY || true
328 ae32f1aa 2023-08-23 op HAVE_GETENTROPY=1
331 f9ab77a8 2023-08-23 op if [ ${HAVE_ARC4RANDOM} -eq 0 -a ${HAVE_GETENTROPY} -eq 1 ]; then
332 f9ab77a8 2023-08-23 op COMPATS="compat/getentropy.c ${COMPATS}"
335 f9ab77a8 2023-08-23 op if [ "${LIBTLS}" = system ]; then
336 f9ab77a8 2023-08-23 op runtest libtls LIBTLS "" -ltls libtls || true
338 f9ab77a8 2023-08-23 op # not actually needed
339 f9ab77a8 2023-08-23 op HAVE_ASN1_TIME_TM_CMP=1
340 f9ab77a8 2023-08-23 op HAVE_ASN1_TIME_TM_CLAMP_NOTAFTER=1
341 f9ab77a8 2023-08-23 op HAVE_ASN1_TIME_PARSE=1
342 f9ab77a8 2023-08-23 op HAVE_SSL_CTX_UCCM=1
343 f9ab77a8 2023-08-23 op HAVE_SSL_CTX_LVM=1
344 f9ab77a8 2023-08-23 op HAVE_X509_LOOKUP_MEM=1
346 f9ab77a8 2023-08-23 op # use bundled one
347 f9ab77a8 2023-08-23 op HAVE_LIBTLS=1
348 f9ab77a8 2023-08-23 op for f in compat/libtls/*.c; do
349 f9ab77a8 2023-08-23 op COMPATS="$f ${COMPATS}"
352 cedef5b0 2023-08-23 op CFLAGS="-Icompat/libtls -I../compat/libtls ${CFLAGS}"
354 f9ab77a8 2023-08-23 op deptest ASN1_time_tm_cmp ASN1_TIME_TM_CMP || true
355 f9ab77a8 2023-08-23 op deptest ASN1_time_tm_clamp_notafter ASN1_TIME_TM_CLAMP_NOTAFTER || true
356 f9ab77a8 2023-08-23 op deptest ASN1_time_parse ASN1_TIME_PARSE || true
357 f9ab77a8 2023-08-23 op deptest SSL_CTX_use_certificate_chain_mem SSL_CTX_UCCM || true
358 f9ab77a8 2023-08-23 op deptest SSL_CTX_load_verify_mem SSL_CTX_LVM || true
359 f9ab77a8 2023-08-23 op deptest X509_LOOKUP_mem X509_LOOKUP_MEM || true
362 1610f954 2023-06-13 op deptest libevent2 LIBEVENT2 || true
364 12042ad7 2021-01-21 op if [ ${HAVE_LIBTLS} -eq 0 ]; then
365 f9ab77a8 2023-08-23 op echo "FATAL: openssl not found" 1>&2
366 f9ab77a8 2023-08-23 op echo "FATAL: openssl not found" 1>&3
370 8443bff7 2021-01-25 op if [ ${HAVE_OPENSSL} -eq 0 ]; then
371 8443bff7 2021-01-25 op echo "FATAL: openssl not found" 1>&2
372 8443bff7 2021-01-25 op echo "FATAL: openssl not found" 1>&3
376 337c7420 2021-02-08 op if [ ${HAVE_LIBEVENT} -eq 0 ]; then
377 337c7420 2021-02-08 op echo "FATAL: libevent not found" 1>&2
378 337c7420 2021-02-08 op echo "FATAL: libevent not found" 1>&3
382 1610f954 2023-06-13 op if [ ${HAVE_IMSG} -eq 0 ]; then
383 1610f954 2023-06-13 op # compat/imsg.c is implicitly added
384 1610f954 2023-06-13 op COMPATS="$COMPATS compat/imsg-buffer.c"
387 492a274f 2021-10-07 op if [ ${HAVE_QUEUE_H} -eq 0 -o ${HAVE_IMSG} -eq 0 -o ${HAVE_TREE_H} -eq 0 ]; then
388 6b191ed5 2021-02-23 op CFLAGS="${CFLAGS} -I ${PWD}/compat"
391 d13b044d 2023-08-07 op if [ ${HAVE_VIS} -eq 0 ]; then
392 d13b044d 2023-08-07 op CFLAGS="${CFLAGS} -I ${PWD}/compat/vis"
395 1610f954 2023-06-13 op if [ $HAVE_LIBEVENT2 -eq 1 ]; then
396 1610f954 2023-06-13 op CFLAGS="$CFLAGS -DHAVE_LIBEVENT2=1"
399 1610f954 2023-06-13 op if [ $NEED_GNU_SOURCE = 1 ]; then
400 1610f954 2023-06-13 op CFLAGS="$CFLAGS -D_GNU_SOURCE"
402 1610f954 2023-06-13 op if [ $NEED_OPENBSD_SOURCE = 1 ]; then
403 1610f954 2023-06-13 op CFLAGS="$CFLAGS -D_OPENBSD_SOURCE"
405 d13b044d 2023-08-07 op if [ $NEED_LIBBSD_OPENBSD_VIS = 1 ]; then
406 d13b044d 2023-08-07 op CFLAGS="$CFLAGS -DLIBBSD_OPENBSD_VIS"
409 f9ab77a8 2023-08-23 op CFLAGS="-I. ${CFLAGS} ${CDIAGFLAGS}"
411 12042ad7 2021-01-21 op exec > config.h
412 1610f954 2023-06-13 op echo "config.h: writing.." >&2
414 12042ad7 2021-01-21 op cat <<__HEREDOC__
415 12042ad7 2021-01-21 op #ifdef __cplusplus
416 12042ad7 2021-01-21 op #error "Do not use C++."
420 6b191ed5 2021-02-23 op [ ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 -o ${HAVE_IMSG} -eq 0 ] \
421 12042ad7 2021-01-21 op && echo "#include <sys/types.h>"
422 12042ad7 2021-01-21 op [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include <stdarg.h>"
424 6b191ed5 2021-02-23 op if [ ${HAVE_QUEUE_H} -eq 1 ]; then
425 6b191ed5 2021-02-23 op echo "#include <sys/queue.h>"
427 6b191ed5 2021-02-23 op echo "#include <queue.h>"
430 492a274f 2021-10-07 op if [ ${HAVE_TREE_H} -eq 1 ]; then
431 492a274f 2021-10-07 op echo "#include <sys/tree.h>"
433 492a274f 2021-10-07 op echo "#include <tree.h>"
436 fda7b99f 2021-02-23 op echo "#include <sys/types.h>"
437 6b191ed5 2021-02-23 op echo "#include <sys/uio.h>"
438 6b191ed5 2021-02-23 op echo "#include <stdint.h>"
439 6b191ed5 2021-02-23 op echo "#include <imsg.h>"
440 fad3441b 2022-10-30 op echo "#include <limits.h>"
442 12042ad7 2021-01-21 op cat <<__HEREDOC__
444 f361f799 2021-07-10 op #define VERSION "${VERSION}"
445 8bb8cf2a 2021-07-02 op #define DISABLE_SANDBOX ${DISABLE_SANDBOX}
446 4d9d3093 2023-08-23 op #define HAVE_LANDLOCK ${HAVE_LANDLOCK}
448 0d5282b6 2024-01-11 op #ifndef SYSCONFDIR
449 0d5282b6 2024-01-11 op # define SYSCONFDIR "${SYSCONFDIR}"
454 5d2f4b16 2023-07-02 op if [ ${HAVE_ENDIAN_H} -eq 1 ]; then
455 5d2f4b16 2023-07-02 op echo "#include <endian.h>"
456 5d2f4b16 2023-07-02 op elif [ ${HAVE_SYS_ENDIAN_H} -eq 1 ]; then
457 5d2f4b16 2023-07-02 op echo "#include <sys/endian.h>"
458 5d2f4b16 2023-07-02 op elif [ ${HAVE_MACHINE_ENDIAN} -eq 1 ]; then
459 5d2f4b16 2023-07-02 op cat <<__HEREDOC__
460 5d2f4b16 2023-07-02 op #include <machine/endian.h>
461 5d2f4b16 2023-07-02 op #include <libkern/OSByteOrder.h>
463 822125ca 2024-01-07 op # define htobe16(x) OSSwapHostToBigInt16(x)
464 822125ca 2024-01-07 op # define htole16(x) OSSwapHostToLittleInt16(x)
465 822125ca 2024-01-07 op # define be16toh(x) OSSwapBigToHostInt16(x)
466 822125ca 2024-01-07 op # define le16toh(x) OSSwapLittleToHostInt16(x)
468 822125ca 2024-01-07 op # define htobe32(x) OSSwapHostToBigInt32(x)
469 822125ca 2024-01-07 op # define htole32(x) OSSwapHostToLittleInt32(x)
470 822125ca 2024-01-07 op # define be32toh(x) OSSwapBigToHostInt32(x)
471 822125ca 2024-01-07 op # define le32toh(x) OSSwapLittleToHostInt32(x)
473 822125ca 2024-01-07 op # define htobe64(x) OSSwapHostToBigInt64(x)
474 822125ca 2024-01-07 op # define htole64(x) OSSwapHostToLittleInt64(x)
475 822125ca 2024-01-07 op # define be64toh(x) OSSwapBigToHostInt64(x)
476 822125ca 2024-01-07 op # define le64toh(x) OSSwapLittleToHostInt64(x)
480 f9ab77a8 2023-08-23 op [ ${HAVE_ARC4RANDOM_BUF} -eq 0 -o \
481 f9ab77a8 2023-08-23 op ${HAVE_ASN1_TIME_PARSE} -eq 0 -o \
482 f9ab77a8 2023-08-23 op ${HAVE_EXPLICIT_BZERO} -eq 0 -o \
483 aa627c91 2021-02-23 op ${HAVE_FREEZERO} -eq 0 -o \
484 f9ab77a8 2023-08-23 op ${HAVE_GETENTROPY} -eq 0 -o \
485 578f13e4 2021-04-25 op ${HAVE_REALLOCARRAY} -eq 0 -o \
486 7e262563 2021-01-22 op ${HAVE_RECALLOCARRAY} -eq 0 -o \
487 7e262563 2021-01-22 op ${HAVE_STRLCAT} -eq 0 -o \
488 7e262563 2021-01-22 op ${HAVE_STRLCPY} -eq 0 -o \
489 f9ab77a8 2023-08-23 op ${HAVE_STRTONUM} -eq 0 -o \
490 f9ab77a8 2023-08-23 op ${HAVE_TIMINGSAFE_MEMCMP} -eq 0 ] && echo "#include <stddef.h>"
492 f9ab77a8 2023-08-23 op [ ${HAVE_ARC4RANDOM} -eq 0 ] && echo "#include <stdint.h>"
494 bd8683d0 2022-12-02 op [ ${HAVE_SETRESGID} -eq 0 -o \
495 bd8683d0 2022-12-02 op ${HAVE_SETRESUID} -eq 0 ] && echo "#include <unistd.h>"
497 f9ab77a8 2023-08-23 op if [ ${HAVE_GETENTROPY} -eq 1 ]; then
498 f9ab77a8 2023-08-23 op echo "#define HAVE_GETENTROPY 1"
500 f9ab77a8 2023-08-23 op echo "#define WITH_OPENSSL 1"
501 f9ab77a8 2023-08-23 op echo "#define OPENSSL_PRNG_ONLY 1"
504 f9ab77a8 2023-08-23 op if [ ${HAVE_ARC4RANDOM} -eq 0 ]; then
505 f9ab77a8 2023-08-23 op echo "extern uint32_t arc4random(void);"
507 f9ab77a8 2023-08-23 op echo "#define HAVE_ARC4RANDOM 1"
509 f9ab77a8 2023-08-23 op if [ ${HAVE_ARC4RANDOM_BUF} -eq 0 ]; then
510 f9ab77a8 2023-08-23 op echo "extern void arc4random_buf(void *, size_t);"
512 f9ab77a8 2023-08-23 op echo "#define HAVE_ARC4RANDOM_BUF 1"
515 f9ab77a8 2023-08-23 op if [ ${HAVE_ASN1_TIME_TM_CMP} -eq 0 ]; then
516 f9ab77a8 2023-08-23 op echo "struct tm;"
517 f9ab77a8 2023-08-23 op echo "extern int ASN1_time_tm_cmp(struct tm *, struct tm *);"
519 f9ab77a8 2023-08-23 op echo "#define HAVE_ASN1_TIME_TM_CMP 1"
522 f9ab77a8 2023-08-23 op if [ ${HAVE_ASN1_TIME_TM_CLAMP_NOTAFTER} -eq 0 ]; then
523 f9ab77a8 2023-08-23 op echo "struct tm;"
524 f9ab77a8 2023-08-23 op echo "extern int ASN1_time_tm_clamp_notafter(struct tm *);"
526 f9ab77a8 2023-08-23 op echo "#define HAVE_ASN1_TIME_TM_CLAMP_NOTAFTER 1"
529 f9ab77a8 2023-08-23 op if [ ${HAVE_ASN1_TIME_PARSE} -eq 0 ]; then
530 f9ab77a8 2023-08-23 op echo "struct tm;"
531 f9ab77a8 2023-08-23 op echo "extern int ASN1_time_parse(const char *, size_t, struct tm *, int);"
533 f9ab77a8 2023-08-23 op echo "#define HAVE_ASN1_TIME_PARSE 1"
536 12042ad7 2021-01-21 op if [ ${HAVE_ERR} -eq 0 ]; then
537 12042ad7 2021-01-21 op echo "extern void err(int, const char*, ...);"
538 12042ad7 2021-01-21 op echo "extern void errx(int, const char*, ...);"
539 12042ad7 2021-01-21 op echo "extern void warn(const char*, ...);"
540 12042ad7 2021-01-21 op echo "extern void warnx(const char*, ...);"
542 2d7abb70 2021-01-21 op echo "#include <err.h>"
544 5c342d05 2021-01-21 op if [ ${HAVE_EXPLICIT_BZERO} -eq 0 ]; then
545 5c342d05 2021-01-21 op echo "extern void explicit_bzero(void*, size_t);"
547 aa627c91 2021-02-23 op if [ ${HAVE_FREEZERO} -eq 0 ]; then
548 aa627c91 2021-02-23 op echo "extern void freezero(void*, size_t);"
550 aa627c91 2021-02-23 op if [ ${HAVE_GETDTABLECOUNT} -eq 0 ]; then
551 aa627c91 2021-02-23 op echo "extern int getdtablecount(void);"
553 aa627c91 2021-02-23 op if [ ${HAVE_GETDTABLESIZE} -eq 0 ]; then
554 aa627c91 2021-02-23 op echo "extern int getdtablesize(void);"
556 f9ab77a8 2023-08-23 op if [ ${HAVE_GETENTROPY} -eq 0 ]; then
557 258131b1 2023-08-23 op echo "extern int getentropy(void *, size_t);"
559 333a6711 2021-01-25 op if [ ${HAVE_GETPROGNAME} -eq 0 ]; then
560 333a6711 2021-01-25 op echo "extern const char *getprogname(void);"
562 19a8d9fe 2022-10-31 op if [ ${HAVE_MEMMEM} -eq 0 ]; then
563 19a8d9fe 2022-10-31 op echo "extern void *memmem(const void *, size_t, const void *, size_t);"
565 578f13e4 2021-04-25 op if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then
566 578f13e4 2021-04-25 op echo "extern void *reallocarray(void*, size_t, size_t);"
568 5c342d05 2021-01-21 op if [ ${HAVE_RECALLOCARRAY} -eq 0 ]; then
569 578f13e4 2021-04-25 op echo "extern void *recallocarray(void*, size_t, size_t, size_t);"
571 fe90d24f 2021-02-04 op if [ ${HAVE_SETPROCTITLE} -eq 0 ]; then
572 fe90d24f 2021-02-04 op echo "extern void setproctitle(const char *fmt, ...);"
574 bd8683d0 2022-12-02 op if [ ${HAVE_SETRESGID} -eq 0 ]; then
575 bd8683d0 2022-12-02 op echo "extern int setresgid(gid_t, gid_t, gid_t);"
577 bd8683d0 2022-12-02 op if [ ${HAVE_SETRESUID} -eq 0 ]; then
578 bd8683d0 2022-12-02 op echo "extern int setresuid(uid_t, uid_t, uid_t);"
580 12042ad7 2021-01-21 op if [ ${HAVE_STRLCAT} -eq 0 ]; then
581 12042ad7 2021-01-21 op echo "extern size_t strlcat(char*, const char*, size_t);"
583 12042ad7 2021-01-21 op if [ ${HAVE_STRLCPY} -eq 0 ]; then
584 12042ad7 2021-01-21 op echo "extern size_t strlcpy(char*, const char*, size_t);"
586 5c342d05 2021-01-21 op if [ ${HAVE_STRTONUM} -eq 0 ]; then
587 3527b7a5 2021-01-22 op echo "extern long long strtonum(const char*, long long, long long, const char**);"
589 f9ab77a8 2023-08-23 op if [ ${HAVE_TIMINGSAFE_MEMCMP} -eq 0 ]; then
590 f9ab77a8 2023-08-23 op echo "extern int timingsafe_memcmp(const void *, const void *, size_t);"
592 12042ad7 2021-01-21 op if [ ${HAVE_VASPRINTF} -eq 0 ]; then
593 12042ad7 2021-01-21 op echo "extern int vasprintf(char**, const char*, va_list);"
596 f9ab77a8 2023-08-23 op if [ ${HAVE_ASN1_TIME_TM_CMP} -eq 0 ]; then
597 f9ab77a8 2023-08-23 op echo "#include <openssl/asn1.h>"
598 f9ab77a8 2023-08-23 op echo "struct tm;"
599 f9ab77a8 2023-08-23 op echo "int ASN1_time_tm_cmp(struct tm *, struct tm *);"
601 f9ab77a8 2023-08-23 op echo "#define HAVE_ASN1_TIME_TM_CMP 1"
604 f9ab77a8 2023-08-23 op if [ ${HAVE_SSL_CTX_UCCM} -eq 0 -o ${HAVE_SSL_CTX_LVM} -eq 0 ]; then
605 f9ab77a8 2023-08-23 op echo "#include <openssl/ssl.h>"
608 f9ab77a8 2023-08-23 op if [ ${HAVE_SSL_CTX_UCCM} -eq 0 ]; then
609 f9ab77a8 2023-08-23 op echo "int SSL_CTX_use_certificate_chain_mem(SSL_CTX *, void *, int);"
611 f9ab77a8 2023-08-23 op echo "#define HAVE_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM 1"
614 f9ab77a8 2023-08-23 op if [ ${HAVE_SSL_CTX_LVM} -eq 0 ]; then
615 f9ab77a8 2023-08-23 op echo "int SSL_CTX_load_verify_mem(SSL_CTX *, void *, int);"
617 f9ab77a8 2023-08-23 op echo "#define HAVE_SSL_CTX_LOAD_VERIFY_MEM 1"
620 f9ab77a8 2023-08-23 op if [ ${HAVE_X509_LOOKUP_MEM} -eq 0 ]; then
621 f9ab77a8 2023-08-23 op echo "#include <openssl/x509_vfy.h>"
622 f9ab77a8 2023-08-23 op echo "X509_LOOKUP_METHOD *X509_LOOKUP_mem(void);"
624 f9ab77a8 2023-08-23 op echo "#define HAVE_X509_LOOKUP_MEM 1"
627 7f03b52b 2022-09-08 op cat <<__HEREDOC__
629 7f03b52b 2022-09-08 op #ifndef __dead
630 7f03b52b 2022-09-08 op #define __dead __attribute__((noreturn))
633 fad3441b 2022-10-30 op /* Linux and OpenBSD have LOGIN_NAME_MAX, FreeBSD MAXLOGNAME. */
634 fad3441b 2022-10-30 op #ifndef LOGIN_NAME_MAX
635 fad3441b 2022-10-30 op # if defined(MAXLOGNAME)
636 fad3441b 2022-10-30 op # define LOGIN_NAME_MAX MAXLOGNAME
637 fad3441b 2022-10-30 op # elif defined(_POSIX_LOGIN_NAME_MAX)
638 fad3441b 2022-10-30 op # define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
640 fad3441b 2022-10-30 op # define LOGIN_NAME_MAX 32
644 81417373 2022-10-30 op #ifndef HOST_NAME_MAX
645 81417373 2022-10-30 op # if defined(_POSIX_HOST_NAME_MAX)
646 81417373 2022-10-30 op # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
648 81417373 2022-10-30 op # define HOST_NAME_MAX 255
653 12042ad7 2021-01-21 op echo "file config.h: written" 1>&2
654 12042ad7 2021-01-21 op echo "file config.h: written" 1>&3
656 1610f954 2023-06-13 op exec > config.mk
658 f5dc7edd 2023-08-13 op [ -z "${BINDIR}" ] && BINDIR="\${PREFIX}/bin"
659 f5dc7edd 2023-08-13 op [ -z "${MANDIR}" ] && MANDIR="\${PREFIX}/man"
661 12042ad7 2021-01-21 op cat << __HEREDOC__
663 12042ad7 2021-01-21 op CFLAGS = ${CFLAGS}
664 1610f954 2023-06-13 op LDFLAGS = ${LDFLAGS}
665 1610f954 2023-06-13 op LIBS = ${LIBS}
666 12042ad7 2021-01-21 op YACC = ${YACC}
667 12042ad7 2021-01-21 op STATIC = ${STATIC}
668 12042ad7 2021-01-21 op PREFIX = ${PREFIX}
669 12042ad7 2021-01-21 op BINDIR = ${BINDIR}
670 60dbafbf 2021-02-07 op MANDIR = ${MANDIR}
672 f5dc7edd 2023-08-13 op INSTALL = ${INSTALL}
673 f5dc7edd 2023-08-13 op INSTALL_PROGRAM = \${INSTALL} -m 0555
674 f5dc7edd 2023-08-13 op INSTALL_LIB = \${INSTALL} -m 0444
675 f5dc7edd 2023-08-13 op INSTALL_MAN = \${INSTALL} -m 0444
676 f5dc7edd 2023-08-13 op INSTALL_DATA = \${INSTALL} -m 0444
678 1610f954 2023-06-13 op COMPATS= ${COMPATS}
680 f361f799 2021-07-10 op VERSION = ${VERSION}
684 1610f954 2023-06-13 op echo "file config.mk: written" 1>&2
685 1610f954 2023-06-13 op echo "file config.mk: written" 1>&3
688 1610f954 2023-06-13 op echo "Now run \`make' to compile." >&2