ksgi

Форк
0
/
configure 
2566 строк · 78.6 Кб
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.
17

18
OCONFIGURE_VERSION="0.3.13"
19

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.
39

40
set -e
41

42
#----------------------------------------------------------------------
43
# Prepare for running: move aside previous configure runs.
44
# Output file descriptor usage:
45
#  1 (stdout): config.h or Makefile.configure
46
#  2 (stderr): original stderr, usually to the console
47
#  3: config.log
48
# You DO NOT want to change this.
49
#----------------------------------------------------------------------
50

51
[ -w config.log ] && mv config.log config.log.old
52
[ -w config.h   ] && mv config.h config.h.old
53

54
exec 3> config.log
55
echo "config.log: writing..."
56

57
# GNU submake prints different output if invoked recursively, which
58
# messes up CC and CFLAGS detection.  Pass --no-print-directory if
59
# we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
60
# allowed.
61

62
MAKE_FLAGS=""
63

64
if [ -n "${MAKELEVEL}" ]; then
65
	if [ "${MAKELEVEL}" -gt 0 ] ; then
66
		MAKE_FLAGS="--no-print-directory"
67
		echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
68
	fi
69
fi
70

71
if [ -n "$MAKE_FLAGS" ]; then 
72
	echo "GNU submake detected: using --no-print-directory" 1>&2
73
	echo "GNU submake detected: using --no-print-directory" 1>&3
74
fi
75

76
#----------------------------------------------------------------------
77
# Initialise all variables here such that nothing can leak in from the
78
# environment except for AR, CC and CFLAGS, which we might have passed
79
# in.
80
#----------------------------------------------------------------------
81

82
AR=`printf "all:\\n\\t@echo \\\$(AR)\\n" | make ${MAKE_FLAGS} -sf -`
83
CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
84
CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
85
CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes"
86
CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter"
87
LDLIBS=
88
LDADD=
89
LDADD_B64_NTOP=
90
LDADD_CRYPT=
91
LDADD_MD5=
92
LDADD_SHA2=
93
LDADD_LIB_SOCKET=
94
LDADD_SCAN_SCALED=
95
LDADD_STATIC=
96
CPPFLAGS=
97
LDFLAGS=
98
LINKER_SONAME=
99
DESTDIR=
100
PREFIX="/usr/local"
101
BINDIR=
102
SBINDIR=
103
INCLUDEDIR=
104
LIBDIR=
105
MANDIR=
106
SHAREDIR=
107
INSTALL="install"
108
INSTALL_PROGRAM=
109
INSTALL_LIB=
110
INSTALL_MAN=
111
INSTALL_DATA=
112

113
# SunOS sets "cc", but this doesn't exist.
114
# It does have gcc, so try that instead.
115
# Prefer clang, though.
116

117
command -v ${CC} 2>/dev/null 1>&2 || {
118
	echo "${CC} not found: trying clang" 1>&2
119
	echo "${CC} not found: trying clang" 1>&3
120
	CC=clang
121
	command -v ${CC} 2>/dev/null 1>&2 || {
122
		echo "${CC} not found: trying gcc" 1>&2
123
		echo "${CC} not found: trying gcc" 1>&3
124
		CC=gcc
125
		command -v ${CC} 2>/dev/null 1>&2 || {
126
			echo "gcc not found: giving up" 1>&2
127
			echo "gcc not found: giving up" 1>&3
128
			exit 1
129
		}
130
	}
131
}
132

133
#----------------------------------------------------------------------
134
# Allow certain variables to be overriden on the command line.
135
#----------------------------------------------------------------------
136

137
for keyvals in "$@"
138
do
139
	key=`echo $keyvals | cut -s -d '=' -f 1`
140
	if [ -z "$key" ]
141
	then
142
		echo "$0: invalid key-value: $keyvals" 1>&2
143
		exit 1
144
	fi
145
	val=`echo $keyvals | cut -d '=' -f 2-`
146
	case "$key" in
147
	LDADD)
148
		LDADD="$val" ;;
149
	LDLIBS)
150
		LDLIBS="$val" ;;
151
	LDFLAGS)
152
		LDFLAGS="$val" ;;
153
	LINKER_SONAME)
154
		LINKER_SONAME="$val" ;;
155
	CPPFLAGS)
156
		CPPFLAGS="$val" ;;
157
	DESTDIR)
158
		DESTDIR="$val" ;;
159
	PREFIX)
160
		PREFIX="$val" ;;
161
	MANDIR)
162
		MANDIR="$val" ;;
163
	LIBDIR)
164
		LIBDIR="$val" ;;
165
	BINDIR)
166
		BINDIR="$val" ;;
167
	SHAREDIR)
168
		SHAREDIR="$val" ;;
169
	SBINDIR)
170
		SBINDIR="$val" ;;
171
	INCLUDEDIR)
172
		INCLUDEDIR="$val" ;;
173
	*)
174
		echo "$0: invalid key: $key" 1>&2
175
		exit 1
176
	esac
177
done
178

179
#----------------------------------------------------------------------
180
# If the user doesn't specify whether we want "-soname" or
181
# "-install_name" for the linker option to generate shared libraries,
182
# try to figure it out here.  If we can't figure it out, just set it to
183
# -soname and let the user figure it out.
184

185
if [ -z "$LINKER_SONAME" ]
186
then
187
	test_soname="`mktemp`" || {
188
		echo "mktemp: failed" 1>&2
189
		echo "mktemp: failed" 1>&3
190
		exit 1
191
	}
192
	echo "int foo(void) { return 1; }" > "${test_soname}.c"
193
	${CC} -fPIC -o ${test_soname}.o -c ${test_soname}.c || {
194
		echo "${CC} -fPIC -o ${test_soname}.o -c ${test_soname}.c: failed" 1>&2
195
		echo "${CC} -fPIC -o ${test_soname}.o -c ${test_soname}.c: failed" 1>&3
196
	}
197
	LINKER_SONAME="-soname"
198
	echo "LINKER_SONAME: testing -soname" 1>&3
199
	${CC} -shared -o ${test_soname}.so.0 ${test_soname}.o -Wl,${LINKER_SONAME},${test_soname}.so.0 || {
200
		LINKER_SONAME="-install_name"
201
		echo "LINKER_SONAME: testing -install_name" 1>&3
202
		${CC} -shared -o ${test_soname}.so.0 ${test_soname}.o -Wl,-install_name,${test_soname}.so.0 || {
203
			echo "LINKER_SONAME: cannot determine: default to -soname" 1>&2
204
			echo "LINKER_SONAME: cannot determine: default to -soname" 1>&3
205
			LINKER_SONAME="-soname"
206
		}
207
	}
208
	echo "LINKER_SONAME: $LINKER_SONAME" 1>&3
209
	rm -f "$test_soname" "${test_soname}.*"
210
fi
211

212
#----------------------------------------------------------------------
213
# These are the values that will be pushed into config.h after we test
214
# for whether they're supported or not.
215
# Each of these must have a runtest(), below.
216
# Please sort by alpha, for clarity.
217
# You WANT to change this.
218
#----------------------------------------------------------------------
219

220
HAVE_ARC4RANDOM=
221
HAVE_B64_NTOP=
222
HAVE_CAPSICUM=
223
HAVE_CRYPT=
224
HAVE_CRYPT_NEWHASH=
225
HAVE_ENDIAN_H=
226
HAVE_ERR=
227
HAVE_EXPLICIT_BZERO=
228
HAVE_FTS=
229
HAVE_GETEXECNAME=
230
HAVE_GETPROGNAME=
231
HAVE_INFTIM=
232
HAVE_LANDLOCK=
233
HAVE_MD5=
234
HAVE_MEMMEM=
235
HAVE_MEMRCHR=
236
HAVE_MEMSET_S=
237
HAVE_MKFIFOAT=
238
HAVE_MKNODAT=
239
HAVE_OSBYTEORDER_H=
240
HAVE_PATH_MAX=
241
HAVE_PLEDGE=
242
HAVE_PROGRAM_INVOCATION_SHORT_NAME=
243
HAVE_READPASSPHRASE=
244
HAVE_REALLOCARRAY=
245
HAVE_RECALLOCARRAY=
246
HAVE_SANDBOX_INIT=
247
HAVE_SCAN_SCALED=
248
HAVE_SECCOMP_FILTER=
249
HAVE_SETRESGID=
250
HAVE_SETRESUID=
251
HAVE_SOCK_NONBLOCK=
252
HAVE_SHA2=
253
HAVE_SHA2_H=
254
HAVE_STRLCAT=
255
HAVE_STRLCPY=
256
HAVE_STRNDUP=
257
HAVE_STRNLEN=
258
HAVE_STRTONUM=
259
HAVE_SYS_BYTEORDER_H=
260
HAVE_SYS_ENDIAN_H=
261
HAVE_SYS_MKDEV_H=
262
HAVE_SYS_QUEUE=
263
HAVE_SYS_SYSMACROS=
264
HAVE_SYS_TREE=
265
HAVE_SYSTRACE=0
266
HAVE_TERMIOS=
267
HAVE_UNVEIL=
268
HAVE_WAIT_ANY=
269
HAVE___PROGNAME=
270

271
#----------------------------------------------------------------------
272
# Allow configure.local to override all variables, default settings,
273
# command-line arguments, and tested features, above.
274
# You PROBABLY DO NOT want to change this.
275
#----------------------------------------------------------------------
276

277
if [ -r ./configure.local ]; then
278
	echo "configure.local: reading..." 1>&2
279
	echo "configure.local: reading..." 1>&3
280
	cat ./configure.local 1>&3
281
	. ./configure.local
282
else
283
	echo "configure.local: no (fully automatic configuration)" 1>&2
284
	echo "configure.local: no (fully automatic configuration)" 1>&3
285
fi
286

287
echo 1>&3
288

289
#----------------------------------------------------------------------
290
# Infrastructure for running tests.
291
# These consists of a series of functions that will attempt to run the
292
# given test file and record its exit into a HAVE_xxx variable.
293
# You DO NOT want to change this.
294
#----------------------------------------------------------------------
295

296
COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
297

298
# Check whether this HAVE_ setting is manually overridden.
299
# If yes, use the override, if no, do not decide anything yet.
300
# Arguments: lower-case test name, manual value
301

302
ismanual() {
303
	[ -z "${3}" ] && return 1
304
	echo "${1}: manual (HAVE_${2}=${3})" 1>&2
305
	echo "${1}: manual (HAVE_${2}=${3})" 1>&3
306
	echo 1>&3
307
	return 0
308
}
309

310
# Run a single autoconfiguration test.
311
# In case of success, enable the feature.
312
# In case of failure, do not decide anything yet.
313
# Arguments: lower-case test name, upper-case test name, additional
314
# CFLAGS, additional LIBS.
315

316
singletest() {
317
	extralib=""
318
	cat 1>&3 << __HEREDOC__
319
${1}: testing...
320
${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${4}
321
__HEREDOC__
322
	if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${4} 1>&3 2>&3; then
323
		echo "${1}: ${CC} succeeded" 1>&3
324
	else 
325
		if [ -n "${5}" ] ; then
326
			echo "${1}: ${CC} failed with $? (retrying)" 1>&3
327
			cat 1>&3 << __HEREDOC__
328
${1}: testing...
329
${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${5}
330
__HEREDOC__
331
			if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${5} 1>&3 2>&3; then
332
				echo "${1}: ${CC} succeeded" 1>&3
333
				extralib="(with ${5})"
334
			else 
335
				echo "${1}: ${CC} failed with $?" 1>&3
336
				echo 1>&3
337
				return 1
338
			fi
339
		else
340
			echo "${1}: ${CC} failed with $?" 1>&3
341
			echo 1>&3
342
			return 1
343
		fi
344
	fi
345

346
	if [ -n "${extralib}" ] 
347
	then
348
		eval "LDADD_${2}=\"${5}\""
349
	elif [ -n "${4}" ]
350
	then
351
		eval "LDADD_${2}=\"${4}\""
352
	fi
353

354
	echo "${1}: yes ${extralib}" 1>&2
355
	echo "${1}: yes ${extralib}" 1>&3
356
	echo 1>&3
357
	eval HAVE_${2}=1
358
	rm "test-${1}"
359
	return 0
360
}
361

362
# Run a complete autoconfiguration test, including the check for
363
# a manual override and disabling the feature on failure.
364
# Arguments: lower case name, upper case name, additional CFLAGS, 
365
# additional LDADD, alternative LDADD.
366

367
runtest() {
368
	eval _manual=\${HAVE_${2}}
369
	ismanual "${1}" "${2}" "${_manual}" && return 0
370
	singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
371
	echo "${1}: no" 1>&2
372
	eval HAVE_${2}=0
373
	return 1
374
}
375

376
#----------------------------------------------------------------------
377
# Begin running the tests themselves.
378
# All of your tests must be defined here.
379
# Please sort as the HAVE_xxxx values were defined.
380
# You WANT to change this.
381
# It consists of the following columns:
382
#    runtest
383
#    (1) test file
384
#    (2) macro to set
385
#    (3) argument to cc *before* -o
386
#    (4) argument to cc *after* 
387
#    (5) alternative argument to cc *after* 
388
#----------------------------------------------------------------------
389

390
runtest arc4random	ARC4RANDOM			  || true
391
runtest b64_ntop	B64_NTOP "" "" "-lresolv"	  || true
392
runtest capsicum	CAPSICUM			  || true
393
runtest crypt		CRYPT "" "" "-lcrypt"	  	  || true
394
runtest crypt_newhash	CRYPT_NEWHASH		  	  || true
395
runtest endian_h	ENDIAN_H			  || true
396
runtest err		ERR				  || true
397
runtest explicit_bzero	EXPLICIT_BZERO			  || true
398
runtest fts		FTS				  || true
399
runtest getexecname	GETEXECNAME			  || true
400
runtest getprogname	GETPROGNAME			  || true
401
runtest INFTIM		INFTIM				  || true
402
runtest landlock	LANDLOCK			  || true
403
runtest lib_socket	LIB_SOCKET "" "" "-lsocket -lnsl" || true
404
runtest md5		MD5 "" "" "-lmd"		  || true
405
runtest memmem		MEMMEM			  	  || true
406
runtest memrchr		MEMRCHR			  	  || true
407
runtest memset_s	MEMSET_S			  || true
408
runtest mkfifoat	MKFIFOAT			  || true
409
runtest mknodat		MKNODAT				  || true
410
runtest osbyteorder_h	OSBYTEORDER_H			  || true
411
runtest PATH_MAX	PATH_MAX			  || true
412
runtest pledge		PLEDGE				  || true
413
runtest program_invocation_short_name	PROGRAM_INVOCATION_SHORT_NAME || true
414
runtest readpassphrase	READPASSPHRASE			  || true
415
runtest reallocarray	REALLOCARRAY			  || true
416
runtest recallocarray	RECALLOCARRAY			  || true
417
runtest sandbox_init	SANDBOX_INIT	"-Wno-deprecated" || true
418
runtest scan_scaled	SCAN_SCALED "" "" "-lutil"	|| true
419
runtest seccomp-filter	SECCOMP_FILTER			  || true
420
runtest setresgid	SETRESGID			  || true
421
runtest setresuid	SETRESUID			  || true
422
runtest sha2		SHA2 "" "" "-lmd"		  || true
423
runtest SOCK_NONBLOCK	SOCK_NONBLOCK			  || true
424
runtest static		STATIC "" "-static"		  || true
425
runtest strlcat		STRLCAT				  || true
426
runtest strlcpy		STRLCPY				  || true
427
runtest strndup		STRNDUP				  || true
428
runtest strnlen		STRNLEN				  || true
429
runtest strtonum	STRTONUM			  || true
430
runtest sys_byteorder_h	SYS_BYTEORDER_H			  || true
431
runtest sys_endian_h	SYS_ENDIAN_H			  || true
432
runtest sys_mkdev_h	SYS_MKDEV_H			  || true
433
runtest sys_sysmacros_h	SYS_SYSMACROS_H			  || true
434
runtest sys_queue	SYS_QUEUE			  || true
435
runtest sys_tree	SYS_TREE			  || true
436
runtest termios		TERMIOS				  || true
437
runtest unveil		UNVEIL				  || true
438
runtest WAIT_ANY	WAIT_ANY			  || true
439
runtest __progname	__PROGNAME			  || true
440

441
#----------------------------------------------------------------------
442
# Output writing: generate the config.h file.
443
# This file contains all of the HAVE_xxxx variables necessary for
444
# compiling your source.
445
# You must include "config.h" BEFORE any other variables.
446
# You WANT to change this.
447
#----------------------------------------------------------------------
448

449
exec > config.h
450

451
# Start with prologue.
452

453
cat << __HEREDOC__
454
#ifndef OCONFIGURE_CONFIG_H
455
#define OCONFIGURE_CONFIG_H
456

457
#ifdef __cplusplus
458
# error "Do not use C++: this is a C application."
459
#endif
460
#if !defined(__GNUC__) || (__GNUC__ < 4)
461
# define __attribute__(x)
462
#endif
463
#if defined(__linux__) || defined(__MINT__) || defined(__wasi__)
464
# define _GNU_SOURCE /* memmem, memrchr, setresuid... */
465
# define _DEFAULT_SOURCE /* le32toh, crypt, ... */
466
#endif
467
#if defined(__NetBSD__)
468
# define _OPENBSD_SOURCE /* reallocarray, etc. */
469
#endif
470
#if defined(__sun)
471
# ifndef _XOPEN_SOURCE /* SunOS already defines */
472
#  define _XOPEN_SOURCE /* XPGx */
473
# endif
474
# define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
475
# ifndef __EXTENSIONS__ /* SunOS already defines */
476
#  define __EXTENSIONS__ /* reallocarray, etc. */
477
# endif
478
#endif
479
#if !defined(__BEGIN_DECLS)
480
# define __BEGIN_DECLS
481
#endif
482
#if !defined(__END_DECLS)
483
# define __END_DECLS
484
#endif
485

486
__HEREDOC__
487

488
# This is just for size_t, mode_t, and dev_t.
489
# Most of these functions, in the real world, pull in <string.h> or
490
# someting that pulls in support for size_t.
491
# Our function declarations are standalone, so specify them here.
492

493
if [ ${HAVE_FTS} -eq 0 -o \
494
     ${HAVE_MD5} -eq 0 -o \
495
     ${HAVE_MEMMEM} -eq 0 -o \
496
     ${HAVE_MEMRCHR} -eq 0 -o \
497
     ${HAVE_MKFIFOAT} -eq 0 -o \
498
     ${HAVE_MKNODAT} -eq 0 -o \
499
     ${HAVE_READPASSPHRASE} -eq 0 -o \
500
     ${HAVE_REALLOCARRAY} -eq 0 -o \
501
     ${HAVE_RECALLOCARRAY} -eq 0 -o \
502
     ${HAVE_SETRESGID} -eq 0 -o \
503
     ${HAVE_SETRESUID} -eq 0 -o \
504
     ${HAVE_SHA2} -eq 0 -o \
505
     ${HAVE_STRLCAT} -eq 0 -o \
506
     ${HAVE_STRLCPY} -eq 0 -o \
507
     ${HAVE_STRNDUP} -eq 0 -o \
508
     ${HAVE_STRNLEN} -eq 0 ]
509
then
510
	echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
511
	echo
512
fi
513

514
if [ ${HAVE_MD5} -eq 0 -o \
515
     ${HAVE_SHA2} -eq 0 ]
516
then
517
	echo "#include <stdint.h> /* C99 [u]int[nn]_t types */"
518
	echo
519
fi
520

521
if [ ${HAVE_ERR} -eq 0 ]
522
then
523
	echo "#include <stdarg.h> /* err(3) */"
524
	echo
525
fi
526

527
# Now we handle our HAVE_xxxx values.
528
# Most will just be defined as 0 or 1.
529

530
if [ ${HAVE_PATH_MAX} -eq 0 ]
531
then
532
	echo "#define PATH_MAX 4096"
533
	echo
534
fi
535

536
if [ ${HAVE_WAIT_ANY} -eq 0 ]
537
then
538
	echo "#define WAIT_ANY (-1) /* sys/wait.h */"
539
	echo "#define WAIT_MYPGRP 0"
540
	echo
541
fi
542

543

544
if [ ${HAVE_INFTIM} -eq 0 ]
545
then
546
	echo "#define INFTIM (-1) /* poll.h */"
547
	echo
548
fi
549

550
cat << __HEREDOC__
551
/*
552
 * Results of configuration feature-testing.
553
 */
554
#define HAVE_ARC4RANDOM ${HAVE_ARC4RANDOM}
555
#define HAVE_B64_NTOP ${HAVE_B64_NTOP}
556
#define HAVE_CAPSICUM ${HAVE_CAPSICUM}
557
#define HAVE_CRYPT ${HAVE_CRYPT}
558
#define HAVE_CRYPT_NEWHASH ${HAVE_CRYPT_NEWHASH}
559
#define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
560
#define HAVE_ERR ${HAVE_ERR}
561
#define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO}
562
#define HAVE_FTS ${HAVE_FTS}
563
#define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
564
#define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
565
#define HAVE_INFTIM ${HAVE_INFTIM}
566
#define HAVE_LANDLOCK ${HAVE_LANDLOCK}
567
#define HAVE_MD5 ${HAVE_MD5}
568
#define HAVE_MEMMEM ${HAVE_MEMMEM}
569
#define HAVE_MEMRCHR ${HAVE_MEMRCHR}
570
#define HAVE_MEMSET_S ${HAVE_MEMSET_S}
571
#define HAVE_MKFIFOAT ${HAVE_MKFIFOAT}
572
#define HAVE_MKNODAT ${HAVE_MKNODAT}
573
#define HAVE_OSBYTEORDER_H ${HAVE_OSBYTEORDER_H}
574
#define HAVE_PATH_MAX ${HAVE_PATH_MAX}
575
#define HAVE_PLEDGE ${HAVE_PLEDGE}
576
#define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
577
#define HAVE_READPASSPHRASE ${HAVE_READPASSPHRASE}
578
#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY}
579
#define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY}
580
#define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT}
581
#define HAVE_SCAN_SCALED ${HAVE_SCAN_SCALED}
582
#define HAVE_SECCOMP_HEADER ${HAVE_SECCOMP_FILTER}
583
#define HAVE_SETRESGID ${HAVE_SETRESGID}
584
#define HAVE_SETRESUID ${HAVE_SETRESUID}
585
#define HAVE_SHA2 ${HAVE_SHA2}
586
#define HAVE_SHA2_H ${HAVE_SHA2}
587
#define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
588
#define HAVE_STRLCAT ${HAVE_STRLCAT}
589
#define HAVE_STRLCPY ${HAVE_STRLCPY}
590
#define HAVE_STRNDUP ${HAVE_STRNDUP}
591
#define HAVE_STRNLEN ${HAVE_STRNLEN}
592
#define HAVE_STRTONUM ${HAVE_STRTONUM}
593
#define HAVE_SYS_BYTEORDER_H ${HAVE_SYS_BYTEORDER_H}
594
#define HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H}
595
#define HAVE_SYS_MKDEV_H ${HAVE_SYS_MKDEV_H}
596
#define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
597
#define HAVE_SYS_SYSMACROS_H ${HAVE_SYS_SYSMACROS_H}
598
#define HAVE_SYS_TREE ${HAVE_SYS_TREE}
599
#define HAVE_SYSTRACE ${HAVE_SYSTRACE}
600
#define HAVE_UNVEIL ${HAVE_UNVEIL}
601
#define HAVE_TERMIOS ${HAVE_TERMIOS}
602
#define HAVE_WAIT_ANY ${HAVE_WAIT_ANY}
603
#define HAVE___PROGNAME ${HAVE___PROGNAME}
604

605
__HEREDOC__
606

607
# Compat for libkern/OSByteOrder.h in place of endian.h.
608

609
[ ${HAVE_OSBYTEORDER_H} -eq 1 -a \
610
  ${HAVE_ENDIAN_H} -eq 0 -a \
611
  ${HAVE_SYS_BYTEORDER_H} -eq 0 -a \
612
  ${HAVE_SYS_ENDIAN_H} -eq 0 ] \
613
	&& cat << __HEREDOC__
614
/*
615
 * endian.h compatibility with libkern/OSByteOrder.h.
616
 */
617
#define htobe16(x) OSSwapHostToBigInt16(x)
618
#define htole16(x) OSSwapHostToLittleInt16(x)
619
#define be16toh(x) OSSwapBigToHostInt16(x)
620
#define le16toh(x) OSSwapLittleToHostInt16(x)
621
#define htobe32(x) OSSwapHostToBigInt32(x)
622
#define htole32(x) OSSwapHostToLittleInt32(x)
623
#define be32toh(x) OSSwapBigToHostInt32(x)
624
#define le32toh(x) OSSwapLittleToHostInt32(x)
625
#define htobe64(x) OSSwapHostToBigInt64(x)
626
#define htole64(x) OSSwapHostToLittleInt64(x)
627
#define be64toh(x) OSSwapBigToHostInt64(x)
628
#define le64toh(x) OSSwapLittleToHostInt64(x)
629

630
__HEREDOC__
631

632
[ ${HAVE_SYS_BYTEORDER_H} -eq 1 -a \
633
  ${HAVE_ENDIAN_H} -eq 0 -a \
634
  ${HAVE_OSBYTEORDER_H} -eq 0 -a \
635
  ${HAVE_SYS_ENDIAN_H} -eq 0 ] \
636
	&& cat << __HEREDOC__
637
/*
638
 * endian.h compatibility with sys/byteorder.h.
639
 */
640
#define htobe16(x) BE_16(x)
641
#define htole16(x) LE_16(x)
642
#define be16toh(x) BE_16(x)
643
#define le16toh(x) LE_16(x)
644
#define htobe32(x) BE_32(x)
645
#define htole32(x) LE_32(x)
646
#define be32toh(x) BE_32(x)
647
#define le32toh(x) LE_32(x)
648
#define htobe64(x) BE_64(x)
649
#define htole64(x) LE_64(x)
650
#define be64toh(x) BE_64(x)
651
#define le64toh(x) LE_64(x)
652

653
__HEREDOC__
654

655
# Make minor()/major()/makedev() easier to use.
656

657
cat << __HEREDOC__
658
/*
659
 * Handle the various major()/minor() header files.
660
 * Use sys/mkdev.h before sys/sysmacros.h because SunOS
661
 * has both, where only the former works properly.
662
 */
663
#if HAVE_SYS_MKDEV_H
664
# define COMPAT_MAJOR_MINOR_H <sys/mkdev.h>
665
#elif HAVE_SYS_SYSMACROS_H
666
# define COMPAT_MAJOR_MINOR_H <sys/sysmacros.h>
667
#else
668
# define COMPAT_MAJOR_MINOR_H <sys/types.h>
669
#endif
670

671
__HEREDOC__
672

673
# Make endian.h easier by providing a COMPAT_ENDIAN_H.
674

675
cat << __HEREDOC__
676
/*
677
 * Make it easier to include endian.h forms.
678
 */
679
#if HAVE_ENDIAN_H
680
# define COMPAT_ENDIAN_H <endian.h>
681
#elif HAVE_SYS_ENDIAN_H
682
# define COMPAT_ENDIAN_H <sys/endian.h>
683
#elif HAVE_OSBYTEORDER_H
684
# define COMPAT_ENDIAN_H <libkern/OSByteOrder.h>
685
#elif HAVE_SYS_BYTEORDER_H
686
# define COMPAT_ENDIAN_H <sys/byteorder.h>
687
#else
688
# warning No suitable endian.h could be found.
689
# warning Please e-mail the maintainers with your OS.
690
# define COMPAT_ENDIAN_H <endian.h>
691
#endif
692

693
__HEREDOC__
694

695
# Now we do our function declarations for missing functions.
696

697
[ ${HAVE_ERR} -eq 0 ] && \
698
	cat << __HEREDOC__
699
/*
700
 * Compatibility functions for err(3).
701
 */
702
extern void err(int, const char *, ...) __attribute__((noreturn));
703
extern void errc(int, int, const char *, ...) __attribute__((noreturn));
704
extern void errx(int, const char *, ...) __attribute__((noreturn));
705
extern void verr(int, const char *, va_list) __attribute__((noreturn));
706
extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
707
extern void verrx(int, const char *, va_list) __attribute__((noreturn));
708
extern void warn(const char *, ...);
709
extern void warnx(const char *, ...);
710
extern void warnc(int, const char *, ...);
711
extern void vwarn(const char *, va_list);
712
extern void vwarnc(int, const char *, va_list);
713
extern void vwarnx(const char *, va_list);
714

715
__HEREDOC__
716

717
[ ${HAVE_MD5} -eq 0 ] && \
718
	cat << __HEREDOC__
719
/*
720
 * Compatibility for md4(3).
721
 */
722
#define MD5_BLOCK_LENGTH 64
723
#define MD5_DIGEST_LENGTH 16
724
#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
725

726
typedef struct MD5Context {
727
	uint32_t state[4];
728
	uint64_t count;
729
	uint8_t buffer[MD5_BLOCK_LENGTH];
730
} MD5_CTX;
731

732
extern void MD5Init(MD5_CTX *);
733
extern void MD5Update(MD5_CTX *, const uint8_t *, size_t);
734
extern void MD5Pad(MD5_CTX *);
735
extern void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]);
736
extern char *MD5End(MD5_CTX *, char *);
737
extern void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
738

739
__HEREDOC__
740

741
[ ${HAVE_SHA2} -eq 0 ] && \
742
	cat << __HEREDOC__
743
/*
744
 * Compatibility for sha2(3).
745
 */
746

747
/*** SHA-256/384/512 Various Length Definitions ***********************/
748
#define SHA256_BLOCK_LENGTH		64
749
#define SHA256_DIGEST_LENGTH		32
750
#define SHA256_DIGEST_STRING_LENGTH	(SHA256_DIGEST_LENGTH * 2 + 1)
751
#define SHA384_BLOCK_LENGTH		128
752
#define SHA384_DIGEST_LENGTH		48
753
#define SHA384_DIGEST_STRING_LENGTH	(SHA384_DIGEST_LENGTH * 2 + 1)
754
#define SHA512_BLOCK_LENGTH		128
755
#define SHA512_DIGEST_LENGTH		64
756
#define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
757
#define SHA512_256_BLOCK_LENGTH		128
758
#define SHA512_256_DIGEST_LENGTH	32
759
#define SHA512_256_DIGEST_STRING_LENGTH	(SHA512_256_DIGEST_LENGTH * 2 + 1)
760

761
/*** SHA-224/256/384/512 Context Structure *******************************/
762
typedef struct _SHA2_CTX {
763
	union {
764
		uint32_t	st32[8];
765
		uint64_t	st64[8];
766
	} state;
767
	uint64_t	bitcount[2];
768
	uint8_t		buffer[SHA512_BLOCK_LENGTH];
769
} SHA2_CTX;
770

771
void SHA256Init(SHA2_CTX *);
772
void SHA256Transform(uint32_t state[8], const uint8_t [SHA256_BLOCK_LENGTH]);
773
void SHA256Update(SHA2_CTX *, const uint8_t *, size_t);
774
void SHA256Pad(SHA2_CTX *);
775
void SHA256Final(uint8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *);
776
char *SHA256End(SHA2_CTX *, char *);
777
char *SHA256File(const char *, char *);
778
char *SHA256FileChunk(const char *, char *, off_t, off_t);
779
char *SHA256Data(const uint8_t *, size_t, char *);
780

781
void SHA384Init(SHA2_CTX *);
782
void SHA384Transform(uint64_t state[8], const uint8_t [SHA384_BLOCK_LENGTH]);
783
void SHA384Update(SHA2_CTX *, const uint8_t *, size_t);
784
void SHA384Pad(SHA2_CTX *);
785
void SHA384Final(uint8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *);
786
char *SHA384End(SHA2_CTX *, char *);
787
char *SHA384File(const char *, char *);
788
char *SHA384FileChunk(const char *, char *, off_t, off_t);
789
char *SHA384Data(const uint8_t *, size_t, char *);
790

791
void SHA512Init(SHA2_CTX *);
792
void SHA512Transform(uint64_t state[8], const uint8_t [SHA512_BLOCK_LENGTH]);
793
void SHA512Update(SHA2_CTX *, const uint8_t *, size_t);
794
void SHA512Pad(SHA2_CTX *);
795
void SHA512Final(uint8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *);
796
char *SHA512End(SHA2_CTX *, char *);
797
char *SHA512File(const char *, char *);
798
char *SHA512FileChunk(const char *, char *, off_t, off_t);
799
char *SHA512Data(const uint8_t *, size_t, char *);
800

801
__HEREDOC__
802

803
if [ ${HAVE_SECCOMP_FILTER} -eq 1 ]; then
804
	seccomp_audit_arch=
805
	arch=$(uname -m 2>/dev/null || echo unknown)
806
	case "$arch" in
807
	x86_64)
808
		seccomp_audit_arch=AUDIT_ARCH_X86_64
809
		;;
810
	i*86)
811
		seccomp_audit_arch=AUDIT_ARCH_I386
812
		;;
813
	arm*)
814
		seccomp_audit_arch=AUDIT_ARCH_ARM
815
		;;
816
	aarch64*)
817
		seccomp_audit_arch=AUDIT_ARCH_AARCH64
818
		;;
819
	s390x)
820
		seccomp_audit_arch=AUDIT_ARCH_S390X
821
		;;
822
	s390)
823
		seccomp_audit_arch=AUDIT_ARCH_S390
824
		;;
825
	ppc)
826
		seccomp_audit_arch=AUDIT_ARCH_PPC
827
		;;
828
	ppc64)
829
		seccomp_audit_arch=AUDIT_ARCH_PPC64
830
		;;
831
	ppc64le)
832
		seccomp_audit_arch=AUDIT_ARCH_PPC64LE
833
		;;
834
	mips)
835
		seccomp_audit_arch=AUDIT_ARCH_MIPS
836
		;;
837
	mipsel)
838
		seccomp_audit_arch=AUDIT_ARCH_MIPSEL
839
		;;
840
	riscv64)
841
		seccomp_audit_arch=AUDIT_ARCH_RISCV64
842
		;;
843
	esac
844
	if [ -n "$seccomp_audit_arch" ]
845
	then
846
		echo "seccomp-arch: $seccomp_audit_arch" 1>&2
847
		cat << __HEREDOC__
848
/*
849
 * Seccomp is both available and has a recognised architecture.
850
 */
851
#define HAVE_SECCOMP_FILTER 1
852
#define SECCOMP_AUDIT_ARCH $seccomp_audit_arch
853

854
__HEREDOC__
855
	else
856
		echo "seccomp-arch: disabling (unknown: `uname -m`)" 1>&2
857
		cat << __HEREDOC__
858
/**
859
 * Seccomp is available, but not with a recognised architecture.
860
 * Please submit your architecture (via uname -m) to the oconfigure
861
 * maintainers.
862
 */
863
#define HAVE_SECCOMP_FILTER 0
864

865
__HEREDOC__
866
	fi
867
else
868
	cat << __HEREDOC__
869
#define HAVE_SECCOMP_FILTER 0
870

871
__HEREDOC__
872
fi
873

874
[ ${HAVE_B64_NTOP} -eq 0 ] && \
875
	cat << __HEREDOC__
876
/*
877
 * Compatibility for b64_ntop(3).
878
 */
879
extern int b64_ntop(unsigned char const *, size_t, char *, size_t);
880
extern int b64_pton(char const *, unsigned char *, size_t);
881

882
__HEREDOC__
883

884
[ ${HAVE_SCAN_SCALED} -eq 0 ] && \
885
	cat << __HEREDOC__
886
#define	FMT_SCALED_STRSIZE	7 /* minus sign, 4 digits, suffix, null byte */
887
int	fmt_scaled(long long, char *);
888
int	scan_scaled(char *, long long *);
889
__HEREDOC__
890

891
[ ${HAVE_EXPLICIT_BZERO} -eq 0 ] && \
892
	cat << __HEREDOC__
893
/*
894
 * Compatibility for explicit_bzero(3).
895
 */
896
extern void explicit_bzero(void *, size_t);
897

898
__HEREDOC__
899

900
[ ${HAVE_MEMMEM} -eq 0 ] && \
901
	cat << __HEREDOC__
902
/*
903
 * Compatibility for memmem(3).
904
 */
905
void *memmem(const void *, size_t, const void *, size_t);
906

907
__HEREDOC__
908

909
[ ${HAVE_MEMRCHR} -eq 0 ] && \
910
	cat << __HEREDOC__
911
/*
912
 * Compatibility for memrchr(3).
913
 */
914
void *memrchr(const void *b, int, size_t);
915

916
__HEREDOC__
917

918
[ ${HAVE_GETPROGNAME} -eq 0 ] && \
919
	cat << __HEREDOC__
920
/*
921
 * Compatibility for getprogname(3).
922
 */
923
extern const char *getprogname(void);
924

925
__HEREDOC__
926

927
[ ${HAVE_READPASSPHRASE} -eq 0 ] && \
928
	cat << __HEREDOC__
929
/*
930
 * Macros and function required for readpassphrase(3).
931
 */
932
#define RPP_ECHO_OFF 0x00
933
#define RPP_ECHO_ON 0x01
934
#define RPP_REQUIRE_TTY 0x02
935
#define RPP_FORCELOWER 0x04
936
#define RPP_FORCEUPPER 0x08
937
#define RPP_SEVENBIT 0x10
938
#define RPP_STDIN 0x20
939
char *readpassphrase(const char *, char *, size_t, int);
940

941
__HEREDOC__
942

943
[ ${HAVE_REALLOCARRAY} -eq 0 ] && \
944
	cat << __HEREDOC__
945
/*
946
 * Compatibility for reallocarray(3).
947
 */
948
extern void *reallocarray(void *, size_t, size_t);
949

950
__HEREDOC__
951

952
[ ${HAVE_RECALLOCARRAY} -eq 0 ] && \
953
	cat << __HEREDOC__
954
/*
955
 * Compatibility for recallocarray(3).
956
 */
957
extern void *recallocarray(void *, size_t, size_t, size_t);
958

959
__HEREDOC__
960

961
[ ${HAVE_STRLCAT} -eq 0 ] && \
962
	cat << __HEREDOC__
963
/*
964
 * Compatibility for strlcat(3).
965
 */
966
extern size_t strlcat(char *, const char *, size_t);
967

968
__HEREDOC__
969

970
[ ${HAVE_STRLCPY} -eq 0 ] && \
971
	cat << __HEREDOC__
972
/*
973
 * Compatibility for strlcpy(3).
974
 */
975
extern size_t strlcpy(char *, const char *, size_t);
976

977
__HEREDOC__
978

979
[ ${HAVE_STRNDUP} -eq 0 ] && \
980
	cat << __HEREDOC__
981
/*
982
 * Compatibility for strndup(3).
983
 */
984
extern char *strndup(const char *, size_t);
985

986
__HEREDOC__
987

988
[ ${HAVE_STRNLEN} -eq 0 ] && \
989
	cat << __HEREDOC__
990
/*
991
 * Compatibility for strnlen(3).
992
 */
993
extern size_t strnlen(const char *, size_t);
994

995
__HEREDOC__
996

997
[ ${HAVE_STRTONUM} -eq 0 ] && \
998
	cat << __HEREDOC__
999
/*
1000
 * Compatibility for strotnum(3).
1001
 */
1002
extern long long strtonum(const char *, long long, long long, const char **);
1003

1004
__HEREDOC__
1005

1006
[ ${HAVE_MKFIFOAT} -eq 0 ] && \
1007
	cat << __HEREDOC__
1008
/*
1009
 * Compatibility for mkfifoat(2).
1010
 */
1011
int mkfifoat(int, const char *, mode_t);
1012

1013
__HEREDOC__
1014

1015
[ ${HAVE_MKNODAT} -eq 0 ] && \
1016
	cat << __HEREDOC__
1017
/*
1018
 * Compatibility for mknodat(2).
1019
 */
1020
int mknodat(int, const char *, mode_t, dev_t);
1021

1022
__HEREDOC__
1023

1024
[ ${HAVE_SETRESGID} -eq 0 ] && \
1025
	cat << __HEREDOC__
1026
/*
1027
 * Compatibility for setresgid(2).
1028
 */
1029
int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1030

1031
__HEREDOC__
1032

1033
[ ${HAVE_SETRESUID} -eq 0 ] && \
1034
	cat << __HEREDOC__
1035
/*
1036
 * Compatibility for setresuid(2).
1037
 */
1038
int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1039

1040
__HEREDOC__
1041

1042
if [ ${HAVE_SYS_QUEUE} -eq 0 ]; then
1043
	cat << __HEREDOC__
1044
/*
1045
 * A compatible version of OpenBSD <sys/queue.h>.
1046
 */
1047
/*
1048
 * Copyright (c) 1991, 1993
1049
 *	The Regents of the University of California.  All rights reserved.
1050
 *
1051
 * Redistribution and use in source and binary forms, with or without
1052
 * modification, are permitted provided that the following conditions
1053
 * are met:
1054
 * 1. Redistributions of source code must retain the above copyright
1055
 *    notice, this list of conditions and the following disclaimer.
1056
 * 2. Redistributions in binary form must reproduce the above copyright
1057
 *    notice, this list of conditions and the following disclaimer in the
1058
 *    documentation and/or other materials provided with the distribution.
1059
 * 3. Neither the name of the University nor the names of its contributors
1060
 *    may be used to endorse or promote products derived from this software
1061
 *    without specific prior written permission.
1062
 *
1063
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND
1064
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1065
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1066
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1067
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1068
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1069
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1070
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1071
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1072
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1073
 * SUCH DAMAGE.
1074
 *
1075
 *	@(#)queue.h	8.5 (Berkeley) 8/20/94
1076
 */
1077

1078
/* OPENBSD ORIGINAL: sys/sys/queue.h */
1079

1080
/*
1081
 * Require for OS/X and other platforms that have old/broken/incomplete
1082
 * <sys/queue.h>.
1083
 */
1084

1085
#undef LIST_EMPTY
1086
#undef LIST_END
1087
#undef LIST_ENTRY
1088
#undef LIST_FIRST
1089
#undef LIST_FOREACH
1090
#undef LIST_FOREACH_SAFE
1091
#undef LIST_HEAD
1092
#undef LIST_HEAD_INITIALIZER
1093
#undef LIST_INIT
1094
#undef LIST_INSERT_AFTER
1095
#undef LIST_INSERT_BEFORE
1096
#undef LIST_INSERT_HEAD
1097
#undef LIST_NEXT
1098
#undef LIST_REMOVE
1099
#undef LIST_REPLACE
1100
#undef SIMPLEQ_CONCAT
1101
#undef SIMPLEQ_EMPTY
1102
#undef SIMPLEQ_END
1103
#undef SIMPLEQ_ENTRY
1104
#undef SIMPLEQ_FIRST
1105
#undef SIMPLEQ_FOREACH
1106
#undef SIMPLEQ_FOREACH_SAFE
1107
#undef SIMPLEQ_HEAD
1108
#undef SIMPLEQ_HEAD_INITIALIZER
1109
#undef SIMPLEQ_INIT
1110
#undef SIMPLEQ_INSERT_AFTER
1111
#undef SIMPLEQ_INSERT_HEAD
1112
#undef SIMPLEQ_INSERT_TAIL
1113
#undef SIMPLEQ_NEXT
1114
#undef SIMPLEQ_REMOVE_AFTER
1115
#undef SIMPLEQ_REMOVE_HEAD
1116
#undef SLIST_EMPTY
1117
#undef SLIST_END
1118
#undef SLIST_ENTRY
1119
#undef SLIST_FIRST
1120
#undef SLIST_FOREACH
1121
#undef SLIST_FOREACH_SAFE
1122
#undef SLIST_HEAD
1123
#undef SLIST_HEAD_INITIALIZER
1124
#undef SLIST_INIT
1125
#undef SLIST_INSERT_AFTER
1126
#undef SLIST_INSERT_HEAD
1127
#undef SLIST_NEXT
1128
#undef SLIST_REMOVE
1129
#undef SLIST_REMOVE_AFTER
1130
#undef SLIST_REMOVE_HEAD
1131
#undef TAILQ_CONCAT
1132
#undef TAILQ_EMPTY
1133
#undef TAILQ_END
1134
#undef TAILQ_ENTRY
1135
#undef TAILQ_FIRST
1136
#undef TAILQ_FOREACH
1137
#undef TAILQ_FOREACH_REVERSE
1138
#undef TAILQ_FOREACH_REVERSE_SAFE
1139
#undef TAILQ_FOREACH_SAFE
1140
#undef TAILQ_HEAD
1141
#undef TAILQ_HEAD_INITIALIZER
1142
#undef TAILQ_INIT
1143
#undef TAILQ_INSERT_AFTER
1144
#undef TAILQ_INSERT_BEFORE
1145
#undef TAILQ_INSERT_HEAD
1146
#undef TAILQ_INSERT_TAIL
1147
#undef TAILQ_LAST
1148
#undef TAILQ_NEXT
1149
#undef TAILQ_PREV
1150
#undef TAILQ_REMOVE
1151
#undef TAILQ_REPLACE
1152
#undef XSIMPLEQ_EMPTY
1153
#undef XSIMPLEQ_END
1154
#undef XSIMPLEQ_ENTRY
1155
#undef XSIMPLEQ_FIRST
1156
#undef XSIMPLEQ_FOREACH
1157
#undef XSIMPLEQ_FOREACH_SAFE
1158
#undef XSIMPLEQ_HEAD
1159
#undef XSIMPLEQ_INIT
1160
#undef XSIMPLEQ_INSERT_AFTER
1161
#undef XSIMPLEQ_INSERT_HEAD
1162
#undef XSIMPLEQ_INSERT_TAIL
1163
#undef XSIMPLEQ_NEXT
1164
#undef XSIMPLEQ_REMOVE_AFTER
1165
#undef XSIMPLEQ_REMOVE_HEAD
1166
#undef XSIMPLEQ_XOR
1167

1168
/*
1169
 * This file defines five types of data structures: singly-linked lists,
1170
 * lists, simple queues, tail queues and XOR simple queues.
1171
 *
1172
 *
1173
 * A singly-linked list is headed by a single forward pointer. The elements
1174
 * are singly linked for minimum space and pointer manipulation overhead at
1175
 * the expense of O(n) removal for arbitrary elements. New elements can be
1176
 * added to the list after an existing element or at the head of the list.
1177
 * Elements being removed from the head of the list should use the explicit
1178
 * macro for this purpose for optimum efficiency. A singly-linked list may
1179
 * only be traversed in the forward direction.  Singly-linked lists are ideal
1180
 * for applications with large datasets and few or no removals or for
1181
 * implementing a LIFO queue.
1182
 *
1183
 * A list is headed by a single forward pointer (or an array of forward
1184
 * pointers for a hash table header). The elements are doubly linked
1185
 * so that an arbitrary element can be removed without a need to
1186
 * traverse the list. New elements can be added to the list before
1187
 * or after an existing element or at the head of the list. A list
1188
 * may only be traversed in the forward direction.
1189
 *
1190
 * A simple queue is headed by a pair of pointers, one to the head of the
1191
 * list and the other to the tail of the list. The elements are singly
1192
 * linked to save space, so elements can only be removed from the
1193
 * head of the list. New elements can be added to the list before or after
1194
 * an existing element, at the head of the list, or at the end of the
1195
 * list. A simple queue may only be traversed in the forward direction.
1196
 *
1197
 * A tail queue is headed by a pair of pointers, one to the head of the
1198
 * list and the other to the tail of the list. The elements are doubly
1199
 * linked so that an arbitrary element can be removed without a need to
1200
 * traverse the list. New elements can be added to the list before or
1201
 * after an existing element, at the head of the list, or at the end of
1202
 * the list. A tail queue may be traversed in either direction.
1203
 *
1204
 * An XOR simple queue is used in the same way as a regular simple queue.
1205
 * The difference is that the head structure also includes a "cookie" that
1206
 * is XOR'd with the queue pointer (first, last or next) to generate the
1207
 * real pointer value.
1208
 *
1209
 * For details on the use of these macros, see the queue(3) manual page.
1210
 */
1211

1212
#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
1213
#define _Q_INVALID ((void *)-1)
1214
#define _Q_INVALIDATE(a) (a) = _Q_INVALID
1215
#else
1216
#define _Q_INVALIDATE(a)
1217
#endif
1218

1219
/*
1220
 * Singly-linked List definitions.
1221
 */
1222
#define SLIST_HEAD(name, type)						\\
1223
struct name {								\\
1224
	struct type *slh_first;	/* first element */			\\
1225
}
1226

1227
#define	SLIST_HEAD_INITIALIZER(head)					\\
1228
	{ NULL }
1229

1230
#define SLIST_ENTRY(type)						\\
1231
struct {								\\
1232
	struct type *sle_next;	/* next element */			\\
1233
}
1234

1235
/*
1236
 * Singly-linked List access methods.
1237
 */
1238
#define	SLIST_FIRST(head)	((head)->slh_first)
1239
#define	SLIST_END(head)		NULL
1240
#define	SLIST_EMPTY(head)	(SLIST_FIRST(head) == SLIST_END(head))
1241
#define	SLIST_NEXT(elm, field)	((elm)->field.sle_next)
1242

1243
#define	SLIST_FOREACH(var, head, field)					\\
1244
	for((var) = SLIST_FIRST(head);					\\
1245
	    (var) != SLIST_END(head);					\\
1246
	    (var) = SLIST_NEXT(var, field))
1247

1248
#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\\
1249
	for ((var) = SLIST_FIRST(head);				\\
1250
	    (var) && ((tvar) = SLIST_NEXT(var, field), 1);		\\
1251
	    (var) = (tvar))
1252

1253
/*
1254
 * Singly-linked List functions.
1255
 */
1256
#define	SLIST_INIT(head) {						\\
1257
	SLIST_FIRST(head) = SLIST_END(head);				\\
1258
}
1259

1260
#define	SLIST_INSERT_AFTER(slistelm, elm, field) do {			\\
1261
	(elm)->field.sle_next = (slistelm)->field.sle_next;		\\
1262
	(slistelm)->field.sle_next = (elm);				\\
1263
} while (0)
1264

1265
#define	SLIST_INSERT_HEAD(head, elm, field) do {			\\
1266
	(elm)->field.sle_next = (head)->slh_first;			\\
1267
	(head)->slh_first = (elm);					\\
1268
} while (0)
1269

1270
#define	SLIST_REMOVE_AFTER(elm, field) do {				\\
1271
	(elm)->field.sle_next = (elm)->field.sle_next->field.sle_next;	\\
1272
} while (0)
1273

1274
#define	SLIST_REMOVE_HEAD(head, field) do {				\\
1275
	(head)->slh_first = (head)->slh_first->field.sle_next;		\\
1276
} while (0)
1277

1278
#define SLIST_REMOVE(head, elm, type, field) do {			\\
1279
	if ((head)->slh_first == (elm)) {				\\
1280
		SLIST_REMOVE_HEAD((head), field);			\\
1281
	} else {							\\
1282
		struct type *curelm = (head)->slh_first;		\\
1283
									\\
1284
		while (curelm->field.sle_next != (elm))			\\
1285
			curelm = curelm->field.sle_next;		\\
1286
		curelm->field.sle_next =				\\
1287
		    curelm->field.sle_next->field.sle_next;		\\
1288
	}								\\
1289
	_Q_INVALIDATE((elm)->field.sle_next);				\\
1290
} while (0)
1291

1292
/*
1293
 * List definitions.
1294
 */
1295
#define LIST_HEAD(name, type)						\\
1296
struct name {								\\
1297
	struct type *lh_first;	/* first element */			\\
1298
}
1299

1300
#define LIST_HEAD_INITIALIZER(head)					\\
1301
	{ NULL }
1302

1303
#define LIST_ENTRY(type)						\\
1304
struct {								\\
1305
	struct type *le_next;	/* next element */			\\
1306
	struct type **le_prev;	/* address of previous next element */	\\
1307
}
1308

1309
/*
1310
 * List access methods.
1311
 */
1312
#define	LIST_FIRST(head)		((head)->lh_first)
1313
#define	LIST_END(head)			NULL
1314
#define	LIST_EMPTY(head)		(LIST_FIRST(head) == LIST_END(head))
1315
#define	LIST_NEXT(elm, field)		((elm)->field.le_next)
1316

1317
#define LIST_FOREACH(var, head, field)					\\
1318
	for((var) = LIST_FIRST(head);					\\
1319
	    (var)!= LIST_END(head);					\\
1320
	    (var) = LIST_NEXT(var, field))
1321

1322
#define	LIST_FOREACH_SAFE(var, head, field, tvar)			\\
1323
	for ((var) = LIST_FIRST(head);				\\
1324
	    (var) && ((tvar) = LIST_NEXT(var, field), 1);		\\
1325
	    (var) = (tvar))
1326

1327
/*
1328
 * List functions.
1329
 */
1330
#define	LIST_INIT(head) do {						\\
1331
	LIST_FIRST(head) = LIST_END(head);				\\
1332
} while (0)
1333

1334
#define LIST_INSERT_AFTER(listelm, elm, field) do {			\\
1335
	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\\
1336
		(listelm)->field.le_next->field.le_prev =		\\
1337
		    &(elm)->field.le_next;				\\
1338
	(listelm)->field.le_next = (elm);				\\
1339
	(elm)->field.le_prev = &(listelm)->field.le_next;		\\
1340
} while (0)
1341

1342
#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\\
1343
	(elm)->field.le_prev = (listelm)->field.le_prev;		\\
1344
	(elm)->field.le_next = (listelm);				\\
1345
	*(listelm)->field.le_prev = (elm);				\\
1346
	(listelm)->field.le_prev = &(elm)->field.le_next;		\\
1347
} while (0)
1348

1349
#define LIST_INSERT_HEAD(head, elm, field) do {				\\
1350
	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\\
1351
		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\\
1352
	(head)->lh_first = (elm);					\\
1353
	(elm)->field.le_prev = &(head)->lh_first;			\\
1354
} while (0)
1355

1356
#define LIST_REMOVE(elm, field) do {					\\
1357
	if ((elm)->field.le_next != NULL)				\\
1358
		(elm)->field.le_next->field.le_prev =			\\
1359
		    (elm)->field.le_prev;				\\
1360
	*(elm)->field.le_prev = (elm)->field.le_next;			\\
1361
	_Q_INVALIDATE((elm)->field.le_prev);				\\
1362
	_Q_INVALIDATE((elm)->field.le_next);				\\
1363
} while (0)
1364

1365
#define LIST_REPLACE(elm, elm2, field) do {				\\
1366
	if (((elm2)->field.le_next = (elm)->field.le_next) != NULL)	\\
1367
		(elm2)->field.le_next->field.le_prev =			\\
1368
		    &(elm2)->field.le_next;				\\
1369
	(elm2)->field.le_prev = (elm)->field.le_prev;			\\
1370
	*(elm2)->field.le_prev = (elm2);				\\
1371
	_Q_INVALIDATE((elm)->field.le_prev);				\\
1372
	_Q_INVALIDATE((elm)->field.le_next);				\\
1373
} while (0)
1374

1375
/*
1376
 * Simple queue definitions.
1377
 */
1378
#define SIMPLEQ_HEAD(name, type)					\\
1379
struct name {								\\
1380
	struct type *sqh_first;	/* first element */			\\
1381
	struct type **sqh_last;	/* addr of last next element */		\\
1382
}
1383

1384
#define SIMPLEQ_HEAD_INITIALIZER(head)					\\
1385
	{ NULL, &(head).sqh_first }
1386

1387
#define SIMPLEQ_ENTRY(type)						\\
1388
struct {								\\
1389
	struct type *sqe_next;	/* next element */			\\
1390
}
1391

1392
/*
1393
 * Simple queue access methods.
1394
 */
1395
#define	SIMPLEQ_FIRST(head)	    ((head)->sqh_first)
1396
#define	SIMPLEQ_END(head)	    NULL
1397
#define	SIMPLEQ_EMPTY(head)	    (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
1398
#define	SIMPLEQ_NEXT(elm, field)    ((elm)->field.sqe_next)
1399

1400
#define SIMPLEQ_FOREACH(var, head, field)				\\
1401
	for((var) = SIMPLEQ_FIRST(head);				\\
1402
	    (var) != SIMPLEQ_END(head);					\\
1403
	    (var) = SIMPLEQ_NEXT(var, field))
1404

1405
#define	SIMPLEQ_FOREACH_SAFE(var, head, field, tvar)			\\
1406
	for ((var) = SIMPLEQ_FIRST(head);				\\
1407
	    (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1);		\\
1408
	    (var) = (tvar))
1409

1410
/*
1411
 * Simple queue functions.
1412
 */
1413
#define	SIMPLEQ_INIT(head) do {						\\
1414
	(head)->sqh_first = NULL;					\\
1415
	(head)->sqh_last = &(head)->sqh_first;				\\
1416
} while (0)
1417

1418
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do {			\\
1419
	if (((elm)->field.sqe_next = (head)->sqh_first) == NULL)	\\
1420
		(head)->sqh_last = &(elm)->field.sqe_next;		\\
1421
	(head)->sqh_first = (elm);					\\
1422
} while (0)
1423

1424
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do {			\\
1425
	(elm)->field.sqe_next = NULL;					\\
1426
	*(head)->sqh_last = (elm);					\\
1427
	(head)->sqh_last = &(elm)->field.sqe_next;			\\
1428
} while (0)
1429

1430
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\\
1431
	if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\\
1432
		(head)->sqh_last = &(elm)->field.sqe_next;		\\
1433
	(listelm)->field.sqe_next = (elm);				\\
1434
} while (0)
1435

1436
#define SIMPLEQ_REMOVE_HEAD(head, field) do {			\\
1437
	if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \\
1438
		(head)->sqh_last = &(head)->sqh_first;			\\
1439
} while (0)
1440

1441
#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do {			\\
1442
	if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \\
1443
	    == NULL)							\\
1444
		(head)->sqh_last = &(elm)->field.sqe_next;		\\
1445
} while (0)
1446

1447
#define SIMPLEQ_CONCAT(head1, head2) do {				\\
1448
	if (!SIMPLEQ_EMPTY((head2))) {					\\
1449
		*(head1)->sqh_last = (head2)->sqh_first;		\\
1450
		(head1)->sqh_last = (head2)->sqh_last;			\\
1451
		SIMPLEQ_INIT((head2));					\\
1452
	}								\\
1453
} while (0)
1454

1455
/*
1456
 * XOR Simple queue definitions.
1457
 */
1458
#define XSIMPLEQ_HEAD(name, type)					\\
1459
struct name {								\\
1460
	struct type *sqx_first;	/* first element */			\\
1461
	struct type **sqx_last;	/* addr of last next element */		\\
1462
	unsigned long sqx_cookie;					\\
1463
}
1464

1465
#define XSIMPLEQ_ENTRY(type)						\\
1466
struct {								\\
1467
	struct type *sqx_next;	/* next element */			\\
1468
}
1469

1470
/*
1471
 * XOR Simple queue access methods.
1472
 */
1473
#define XSIMPLEQ_XOR(head, ptr)	    ((__typeof(ptr))((head)->sqx_cookie ^ \\
1474
					(unsigned long)(ptr)))
1475
#define	XSIMPLEQ_FIRST(head)	    XSIMPLEQ_XOR(head, ((head)->sqx_first))
1476
#define	XSIMPLEQ_END(head)	    NULL
1477
#define	XSIMPLEQ_EMPTY(head)	    (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head))
1478
#define	XSIMPLEQ_NEXT(head, elm, field)    XSIMPLEQ_XOR(head, ((elm)->field.sqx_next))
1479

1480

1481
#define XSIMPLEQ_FOREACH(var, head, field)				\\
1482
	for ((var) = XSIMPLEQ_FIRST(head);				\\
1483
	    (var) != XSIMPLEQ_END(head);				\\
1484
	    (var) = XSIMPLEQ_NEXT(head, var, field))
1485

1486
#define	XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar)			\\
1487
	for ((var) = XSIMPLEQ_FIRST(head);				\\
1488
	    (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1);	\\
1489
	    (var) = (tvar))
1490

1491
/*
1492
 * XOR Simple queue functions.
1493
 */
1494
#define	XSIMPLEQ_INIT(head) do {					\\
1495
	arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \\
1496
	(head)->sqx_first = XSIMPLEQ_XOR(head, NULL);			\\
1497
	(head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first);	\\
1498
} while (0)
1499

1500
#define XSIMPLEQ_INSERT_HEAD(head, elm, field) do {			\\
1501
	if (((elm)->field.sqx_next = (head)->sqx_first) ==		\\
1502
	    XSIMPLEQ_XOR(head, NULL))					\\
1503
		(head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \\
1504
	(head)->sqx_first = XSIMPLEQ_XOR(head, (elm));			\\
1505
} while (0)
1506

1507
#define XSIMPLEQ_INSERT_TAIL(head, elm, field) do {			\\
1508
	(elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL);		\\
1509
	*(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \\
1510
	(head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next);	\\
1511
} while (0)
1512

1513
#define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do {		\\
1514
	if (((elm)->field.sqx_next = (listelm)->field.sqx_next) ==	\\
1515
	    XSIMPLEQ_XOR(head, NULL))					\\
1516
		(head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \\
1517
	(listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm));		\\
1518
} while (0)
1519

1520
#define XSIMPLEQ_REMOVE_HEAD(head, field) do {				\\
1521
	if (((head)->sqx_first = XSIMPLEQ_XOR(head,			\\
1522
	    (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \\
1523
		(head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \\
1524
} while (0)
1525

1526
#define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do {			\\
1527
	if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head,			\\
1528
	    (elm)->field.sqx_next)->field.sqx_next)			\\
1529
	    == XSIMPLEQ_XOR(head, NULL))				\\
1530
		(head)->sqx_last = 					\\
1531
		    XSIMPLEQ_XOR(head, &(elm)->field.sqx_next);		\\
1532
} while (0)
1533

1534

1535
/*
1536
 * Tail queue definitions.
1537
 */
1538
#define TAILQ_HEAD(name, type)						\\
1539
struct name {								\\
1540
	struct type *tqh_first;	/* first element */			\\
1541
	struct type **tqh_last;	/* addr of last next element */		\\
1542
}
1543

1544
#define TAILQ_HEAD_INITIALIZER(head)					\\
1545
	{ NULL, &(head).tqh_first }
1546

1547
#define TAILQ_ENTRY(type)						\\
1548
struct {								\\
1549
	struct type *tqe_next;	/* next element */			\\
1550
	struct type **tqe_prev;	/* address of previous next element */	\\
1551
}
1552

1553
/*
1554
 * Tail queue access methods.
1555
 */
1556
#define	TAILQ_FIRST(head)		((head)->tqh_first)
1557
#define	TAILQ_END(head)			NULL
1558
#define	TAILQ_NEXT(elm, field)		((elm)->field.tqe_next)
1559
#define TAILQ_LAST(head, headname)					\\
1560
	(*(((struct headname *)((head)->tqh_last))->tqh_last))
1561
/* XXX */
1562
#define TAILQ_PREV(elm, headname, field)				\\
1563
	(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
1564
#define	TAILQ_EMPTY(head)						\\
1565
	(TAILQ_FIRST(head) == TAILQ_END(head))
1566

1567
#define TAILQ_FOREACH(var, head, field)					\\
1568
	for((var) = TAILQ_FIRST(head);					\\
1569
	    (var) != TAILQ_END(head);					\\
1570
	    (var) = TAILQ_NEXT(var, field))
1571

1572
#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\\
1573
	for ((var) = TAILQ_FIRST(head);					\\
1574
	    (var) != TAILQ_END(head) &&					\\
1575
	    ((tvar) = TAILQ_NEXT(var, field), 1);			\\
1576
	    (var) = (tvar))
1577

1578

1579
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)		\\
1580
	for((var) = TAILQ_LAST(head, headname);				\\
1581
	    (var) != TAILQ_END(head);					\\
1582
	    (var) = TAILQ_PREV(var, headname, field))
1583

1584
#define	TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\\
1585
	for ((var) = TAILQ_LAST(head, headname);			\\
1586
	    (var) != TAILQ_END(head) &&					\\
1587
	    ((tvar) = TAILQ_PREV(var, headname, field), 1);		\\
1588
	    (var) = (tvar))
1589

1590
/*
1591
 * Tail queue functions.
1592
 */
1593
#define	TAILQ_INIT(head) do {						\\
1594
	(head)->tqh_first = NULL;					\\
1595
	(head)->tqh_last = &(head)->tqh_first;				\\
1596
} while (0)
1597

1598
#define TAILQ_INSERT_HEAD(head, elm, field) do {			\\
1599
	if (((elm)->field.tqe_next = (head)->tqh_first) != NULL)	\\
1600
		(head)->tqh_first->field.tqe_prev =			\\
1601
		    &(elm)->field.tqe_next;				\\
1602
	else								\\
1603
		(head)->tqh_last = &(elm)->field.tqe_next;		\\
1604
	(head)->tqh_first = (elm);					\\
1605
	(elm)->field.tqe_prev = &(head)->tqh_first;			\\
1606
} while (0)
1607

1608
#define TAILQ_INSERT_TAIL(head, elm, field) do {			\\
1609
	(elm)->field.tqe_next = NULL;					\\
1610
	(elm)->field.tqe_prev = (head)->tqh_last;			\\
1611
	*(head)->tqh_last = (elm);					\\
1612
	(head)->tqh_last = &(elm)->field.tqe_next;			\\
1613
} while (0)
1614

1615
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\\
1616
	if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\\
1617
		(elm)->field.tqe_next->field.tqe_prev =			\\
1618
		    &(elm)->field.tqe_next;				\\
1619
	else								\\
1620
		(head)->tqh_last = &(elm)->field.tqe_next;		\\
1621
	(listelm)->field.tqe_next = (elm);				\\
1622
	(elm)->field.tqe_prev = &(listelm)->field.tqe_next;		\\
1623
} while (0)
1624

1625
#define	TAILQ_INSERT_BEFORE(listelm, elm, field) do {			\\
1626
	(elm)->field.tqe_prev = (listelm)->field.tqe_prev;		\\
1627
	(elm)->field.tqe_next = (listelm);				\\
1628
	*(listelm)->field.tqe_prev = (elm);				\\
1629
	(listelm)->field.tqe_prev = &(elm)->field.tqe_next;		\\
1630
} while (0)
1631

1632
#define TAILQ_REMOVE(head, elm, field) do {				\\
1633
	if (((elm)->field.tqe_next) != NULL)				\\
1634
		(elm)->field.tqe_next->field.tqe_prev =			\\
1635
		    (elm)->field.tqe_prev;				\\
1636
	else								\\
1637
		(head)->tqh_last = (elm)->field.tqe_prev;		\\
1638
	*(elm)->field.tqe_prev = (elm)->field.tqe_next;			\\
1639
	_Q_INVALIDATE((elm)->field.tqe_prev);				\\
1640
	_Q_INVALIDATE((elm)->field.tqe_next);				\\
1641
} while (0)
1642

1643
#define TAILQ_REPLACE(head, elm, elm2, field) do {			\\
1644
	if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL)	\\
1645
		(elm2)->field.tqe_next->field.tqe_prev =		\\
1646
		    &(elm2)->field.tqe_next;				\\
1647
	else								\\
1648
		(head)->tqh_last = &(elm2)->field.tqe_next;		\\
1649
	(elm2)->field.tqe_prev = (elm)->field.tqe_prev;			\\
1650
	*(elm2)->field.tqe_prev = (elm2);				\\
1651
	_Q_INVALIDATE((elm)->field.tqe_prev);				\\
1652
	_Q_INVALIDATE((elm)->field.tqe_next);				\\
1653
} while (0)
1654

1655
#define TAILQ_CONCAT(head1, head2, field) do {				\\
1656
	if (!TAILQ_EMPTY(head2)) {					\\
1657
		*(head1)->tqh_last = (head2)->tqh_first;		\\
1658
		(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last;	\\
1659
		(head1)->tqh_last = (head2)->tqh_last;			\\
1660
		TAILQ_INIT((head2));					\\
1661
	}								\\
1662
} while (0)
1663

1664
__HEREDOC__
1665
fi
1666

1667
if [ ${HAVE_SYS_TREE} -eq 0 ]; then
1668
	cat << __HEREDOC__
1669
/*
1670
 * A compatible version of OpenBSD <sys/tree.h>.
1671
 */
1672
/*
1673
 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
1674
 * All rights reserved.
1675
 *
1676
 * Redistribution and use in source and binary forms, with or without
1677
 * modification, are permitted provided that the following conditions
1678
 * are met:
1679
 * 1. Redistributions of source code must retain the above copyright
1680
 *    notice, this list of conditions and the following disclaimer.
1681
 * 2. Redistributions in binary form must reproduce the above copyright
1682
 *    notice, this list of conditions and the following disclaimer in the
1683
 *    documentation and/or other materials provided with the distribution.
1684
 *
1685
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
1686
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1687
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1688
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1689
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1690
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1691
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1692
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1693
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1694
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1695
 */
1696

1697
/* OPENBSD ORIGINAL: sys/sys/tree.h */
1698

1699
/*
1700
 * This file defines data structures for different types of trees:
1701
 * splay trees and red-black trees.
1702
 *
1703
 * A splay tree is a self-organizing data structure.  Every operation
1704
 * on the tree causes a splay to happen.  The splay moves the requested
1705
 * node to the root of the tree and partly rebalances it.
1706
 *
1707
 * This has the benefit that request locality causes faster lookups as
1708
 * the requested nodes move to the top of the tree.  On the other hand,
1709
 * every lookup causes memory writes.
1710
 *
1711
 * The Balance Theorem bounds the total access time for m operations
1712
 * and n inserts on an initially empty tree as O((m + n)lg n).  The
1713
 * amortized cost for a sequence of m accesses to a splay tree is O(lg n);
1714
 *
1715
 * A red-black tree is a binary search tree with the node color as an
1716
 * extra attribute.  It fulfills a set of conditions:
1717
 *	- every search path from the root to a leaf consists of the
1718
 *	  same number of black nodes,
1719
 *	- each red node (except for the root) has a black parent,
1720
 *	- each leaf node is black.
1721
 *
1722
 * Every operation on a red-black tree is bounded as O(lg n).
1723
 * The maximum height of a red-black tree is 2lg (n+1).
1724
 */
1725

1726
#define SPLAY_HEAD(name, type)						\\
1727
struct name {								\\
1728
	struct type *sph_root; /* root of the tree */			\\
1729
}
1730

1731
#define SPLAY_INITIALIZER(root)						\\
1732
	{ NULL }
1733

1734
#define SPLAY_INIT(root) do {						\\
1735
	(root)->sph_root = NULL;					\\
1736
} while (0)
1737

1738
#define SPLAY_ENTRY(type)						\\
1739
struct {								\\
1740
	struct type *spe_left; /* left element */			\\
1741
	struct type *spe_right; /* right element */			\\
1742
}
1743

1744
#define SPLAY_LEFT(elm, field)		(elm)->field.spe_left
1745
#define SPLAY_RIGHT(elm, field)		(elm)->field.spe_right
1746
#define SPLAY_ROOT(head)		(head)->sph_root
1747
#define SPLAY_EMPTY(head)		(SPLAY_ROOT(head) == NULL)
1748

1749
/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
1750
#define SPLAY_ROTATE_RIGHT(head, tmp, field) do {			\\
1751
	SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field);	\\
1752
	SPLAY_RIGHT(tmp, field) = (head)->sph_root;			\\
1753
	(head)->sph_root = tmp;						\\
1754
} while (0)
1755
	
1756
#define SPLAY_ROTATE_LEFT(head, tmp, field) do {			\\
1757
	SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field);	\\
1758
	SPLAY_LEFT(tmp, field) = (head)->sph_root;			\\
1759
	(head)->sph_root = tmp;						\\
1760
} while (0)
1761

1762
#define SPLAY_LINKLEFT(head, tmp, field) do {				\\
1763
	SPLAY_LEFT(tmp, field) = (head)->sph_root;			\\
1764
	tmp = (head)->sph_root;						\\
1765
	(head)->sph_root = SPLAY_LEFT((head)->sph_root, field);		\\
1766
} while (0)
1767

1768
#define SPLAY_LINKRIGHT(head, tmp, field) do {				\\
1769
	SPLAY_RIGHT(tmp, field) = (head)->sph_root;			\\
1770
	tmp = (head)->sph_root;						\\
1771
	(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);	\\
1772
} while (0)
1773

1774
#define SPLAY_ASSEMBLE(head, node, left, right, field) do {		\\
1775
	SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field);	\\
1776
	SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\\
1777
	SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field);	\\
1778
	SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field);	\\
1779
} while (0)
1780

1781
/* Generates prototypes and inline functions */
1782

1783
#define SPLAY_PROTOTYPE(name, type, field, cmp)				\\
1784
void name##_SPLAY(struct name *, struct type *);			\\
1785
void name##_SPLAY_MINMAX(struct name *, int);				\\
1786
struct type *name##_SPLAY_INSERT(struct name *, struct type *);		\\
1787
struct type *name##_SPLAY_REMOVE(struct name *, struct type *);		\\
1788
									\\
1789
/* Finds the node with the same key as elm */				\\
1790
static __inline struct type *						\\
1791
name##_SPLAY_FIND(struct name *head, struct type *elm)			\\
1792
{									\\
1793
	if (SPLAY_EMPTY(head))						\\
1794
		return(NULL);						\\
1795
	name##_SPLAY(head, elm);					\\
1796
	if ((cmp)(elm, (head)->sph_root) == 0)				\\
1797
		return (head->sph_root);				\\
1798
	return (NULL);							\\
1799
}									\\
1800
									\\
1801
static __inline struct type *						\\
1802
name##_SPLAY_NEXT(struct name *head, struct type *elm)			\\
1803
{									\\
1804
	name##_SPLAY(head, elm);					\\
1805
	if (SPLAY_RIGHT(elm, field) != NULL) {				\\
1806
		elm = SPLAY_RIGHT(elm, field);				\\
1807
		while (SPLAY_LEFT(elm, field) != NULL) {		\\
1808
			elm = SPLAY_LEFT(elm, field);			\\
1809
		}							\\
1810
	} else								\\
1811
		elm = NULL;						\\
1812
	return (elm);							\\
1813
}									\\
1814
									\\
1815
static __inline struct type *						\\
1816
name##_SPLAY_MIN_MAX(struct name *head, int val)			\\
1817
{									\\
1818
	name##_SPLAY_MINMAX(head, val);					\\
1819
        return (SPLAY_ROOT(head));					\\
1820
}
1821

1822
/* Main splay operation.
1823
 * Moves node close to the key of elm to top
1824
 */
1825
#define SPLAY_GENERATE(name, type, field, cmp)				\\
1826
struct type *								\\
1827
name##_SPLAY_INSERT(struct name *head, struct type *elm)		\\
1828
{									\\
1829
    if (SPLAY_EMPTY(head)) {						\\
1830
	    SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL;	\\
1831
    } else {								\\
1832
	    int __comp;							\\
1833
	    name##_SPLAY(head, elm);					\\
1834
	    __comp = (cmp)(elm, (head)->sph_root);			\\
1835
	    if(__comp < 0) {						\\
1836
		    SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\\
1837
		    SPLAY_RIGHT(elm, field) = (head)->sph_root;		\\
1838
		    SPLAY_LEFT((head)->sph_root, field) = NULL;		\\
1839
	    } else if (__comp > 0) {					\\
1840
		    SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\\
1841
		    SPLAY_LEFT(elm, field) = (head)->sph_root;		\\
1842
		    SPLAY_RIGHT((head)->sph_root, field) = NULL;	\\
1843
	    } else							\\
1844
		    return ((head)->sph_root);				\\
1845
    }									\\
1846
    (head)->sph_root = (elm);						\\
1847
    return (NULL);							\\
1848
}									\\
1849
									\\
1850
struct type *								\\
1851
name##_SPLAY_REMOVE(struct name *head, struct type *elm)		\\
1852
{									\\
1853
	struct type *__tmp;						\\
1854
	if (SPLAY_EMPTY(head))						\\
1855
		return (NULL);						\\
1856
	name##_SPLAY(head, elm);					\\
1857
	if ((cmp)(elm, (head)->sph_root) == 0) {			\\
1858
		if (SPLAY_LEFT((head)->sph_root, field) == NULL) {	\\
1859
			(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\\
1860
		} else {						\\
1861
			__tmp = SPLAY_RIGHT((head)->sph_root, field);	\\
1862
			(head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\\
1863
			name##_SPLAY(head, elm);			\\
1864
			SPLAY_RIGHT((head)->sph_root, field) = __tmp;	\\
1865
		}							\\
1866
		return (elm);						\\
1867
	}								\\
1868
	return (NULL);							\\
1869
}									\\
1870
									\\
1871
void									\\
1872
name##_SPLAY(struct name *head, struct type *elm)			\\
1873
{									\\
1874
	struct type __node, *__left, *__right, *__tmp;			\\
1875
	int __comp;							\\
1876
\\
1877
	SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\\
1878
	__left = __right = &__node;					\\
1879
\\
1880
	while ((__comp = (cmp)(elm, (head)->sph_root))) {		\\
1881
		if (__comp < 0) {					\\
1882
			__tmp = SPLAY_LEFT((head)->sph_root, field);	\\
1883
			if (__tmp == NULL)				\\
1884
				break;					\\
1885
			if ((cmp)(elm, __tmp) < 0){			\\
1886
				SPLAY_ROTATE_RIGHT(head, __tmp, field);	\\
1887
				if (SPLAY_LEFT((head)->sph_root, field) == NULL)\\
1888
					break;				\\
1889
			}						\\
1890
			SPLAY_LINKLEFT(head, __right, field);		\\
1891
		} else if (__comp > 0) {				\\
1892
			__tmp = SPLAY_RIGHT((head)->sph_root, field);	\\
1893
			if (__tmp == NULL)				\\
1894
				break;					\\
1895
			if ((cmp)(elm, __tmp) > 0){			\\
1896
				SPLAY_ROTATE_LEFT(head, __tmp, field);	\\
1897
				if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\\
1898
					break;				\\
1899
			}						\\
1900
			SPLAY_LINKRIGHT(head, __left, field);		\\
1901
		}							\\
1902
	}								\\
1903
	SPLAY_ASSEMBLE(head, &__node, __left, __right, field);		\\
1904
}									\\
1905
									\\
1906
/* Splay with either the minimum or the maximum element			\\
1907
 * Used to find minimum or maximum element in tree.			\\
1908
 */									\\
1909
void name##_SPLAY_MINMAX(struct name *head, int __comp) \\
1910
{									\\
1911
	struct type __node, *__left, *__right, *__tmp;			\\
1912
\\
1913
	SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\\
1914
	__left = __right = &__node;					\\
1915
\\
1916
	while (1) {							\\
1917
		if (__comp < 0) {					\\
1918
			__tmp = SPLAY_LEFT((head)->sph_root, field);	\\
1919
			if (__tmp == NULL)				\\
1920
				break;					\\
1921
			if (__comp < 0){				\\
1922
				SPLAY_ROTATE_RIGHT(head, __tmp, field);	\\
1923
				if (SPLAY_LEFT((head)->sph_root, field) == NULL)\\
1924
					break;				\\
1925
			}						\\
1926
			SPLAY_LINKLEFT(head, __right, field);		\\
1927
		} else if (__comp > 0) {				\\
1928
			__tmp = SPLAY_RIGHT((head)->sph_root, field);	\\
1929
			if (__tmp == NULL)				\\
1930
				break;					\\
1931
			if (__comp > 0) {				\\
1932
				SPLAY_ROTATE_LEFT(head, __tmp, field);	\\
1933
				if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\\
1934
					break;				\\
1935
			}						\\
1936
			SPLAY_LINKRIGHT(head, __left, field);		\\
1937
		}							\\
1938
	}								\\
1939
	SPLAY_ASSEMBLE(head, &__node, __left, __right, field);		\\
1940
}
1941

1942
#define SPLAY_NEGINF	-1
1943
#define SPLAY_INF	1
1944

1945
#define SPLAY_INSERT(name, x, y)	name##_SPLAY_INSERT(x, y)
1946
#define SPLAY_REMOVE(name, x, y)	name##_SPLAY_REMOVE(x, y)
1947
#define SPLAY_FIND(name, x, y)		name##_SPLAY_FIND(x, y)
1948
#define SPLAY_NEXT(name, x, y)		name##_SPLAY_NEXT(x, y)
1949
#define SPLAY_MIN(name, x)		(SPLAY_EMPTY(x) ? NULL	\\
1950
					: name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
1951
#define SPLAY_MAX(name, x)		(SPLAY_EMPTY(x) ? NULL	\\
1952
					: name##_SPLAY_MIN_MAX(x, SPLAY_INF))
1953

1954
#define SPLAY_FOREACH(x, name, head)					\\
1955
	for ((x) = SPLAY_MIN(name, head);				\\
1956
	     (x) != NULL;						\\
1957
	     (x) = SPLAY_NEXT(name, head, x))
1958

1959
/* Macros that define a red-black tree */
1960
#define RB_HEAD(name, type)						\\
1961
struct name {								\\
1962
	struct type *rbh_root; /* root of the tree */			\\
1963
}
1964

1965
#define RB_INITIALIZER(root)						\\
1966
	{ NULL }
1967

1968
#define RB_INIT(root) do {						\\
1969
	(root)->rbh_root = NULL;					\\
1970
} while (0)
1971

1972
#define RB_BLACK	0
1973
#define RB_RED		1
1974
#define RB_ENTRY(type)							\\
1975
struct {								\\
1976
	struct type *rbe_left;		/* left element */		\\
1977
	struct type *rbe_right;		/* right element */		\\
1978
	struct type *rbe_parent;	/* parent element */		\\
1979
	int rbe_color;			/* node color */		\\
1980
}
1981

1982
#define RB_LEFT(elm, field)		(elm)->field.rbe_left
1983
#define RB_RIGHT(elm, field)		(elm)->field.rbe_right
1984
#define RB_PARENT(elm, field)		(elm)->field.rbe_parent
1985
#define RB_COLOR(elm, field)		(elm)->field.rbe_color
1986
#define RB_ROOT(head)			(head)->rbh_root
1987
#define RB_EMPTY(head)			(RB_ROOT(head) == NULL)
1988

1989
#define RB_SET(elm, parent, field) do {					\\
1990
	RB_PARENT(elm, field) = parent;					\\
1991
	RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL;		\\
1992
	RB_COLOR(elm, field) = RB_RED;					\\
1993
} while (0)
1994

1995
#define RB_SET_BLACKRED(black, red, field) do {				\\
1996
	RB_COLOR(black, field) = RB_BLACK;				\\
1997
	RB_COLOR(red, field) = RB_RED;					\\
1998
} while (0)
1999

2000
#ifndef RB_AUGMENT
2001
#define RB_AUGMENT(x)	do {} while (0)
2002
#endif
2003

2004
#define RB_ROTATE_LEFT(head, elm, tmp, field) do {			\\
2005
	(tmp) = RB_RIGHT(elm, field);					\\
2006
	if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) {		\\
2007
		RB_PARENT(RB_LEFT(tmp, field), field) = (elm);		\\
2008
	}								\\
2009
	RB_AUGMENT(elm);						\\
2010
	if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) {		\\
2011
		if ((elm) == RB_LEFT(RB_PARENT(elm, field), field))	\\
2012
			RB_LEFT(RB_PARENT(elm, field), field) = (tmp);	\\
2013
		else							\\
2014
			RB_RIGHT(RB_PARENT(elm, field), field) = (tmp);	\\
2015
	} else								\\
2016
		(head)->rbh_root = (tmp);				\\
2017
	RB_LEFT(tmp, field) = (elm);					\\
2018
	RB_PARENT(elm, field) = (tmp);					\\
2019
	RB_AUGMENT(tmp);						\\
2020
	if ((RB_PARENT(tmp, field)))					\\
2021
		RB_AUGMENT(RB_PARENT(tmp, field));			\\
2022
} while (0)
2023

2024
#define RB_ROTATE_RIGHT(head, elm, tmp, field) do {			\\
2025
	(tmp) = RB_LEFT(elm, field);					\\
2026
	if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) {		\\
2027
		RB_PARENT(RB_RIGHT(tmp, field), field) = (elm);		\\
2028
	}								\\
2029
	RB_AUGMENT(elm);						\\
2030
	if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) {		\\
2031
		if ((elm) == RB_LEFT(RB_PARENT(elm, field), field))	\\
2032
			RB_LEFT(RB_PARENT(elm, field), field) = (tmp);	\\
2033
		else							\\
2034
			RB_RIGHT(RB_PARENT(elm, field), field) = (tmp);	\\
2035
	} else								\\
2036
		(head)->rbh_root = (tmp);				\\
2037
	RB_RIGHT(tmp, field) = (elm);					\\
2038
	RB_PARENT(elm, field) = (tmp);					\\
2039
	RB_AUGMENT(tmp);						\\
2040
	if ((RB_PARENT(tmp, field)))					\\
2041
		RB_AUGMENT(RB_PARENT(tmp, field));			\\
2042
} while (0)
2043

2044
/* Generates prototypes and inline functions */
2045
#define	RB_PROTOTYPE(name, type, field, cmp)				\\
2046
	RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
2047
#define	RB_PROTOTYPE_STATIC(name, type, field, cmp)			\\
2048
	RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
2049
#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr)		\\
2050
attr void name##_RB_INSERT_COLOR(struct name *, struct type *);		\\
2051
attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\\
2052
attr struct type *name##_RB_REMOVE(struct name *, struct type *);	\\
2053
attr struct type *name##_RB_INSERT(struct name *, struct type *);	\\
2054
attr struct type *name##_RB_FIND(struct name *, struct type *);		\\
2055
attr struct type *name##_RB_NFIND(struct name *, struct type *);	\\
2056
attr struct type *name##_RB_NEXT(struct type *);			\\
2057
attr struct type *name##_RB_PREV(struct type *);			\\
2058
attr struct type *name##_RB_MINMAX(struct name *, int);			\\
2059
									\\
2060

2061
/* Main rb operation.
2062
 * Moves node close to the key of elm to top
2063
 */
2064
#define	RB_GENERATE(name, type, field, cmp)				\\
2065
	RB_GENERATE_INTERNAL(name, type, field, cmp,)
2066
#define	RB_GENERATE_STATIC(name, type, field, cmp)			\\
2067
	RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
2068
#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr)		\\
2069
attr void								\\
2070
name##_RB_INSERT_COLOR(struct name *head, struct type *elm)		\\
2071
{									\\
2072
	struct type *parent, *gparent, *tmp;				\\
2073
	while ((parent = RB_PARENT(elm, field)) &&			\\
2074
	    RB_COLOR(parent, field) == RB_RED) {			\\
2075
		gparent = RB_PARENT(parent, field);			\\
2076
		if (parent == RB_LEFT(gparent, field)) {		\\
2077
			tmp = RB_RIGHT(gparent, field);			\\
2078
			if (tmp && RB_COLOR(tmp, field) == RB_RED) {	\\
2079
				RB_COLOR(tmp, field) = RB_BLACK;	\\
2080
				RB_SET_BLACKRED(parent, gparent, field);\\
2081
				elm = gparent;				\\
2082
				continue;				\\
2083
			}						\\
2084
			if (RB_RIGHT(parent, field) == elm) {		\\
2085
				RB_ROTATE_LEFT(head, parent, tmp, field);\\
2086
				tmp = parent;				\\
2087
				parent = elm;				\\
2088
				elm = tmp;				\\
2089
			}						\\
2090
			RB_SET_BLACKRED(parent, gparent, field);	\\
2091
			RB_ROTATE_RIGHT(head, gparent, tmp, field);	\\
2092
		} else {						\\
2093
			tmp = RB_LEFT(gparent, field);			\\
2094
			if (tmp && RB_COLOR(tmp, field) == RB_RED) {	\\
2095
				RB_COLOR(tmp, field) = RB_BLACK;	\\
2096
				RB_SET_BLACKRED(parent, gparent, field);\\
2097
				elm = gparent;				\\
2098
				continue;				\\
2099
			}						\\
2100
			if (RB_LEFT(parent, field) == elm) {		\\
2101
				RB_ROTATE_RIGHT(head, parent, tmp, field);\\
2102
				tmp = parent;				\\
2103
				parent = elm;				\\
2104
				elm = tmp;				\\
2105
			}						\\
2106
			RB_SET_BLACKRED(parent, gparent, field);	\\
2107
			RB_ROTATE_LEFT(head, gparent, tmp, field);	\\
2108
		}							\\
2109
	}								\\
2110
	RB_COLOR(head->rbh_root, field) = RB_BLACK;			\\
2111
}									\\
2112
									\\
2113
attr void								\\
2114
name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \\
2115
{									\\
2116
	struct type *tmp;						\\
2117
	while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) &&	\\
2118
	    elm != RB_ROOT(head)) {					\\
2119
		if (RB_LEFT(parent, field) == elm) {			\\
2120
			tmp = RB_RIGHT(parent, field);			\\
2121
			if (RB_COLOR(tmp, field) == RB_RED) {		\\
2122
				RB_SET_BLACKRED(tmp, parent, field);	\\
2123
				RB_ROTATE_LEFT(head, parent, tmp, field);\\
2124
				tmp = RB_RIGHT(parent, field);		\\
2125
			}						\\
2126
			if ((RB_LEFT(tmp, field) == NULL ||		\\
2127
			    RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\\
2128
			    (RB_RIGHT(tmp, field) == NULL ||		\\
2129
			    RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\\
2130
				RB_COLOR(tmp, field) = RB_RED;		\\
2131
				elm = parent;				\\
2132
				parent = RB_PARENT(elm, field);		\\
2133
			} else {					\\
2134
				if (RB_RIGHT(tmp, field) == NULL ||	\\
2135
				    RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\\
2136
					struct type *oleft;		\\
2137
					if ((oleft = RB_LEFT(tmp, field)))\\
2138
						RB_COLOR(oleft, field) = RB_BLACK;\\
2139
					RB_COLOR(tmp, field) = RB_RED;	\\
2140
					RB_ROTATE_RIGHT(head, tmp, oleft, field);\\
2141
					tmp = RB_RIGHT(parent, field);	\\
2142
				}					\\
2143
				RB_COLOR(tmp, field) = RB_COLOR(parent, field);\\
2144
				RB_COLOR(parent, field) = RB_BLACK;	\\
2145
				if (RB_RIGHT(tmp, field))		\\
2146
					RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\\
2147
				RB_ROTATE_LEFT(head, parent, tmp, field);\\
2148
				elm = RB_ROOT(head);			\\
2149
				break;					\\
2150
			}						\\
2151
		} else {						\\
2152
			tmp = RB_LEFT(parent, field);			\\
2153
			if (RB_COLOR(tmp, field) == RB_RED) {		\\
2154
				RB_SET_BLACKRED(tmp, parent, field);	\\
2155
				RB_ROTATE_RIGHT(head, parent, tmp, field);\\
2156
				tmp = RB_LEFT(parent, field);		\\
2157
			}						\\
2158
			if ((RB_LEFT(tmp, field) == NULL ||		\\
2159
			    RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\\
2160
			    (RB_RIGHT(tmp, field) == NULL ||		\\
2161
			    RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\\
2162
				RB_COLOR(tmp, field) = RB_RED;		\\
2163
				elm = parent;				\\
2164
				parent = RB_PARENT(elm, field);		\\
2165
			} else {					\\
2166
				if (RB_LEFT(tmp, field) == NULL ||	\\
2167
				    RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\\
2168
					struct type *oright;		\\
2169
					if ((oright = RB_RIGHT(tmp, field)))\\
2170
						RB_COLOR(oright, field) = RB_BLACK;\\
2171
					RB_COLOR(tmp, field) = RB_RED;	\\
2172
					RB_ROTATE_LEFT(head, tmp, oright, field);\\
2173
					tmp = RB_LEFT(parent, field);	\\
2174
				}					\\
2175
				RB_COLOR(tmp, field) = RB_COLOR(parent, field);\\
2176
				RB_COLOR(parent, field) = RB_BLACK;	\\
2177
				if (RB_LEFT(tmp, field))		\\
2178
					RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\\
2179
				RB_ROTATE_RIGHT(head, parent, tmp, field);\\
2180
				elm = RB_ROOT(head);			\\
2181
				break;					\\
2182
			}						\\
2183
		}							\\
2184
	}								\\
2185
	if (elm)							\\
2186
		RB_COLOR(elm, field) = RB_BLACK;			\\
2187
}									\\
2188
									\\
2189
attr struct type *							\\
2190
name##_RB_REMOVE(struct name *head, struct type *elm)			\\
2191
{									\\
2192
	struct type *child, *parent, *old = elm;			\\
2193
	int color;							\\
2194
	if (RB_LEFT(elm, field) == NULL)				\\
2195
		child = RB_RIGHT(elm, field);				\\
2196
	else if (RB_RIGHT(elm, field) == NULL)				\\
2197
		child = RB_LEFT(elm, field);				\\
2198
	else {								\\
2199
		struct type *left;					\\
2200
		elm = RB_RIGHT(elm, field);				\\
2201
		while ((left = RB_LEFT(elm, field)))			\\
2202
			elm = left;					\\
2203
		child = RB_RIGHT(elm, field);				\\
2204
		parent = RB_PARENT(elm, field);				\\
2205
		color = RB_COLOR(elm, field);				\\
2206
		if (child)						\\
2207
			RB_PARENT(child, field) = parent;		\\
2208
		if (parent) {						\\
2209
			if (RB_LEFT(parent, field) == elm)		\\
2210
				RB_LEFT(parent, field) = child;		\\
2211
			else						\\
2212
				RB_RIGHT(parent, field) = child;	\\
2213
			RB_AUGMENT(parent);				\\
2214
		} else							\\
2215
			RB_ROOT(head) = child;				\\
2216
		if (RB_PARENT(elm, field) == old)			\\
2217
			parent = elm;					\\
2218
		(elm)->field = (old)->field;				\\
2219
		if (RB_PARENT(old, field)) {				\\
2220
			if (RB_LEFT(RB_PARENT(old, field), field) == old)\\
2221
				RB_LEFT(RB_PARENT(old, field), field) = elm;\\
2222
			else						\\
2223
				RB_RIGHT(RB_PARENT(old, field), field) = elm;\\
2224
			RB_AUGMENT(RB_PARENT(old, field));		\\
2225
		} else							\\
2226
			RB_ROOT(head) = elm;				\\
2227
		RB_PARENT(RB_LEFT(old, field), field) = elm;		\\
2228
		if (RB_RIGHT(old, field))				\\
2229
			RB_PARENT(RB_RIGHT(old, field), field) = elm;	\\
2230
		if (parent) {						\\
2231
			left = parent;					\\
2232
			do {						\\
2233
				RB_AUGMENT(left);			\\
2234
			} while ((left = RB_PARENT(left, field)));	\\
2235
		}							\\
2236
		goto color;						\\
2237
	}								\\
2238
	parent = RB_PARENT(elm, field);					\\
2239
	color = RB_COLOR(elm, field);					\\
2240
	if (child)							\\
2241
		RB_PARENT(child, field) = parent;			\\
2242
	if (parent) {							\\
2243
		if (RB_LEFT(parent, field) == elm)			\\
2244
			RB_LEFT(parent, field) = child;			\\
2245
		else							\\
2246
			RB_RIGHT(parent, field) = child;		\\
2247
		RB_AUGMENT(parent);					\\
2248
	} else								\\
2249
		RB_ROOT(head) = child;					\\
2250
color:									\\
2251
	if (color == RB_BLACK)						\\
2252
		name##_RB_REMOVE_COLOR(head, parent, child);		\\
2253
	return (old);							\\
2254
}									\\
2255
									\\
2256
/* Inserts a node into the RB tree */					\\
2257
attr struct type *							\\
2258
name##_RB_INSERT(struct name *head, struct type *elm)			\\
2259
{									\\
2260
	struct type *tmp;						\\
2261
	struct type *parent = NULL;					\\
2262
	int comp = 0;							\\
2263
	tmp = RB_ROOT(head);						\\
2264
	while (tmp) {							\\
2265
		parent = tmp;						\\
2266
		comp = (cmp)(elm, parent);				\\
2267
		if (comp < 0)						\\
2268
			tmp = RB_LEFT(tmp, field);			\\
2269
		else if (comp > 0)					\\
2270
			tmp = RB_RIGHT(tmp, field);			\\
2271
		else							\\
2272
			return (tmp);					\\
2273
	}								\\
2274
	RB_SET(elm, parent, field);					\\
2275
	if (parent != NULL) {						\\
2276
		if (comp < 0)						\\
2277
			RB_LEFT(parent, field) = elm;			\\
2278
		else							\\
2279
			RB_RIGHT(parent, field) = elm;			\\
2280
		RB_AUGMENT(parent);					\\
2281
	} else								\\
2282
		RB_ROOT(head) = elm;					\\
2283
	name##_RB_INSERT_COLOR(head, elm);				\\
2284
	return (NULL);							\\
2285
}									\\
2286
									\\
2287
/* Finds the node with the same key as elm */				\\
2288
attr struct type *							\\
2289
name##_RB_FIND(struct name *head, struct type *elm)			\\
2290
{									\\
2291
	struct type *tmp = RB_ROOT(head);				\\
2292
	int comp;							\\
2293
	while (tmp) {							\\
2294
		comp = cmp(elm, tmp);					\\
2295
		if (comp < 0)						\\
2296
			tmp = RB_LEFT(tmp, field);			\\
2297
		else if (comp > 0)					\\
2298
			tmp = RB_RIGHT(tmp, field);			\\
2299
		else							\\
2300
			return (tmp);					\\
2301
	}								\\
2302
	return (NULL);							\\
2303
}									\\
2304
									\\
2305
/* Finds the first node greater than or equal to the search key */	\\
2306
attr struct type *							\\
2307
name##_RB_NFIND(struct name *head, struct type *elm)			\\
2308
{									\\
2309
	struct type *tmp = RB_ROOT(head);				\\
2310
	struct type *res = NULL;					\\
2311
	int comp;							\\
2312
	while (tmp) {							\\
2313
		comp = cmp(elm, tmp);					\\
2314
		if (comp < 0) {						\\
2315
			res = tmp;					\\
2316
			tmp = RB_LEFT(tmp, field);			\\
2317
		}							\\
2318
		else if (comp > 0)					\\
2319
			tmp = RB_RIGHT(tmp, field);			\\
2320
		else							\\
2321
			return (tmp);					\\
2322
	}								\\
2323
	return (res);							\\
2324
}									\\
2325
									\\
2326
/* ARGSUSED */								\\
2327
attr struct type *							\\
2328
name##_RB_NEXT(struct type *elm)					\\
2329
{									\\
2330
	if (RB_RIGHT(elm, field)) {					\\
2331
		elm = RB_RIGHT(elm, field);				\\
2332
		while (RB_LEFT(elm, field))				\\
2333
			elm = RB_LEFT(elm, field);			\\
2334
	} else {							\\
2335
		if (RB_PARENT(elm, field) &&				\\
2336
		    (elm == RB_LEFT(RB_PARENT(elm, field), field)))	\\
2337
			elm = RB_PARENT(elm, field);			\\
2338
		else {							\\
2339
			while (RB_PARENT(elm, field) &&			\\
2340
			    (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\\
2341
				elm = RB_PARENT(elm, field);		\\
2342
			elm = RB_PARENT(elm, field);			\\
2343
		}							\\
2344
	}								\\
2345
	return (elm);							\\
2346
}									\\
2347
									\\
2348
/* ARGSUSED */								\\
2349
attr struct type *							\\
2350
name##_RB_PREV(struct type *elm)					\\
2351
{									\\
2352
	if (RB_LEFT(elm, field)) {					\\
2353
		elm = RB_LEFT(elm, field);				\\
2354
		while (RB_RIGHT(elm, field))				\\
2355
			elm = RB_RIGHT(elm, field);			\\
2356
	} else {							\\
2357
		if (RB_PARENT(elm, field) &&				\\
2358
		    (elm == RB_RIGHT(RB_PARENT(elm, field), field)))	\\
2359
			elm = RB_PARENT(elm, field);			\\
2360
		else {							\\
2361
			while (RB_PARENT(elm, field) &&			\\
2362
			    (elm == RB_LEFT(RB_PARENT(elm, field), field)))\\
2363
				elm = RB_PARENT(elm, field);		\\
2364
			elm = RB_PARENT(elm, field);			\\
2365
		}							\\
2366
	}								\\
2367
	return (elm);							\\
2368
}									\\
2369
									\\
2370
attr struct type *							\\
2371
name##_RB_MINMAX(struct name *head, int val)				\\
2372
{									\\
2373
	struct type *tmp = RB_ROOT(head);				\\
2374
	struct type *parent = NULL;					\\
2375
	while (tmp) {							\\
2376
		parent = tmp;						\\
2377
		if (val < 0)						\\
2378
			tmp = RB_LEFT(tmp, field);			\\
2379
		else							\\
2380
			tmp = RB_RIGHT(tmp, field);			\\
2381
	}								\\
2382
	return (parent);						\\
2383
}
2384

2385
#define RB_NEGINF	-1
2386
#define RB_INF	1
2387

2388
#define RB_INSERT(name, x, y)	name##_RB_INSERT(x, y)
2389
#define RB_REMOVE(name, x, y)	name##_RB_REMOVE(x, y)
2390
#define RB_FIND(name, x, y)	name##_RB_FIND(x, y)
2391
#define RB_NFIND(name, x, y)	name##_RB_NFIND(x, y)
2392
#define RB_NEXT(name, x, y)	name##_RB_NEXT(y)
2393
#define RB_PREV(name, x, y)	name##_RB_PREV(y)
2394
#define RB_MIN(name, x)		name##_RB_MINMAX(x, RB_NEGINF)
2395
#define RB_MAX(name, x)		name##_RB_MINMAX(x, RB_INF)
2396

2397
#define RB_FOREACH(x, name, head)					\\
2398
	for ((x) = RB_MIN(name, head);					\\
2399
	     (x) != NULL;						\\
2400
	     (x) = name##_RB_NEXT(x))
2401

2402
#define RB_FOREACH_SAFE(x, name, head, y)				\\
2403
	for ((x) = RB_MIN(name, head);					\\
2404
	    ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1);		\\
2405
	     (x) = (y))
2406

2407
#define RB_FOREACH_REVERSE(x, name, head)				\\
2408
	for ((x) = RB_MAX(name, head);					\\
2409
	     (x) != NULL;						\\
2410
	     (x) = name##_RB_PREV(x))
2411

2412
#define RB_FOREACH_REVERSE_SAFE(x, name, head, y)			\\
2413
	for ((x) = RB_MAX(name, head);					\\
2414
	    ((x) != NULL) && ((y) = name##_RB_PREV(x), 1);		\\
2415
	     (x) = (y))
2416

2417
__HEREDOC__
2418
fi
2419

2420
if [ ${HAVE_FTS} -eq 0 ]; then
2421
	cat << __HEREDOC__
2422
/*
2423
 * Compatibility for fts(3) functions.
2424
 */
2425
typedef struct {
2426
	struct _ftsent *fts_cur;	/* current node */
2427
	struct _ftsent *fts_child;	/* linked list of children */
2428
	struct _ftsent **fts_array;	/* sort array */
2429
	dev_t fts_dev;			/* starting device # */
2430
	char *fts_path;			/* path for this descent */
2431
	int fts_rfd;			/* fd for root */
2432
	size_t fts_pathlen;		/* sizeof(path) */
2433
	int fts_nitems;			/* elements in the sort array */
2434
	int (*fts_compar)(const struct _ftsent **, const struct _ftsent **); /* compare function */
2435
#define	FTS_COMFOLLOW	0x0001		/* follow command line symlinks */
2436
#define	FTS_LOGICAL	0x0002		/* logical walk */
2437
#define	FTS_NOCHDIR	0x0004		/* don't change directories */
2438
#define	FTS_NOSTAT	0x0008		/* don't get stat info */
2439
#define	FTS_PHYSICAL	0x0010		/* physical walk */
2440
#define	FTS_SEEDOT	0x0020		/* return dot and dot-dot */
2441
#define	FTS_XDEV	0x0040		/* don't cross devices */
2442
#define	FTS_OPTIONMASK	0x00ff		/* valid user option mask */
2443
#define	FTS_NAMEONLY	0x1000		/* (private) child names only */
2444
#define	FTS_STOP	0x2000		/* (private) unrecoverable error */
2445
	int fts_options;		/* fts_open options, global flags */
2446
} FTS;
2447

2448
typedef struct _ftsent {
2449
	struct _ftsent *fts_cycle;	/* cycle node */
2450
	struct _ftsent *fts_parent;	/* parent directory */
2451
	struct _ftsent *fts_link;	/* next file in directory */
2452
	long fts_number;	        /* local numeric value */
2453
	void *fts_pointer;	        /* local address value */
2454
	char *fts_accpath;		/* access path */
2455
	char *fts_path;			/* root path */
2456
	int fts_errno;			/* errno for this node */
2457
	int fts_symfd;			/* fd for symlink */
2458
	size_t fts_pathlen;		/* strlen(fts_path) */
2459
	size_t fts_namelen;		/* strlen(fts_name) */
2460
	ino_t fts_ino;			/* inode */
2461
	dev_t fts_dev;			/* device */
2462
	nlink_t fts_nlink;		/* link count */
2463
#define	FTS_ROOTPARENTLEVEL	-1
2464
#define	FTS_ROOTLEVEL		 0
2465
#define	FTS_MAXLEVEL		 0x7fffffff
2466
	int fts_level;		/* depth (-1 to N) */
2467
#define	FTS_D		 1		/* preorder directory */
2468
#define	FTS_DC		 2		/* directory that causes cycles */
2469
#define	FTS_DEFAULT	 3		/* none of the above */
2470
#define	FTS_DNR		 4		/* unreadable directory */
2471
#define	FTS_DOT		 5		/* dot or dot-dot */
2472
#define	FTS_DP		 6		/* postorder directory */
2473
#define	FTS_ERR		 7		/* error; errno is set */
2474
#define	FTS_F		 8		/* regular file */
2475
#define	FTS_INIT	 9		/* initialized only */
2476
#define	FTS_NS		10		/* stat(2) failed */
2477
#define	FTS_NSOK	11		/* no stat(2) requested */
2478
#define	FTS_SL		12		/* symbolic link */
2479
#define	FTS_SLNONE	13		/* symbolic link without target */
2480
	unsigned short fts_info;	/* user flags for FTSENT structure */
2481
#define	FTS_DONTCHDIR	 0x01		/* don't chdir .. to the parent */
2482
#define	FTS_SYMFOLLOW	 0x02		/* followed a symlink to get here */
2483
	unsigned short fts_flags;	/* private flags for FTSENT structure */
2484
#define	FTS_AGAIN	 1		/* read node again */
2485
#define	FTS_FOLLOW	 2		/* follow symbolic link */
2486
#define	FTS_NOINSTR	 3		/* no instructions */
2487
#define	FTS_SKIP	 4		/* discard node */
2488
	unsigned short fts_instr;	/* fts_set() instructions */
2489
	unsigned short fts_spare;	/* unused */
2490
	struct stat *fts_statp;		/* stat(2) information */
2491
	char fts_name[1];		/* file name */
2492
} FTSENT;
2493

2494
FTSENT	*fts_children(FTS *, int);
2495
int	 fts_close(FTS *);
2496
FTS	*fts_open(char * const *, int,
2497
	    int (*)(const FTSENT **, const FTSENT **));
2498
FTSENT	*fts_read(FTS *);
2499
int	 fts_set(FTS *, FTSENT *, int);
2500

2501
__HEREDOC__
2502
fi
2503

2504
cat << __HEREDOC__
2505
#endif /*!OCONFIGURE_CONFIG_H*/
2506
__HEREDOC__
2507

2508
echo "config.h: written" 1>&2
2509
echo "config.h: written" 1>&3
2510

2511
#----------------------------------------------------------------------
2512
# Now we go to generate our Makefile.configure.
2513
# This file is simply a bunch of Makefile variables.
2514
# They'll work in both GNUmakefile and BSDmakefile.
2515
# You MIGHT want to change this.
2516
#----------------------------------------------------------------------
2517

2518
exec > Makefile.configure
2519

2520
[ -z "${BINDIR}"     ] && BINDIR="${PREFIX}/bin"
2521
[ -z "${SBINDIR}"    ] && SBINDIR="${PREFIX}/sbin"
2522
[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
2523
[ -z "${LIBDIR}"     ] && LIBDIR="${PREFIX}/lib"
2524
[ -z "${MANDIR}"     ] && MANDIR="${PREFIX}/man"
2525
[ -z "${SHAREDIR}"   ] && SHAREDIR="${PREFIX}/share"
2526

2527
[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
2528
[ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0444"
2529
[ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0444"
2530
[ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0444"
2531

2532
cat << __HEREDOC__
2533
AR		 = ${AR}
2534
CC		 = ${CC}
2535
CFLAGS		 = ${CFLAGS}
2536
CPPFLAGS	 = ${CPPFLAGS}
2537
LDLIBS		 = ${LDLIBS}
2538
LDADD		 = ${LDADD}
2539
LDADD_B64_NTOP	 = ${LDADD_B64_NTOP}
2540
LDADD_CRYPT	 = ${LDADD_CRYPT}
2541
LDADD_LIB_SOCKET = ${LDADD_LIB_SOCKET}
2542
LDADD_MD5	 = ${LDADD_MD5}
2543
LDADD_SHA2	 = ${LDADD_SHA2}
2544
LDADD_SCAN_SCALED= ${LDADD_SCAN_SCALED}
2545
LDADD_STATIC	 = ${LDADD_STATIC}
2546
LDFLAGS		 = ${LDFLAGS}
2547
LINKER_SONAME	 = ${LINKER_SONAME}
2548
STATIC		 = ${STATIC}
2549
PREFIX		 = ${PREFIX}
2550
BINDIR		 = ${BINDIR}
2551
SHAREDIR	 = ${SHAREDIR}
2552
SBINDIR		 = ${SBINDIR}
2553
INCLUDEDIR	 = ${INCLUDEDIR}
2554
LIBDIR		 = ${LIBDIR}
2555
MANDIR		 = ${MANDIR}
2556
INSTALL		 = ${INSTALL}
2557
INSTALL_PROGRAM	 = ${INSTALL_PROGRAM}
2558
INSTALL_LIB	 = ${INSTALL_LIB}
2559
INSTALL_MAN	 = ${INSTALL_MAN}
2560
INSTALL_DATA	 = ${INSTALL_DATA}
2561
__HEREDOC__
2562

2563
echo "Makefile.configure: written" 1>&2
2564
echo "Makefile.configure: written" 1>&3
2565

2566
exit 0
2567

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.