3 80189b3a 2022-08-13 op # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4 80189b3a 2022-08-13 op # Copyright (c) 2017, 2018 Kristaps Dzonsons <kristaps@bsd.lv>
6 80189b3a 2022-08-13 op # Permission to use, copy, modify, and distribute this software for any
7 80189b3a 2022-08-13 op # purpose with or without fee is hereby granted, provided that the above
8 80189b3a 2022-08-13 op # copyright notice and this permission notice appear in all copies.
10 80189b3a 2022-08-13 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 80189b3a 2022-08-13 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 80189b3a 2022-08-13 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 80189b3a 2022-08-13 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 80189b3a 2022-08-13 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 80189b3a 2022-08-13 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 80189b3a 2022-08-13 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 80189b3a 2022-08-13 op OCONFIGURE_VERSION="0.3.8"
21 80189b3a 2022-08-13 op # This script outputs two files: config.h and Makefile.configure.
22 80189b3a 2022-08-13 op # It tries to read from configure.local, which contains predefined
23 80189b3a 2022-08-13 op # values we won't autoconfigure.
25 80189b3a 2022-08-13 op # If you want to use configure with your project, have your GNUmakefile
26 80189b3a 2022-08-13 op # or BSDmakefile---whichever---try to import/include Makefile.configure
27 80189b3a 2022-08-13 op # at the beginning of the file.
29 80189b3a 2022-08-13 op # Like so (note no quotes, no period, etc.):
31 80189b3a 2022-08-13 op # include Makefile.configure
33 80189b3a 2022-08-13 op # If it exists, configure was run; otherwise, it wasn't.
35 80189b3a 2022-08-13 op # You'll probably want to change parts of this file. I've noted the
36 80189b3a 2022-08-13 op # parts that you'll probably change in the section documentation.
38 80189b3a 2022-08-13 op # See https://github.com/kristapsdz/oconfigure for more.
42 80189b3a 2022-08-13 op # try to be helpful
46 80189b3a 2022-08-13 op \`configure' configures amused to adapt to many kinds of systems.
48 80189b3a 2022-08-13 op Usage: $0 [-h] [--prefix=path] [VAR=VALUE]...
50 80189b3a 2022-08-13 op The options are as follows:
52 80189b3a 2022-08-13 op -h, --help print this help message
54 80189b3a 2022-08-13 op --prefix=path equivalent to specify the PREFIX variable, supported
55 80189b3a 2022-08-13 op for compatibility with other common "configure" scripts.
57 80189b3a 2022-08-13 op Variables available:
59 80189b3a 2022-08-13 op LDADD generic linker flags
60 80189b3a 2022-08-13 op LDADD_LIBEVENT linker flags for libevent
61 80189b3a 2022-08-13 op LDADD_LIBEVENT2 linker flags for libevent2
62 80189b3a 2022-08-13 op LDADD_LIB_SOCKET linker flags for libsocket
63 80189b3a 2022-08-13 op LDFLAGS extra linker flags
64 80189b3a 2022-08-13 op CPPFLAGS C preprocessor flags
65 80189b3a 2022-08-13 op DESTDIR destination directory
66 80189b3a 2022-08-13 op MANDIR where to install man pages (PREFIX/man)
67 80189b3a 2022-08-13 op LIBDIR where to install libraries (PREFIX/lib)
68 80189b3a 2022-08-13 op BINDIR where to install executables (PREFIX/bin)
69 80189b3a 2022-08-13 op SHAREDIR where to install misc files (PREFIX/share)
70 80189b3a 2022-08-13 op SBINDIR where to install system executables (PREFIX/sbin)
71 80189b3a 2022-08-13 op INCLUDEDIR where to install header files (PREFIX/include)
72 80189b3a 2022-08-13 op PKG_CONFIG pkg-config program, \`false' to disable (pkg-config)
74 80189b3a 2022-08-13 op Additionally, the following environment variables are used if set:
76 80189b3a 2022-08-13 op CC the C compiler to use (defaults to cc, clang or gcc)
77 80189b3a 2022-08-13 op CFLAGS generic C compiler flags
83 80189b3a 2022-08-13 op #----------------------------------------------------------------------
84 80189b3a 2022-08-13 op # Prepare for running: move aside previous configure runs.
85 80189b3a 2022-08-13 op # Output file descriptor usage:
86 80189b3a 2022-08-13 op # 1 (stdout): config.h or Makefile.configure
87 80189b3a 2022-08-13 op # 2 (stderr): original stderr, usually to the console
88 80189b3a 2022-08-13 op # 3: config.log
89 80189b3a 2022-08-13 op # You DO NOT want to change this.
90 80189b3a 2022-08-13 op #----------------------------------------------------------------------
92 80189b3a 2022-08-13 op [ -w config.log ] && mv config.log config.log.old
93 80189b3a 2022-08-13 op [ -w config.h ] && mv config.h config.h.old
95 80189b3a 2022-08-13 op exec 3> config.log
96 80189b3a 2022-08-13 op echo "config.log: writing..."
98 80189b3a 2022-08-13 op # GNU submake prints different output if invoked recursively, which
99 80189b3a 2022-08-13 op # messes up CC and CFLAGS detection. Pass --no-print-directory if
100 80189b3a 2022-08-13 op # we have a MAKELEVEL (GNU and FreeBSD make) and the argument is
103 80189b3a 2022-08-13 op MAKE_FLAGS=""
105 80189b3a 2022-08-13 op if [ -n "${MAKELEVEL}" ]; then
106 80189b3a 2022-08-13 op if [ "${MAKELEVEL}" -gt 0 ] ; then
107 80189b3a 2022-08-13 op MAKE_FLAGS="--no-print-directory"
108 80189b3a 2022-08-13 op echo "all:" | make ${MAKE_FLAGS} -sf - 2>/dev/null || MAKE_FLAGS=""
112 80189b3a 2022-08-13 op if [ -n "$MAKE_FLAGS" ]; then
113 80189b3a 2022-08-13 op echo "GNU submake detected: using --no-print-directory" 1>&2
114 80189b3a 2022-08-13 op echo "GNU submake detected: using --no-print-directory" 1>&3
117 80189b3a 2022-08-13 op #----------------------------------------------------------------------
118 80189b3a 2022-08-13 op # Initialize all variables here such that nothing can leak in from the
119 80189b3a 2022-08-13 op # environment except for CC and CFLAGS, which we might have passed in.
120 80189b3a 2022-08-13 op #----------------------------------------------------------------------
122 80189b3a 2022-08-13 op CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make ${MAKE_FLAGS} -sf -`
123 80189b3a 2022-08-13 op CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | make ${MAKE_FLAGS} -sf -`
124 80189b3a 2022-08-13 op CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes"
125 80189b3a 2022-08-13 op CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter"
127 80189b3a 2022-08-13 op LDADD_LIBEVENT=
128 80189b3a 2022-08-13 op LDADD_LIBEVENT2=
129 80189b3a 2022-08-13 op LDADD_LIB_SOCKET=
130 80189b3a 2022-08-13 op LDADD_STATIC=
134 80189b3a 2022-08-13 op PREFIX="/usr/local"
141 80189b3a 2022-08-13 op INSTALL="install"
142 80189b3a 2022-08-13 op INSTALL_PROGRAM=
145 80189b3a 2022-08-13 op INSTALL_DATA=
147 80189b3a 2022-08-13 op # SunOS sets "cc", but this doesn't exist.
148 80189b3a 2022-08-13 op # It does have gcc, so try that instead.
149 80189b3a 2022-08-13 op # Prefer clang, though.
151 80189b3a 2022-08-13 op command -v ${CC} 2>/dev/null 1>&2 || {
152 80189b3a 2022-08-13 op echo "${CC} not found: trying clang" 1>&2
153 80189b3a 2022-08-13 op echo "${CC} not found: trying clang" 1>&3
155 80189b3a 2022-08-13 op command -v ${CC} 2>/dev/null 1>&2 || {
156 80189b3a 2022-08-13 op echo "${CC} not found: trying gcc" 1>&2
157 80189b3a 2022-08-13 op echo "${CC} not found: trying gcc" 1>&3
159 80189b3a 2022-08-13 op command -v ${CC} 2>/dev/null 1>&2 || {
160 80189b3a 2022-08-13 op echo "gcc not found: giving up" 1>&2
161 80189b3a 2022-08-13 op echo "gcc not found: giving up" 1>&3
167 80189b3a 2022-08-13 op #----------------------------------------------------------------------
168 80189b3a 2022-08-13 op # Allow certain variables to be overriden on the command line.
169 80189b3a 2022-08-13 op #----------------------------------------------------------------------
171 80189b3a 2022-08-13 op while [ $# -gt 0 ]; do
172 80189b3a 2022-08-13 op key"${1%%=*}"
173 80189b3a 2022-08-13 op val="${1#*=}"
175 80189b3a 2022-08-13 op if [ "$key" "-prefix" ]; then
177 80189b3a 2022-08-13 op if [ "$1" = "--prefix" ]; then
178 80189b3a 2022-08-13 op if ! shift 2>&1 >/dev/null; then
179 80189b3a 2022-08-13 op echo "$0: missing value for --prefix" >&2
186 80189b3a 2022-08-13 op if [ "$1" = "$key" ]; then
187 80189b3a 2022-08-13 op echo "$0: invalid key-value: $1" >&2
193 80189b3a 2022-08-13 op case "$key" in
195 80189b3a 2022-08-13 op LDADD="$val" ;;
196 80189b3a 2022-08-13 op LDADD_LIBEVENT)
197 80189b3a 2022-08-13 op LDADD_LIBEVENT="$val" ;;
198 80189b3a 2022-08-13 op LDADD_LIBEVENT2)
199 80189b3a 2022-08-13 op LDADD_LIBEVENT2="$val" ;;
200 80189b3a 2022-08-13 op LDADD_LIB_SOCKET)
201 80189b3a 2022-08-13 op LDADD_LIB_SOCKET="$val" ;;
203 80189b3a 2022-08-13 op LDFLAGS="$val" ;;
205 80189b3a 2022-08-13 op CPPFLAGS="$val" ;;
207 80189b3a 2022-08-13 op DESTDIR="$val" ;;
209 80189b3a 2022-08-13 op PREFIX="$val" ;;
211 80189b3a 2022-08-13 op MANDIR="$val" ;;
213 80189b3a 2022-08-13 op LIBDIR="$val" ;;
215 80189b3a 2022-08-13 op BINDIR="$val" ;;
217 80189b3a 2022-08-13 op SHAREDIR="$val" ;;
219 80189b3a 2022-08-13 op SBINDIR="$val" ;;
221 80189b3a 2022-08-13 op INCLUDEDIR="$val" ;;
223 80189b3a 2022-08-13 op PKG_CONFIG="$val" ;;
225 80189b3a 2022-08-13 op echo "$0: invalid key: $key" 1>&2
230 80189b3a 2022-08-13 op test -z "${PKG_CONFIG}" && {
231 80189b3a 2022-08-13 op PKG_CONFIG="$(command -v pkg-config)" 2>/dev/null && {
232 80189b3a 2022-08-13 op echo "found pkg-config: $PKG_CONFIG" 1>&2
233 80189b3a 2022-08-13 op echo "found pkg-config: $PKG_CONFIG" 1>&3
235 80189b3a 2022-08-13 op PKG_CONFIG=false
236 80189b3a 2022-08-13 op echo "pkg-config not found: $PKG_CONFIG" 1>&2
237 80189b3a 2022-08-13 op echo "pkg-config not found: $PKG_CONFIG" 1>&3
242 80189b3a 2022-08-13 op #----------------------------------------------------------------------
243 80189b3a 2022-08-13 op # These are the values that will be pushed into config.h after we test
244 80189b3a 2022-08-13 op # for whether they're supported or not.
245 80189b3a 2022-08-13 op # Each of these must have a runtest(), below.
246 80189b3a 2022-08-13 op # Please sort by alpha, for clarity.
247 80189b3a 2022-08-13 op # You WANT to change this.
248 80189b3a 2022-08-13 op #----------------------------------------------------------------------
250 80189b3a 2022-08-13 op HAVE_ENDIAN_H=
252 80189b3a 2022-08-13 op HAVE_GETDTABLECOUNT=
253 80189b3a 2022-08-13 op HAVE_GETEXECNAME=
254 80189b3a 2022-08-13 op HAVE_GETPROGNAME=
255 80189b3a 2022-08-13 op HAVE_OSBYTEORDER_H=
256 80189b3a 2022-08-13 op HAVE_PATH_MAX=
258 80189b3a 2022-08-13 op HAVE_PROGRAM_INVOCATION_SHORT_NAME=
259 80189b3a 2022-08-13 op HAVE_SETRESGID=
260 80189b3a 2022-08-13 op HAVE_SETRESUID=
261 80189b3a 2022-08-13 op HAVE_SOCK_NONBLOCK=
262 80189b3a 2022-08-13 op HAVE_STRLCAT=
263 80189b3a 2022-08-13 op HAVE_STRLCPY=
264 80189b3a 2022-08-13 op HAVE_STRTONUM=
265 80189b3a 2022-08-13 op HAVE_SYS_BYTEORDER_H=
266 80189b3a 2022-08-13 op HAVE_SYS_ENDIAN_H=
267 80189b3a 2022-08-13 op HAVE_SYS_QUEUE=
268 80189b3a 2022-08-13 op HAVE_WAIT_ANY=
269 80189b3a 2022-08-13 op HAVE___PROGNAME=
271 80189b3a 2022-08-13 op #----------------------------------------------------------------------
272 80189b3a 2022-08-13 op # Allow configure.local to override all variables, default settings,
273 80189b3a 2022-08-13 op # command-line arguments, and tested features, above.
274 80189b3a 2022-08-13 op # You PROBABLY DO NOT want to change this.
275 80189b3a 2022-08-13 op #----------------------------------------------------------------------
277 80189b3a 2022-08-13 op if [ -r ./configure.local ]; then
278 80189b3a 2022-08-13 op echo "configure.local: reading..." 1>&2
279 80189b3a 2022-08-13 op echo "configure.local: reading..." 1>&3
280 80189b3a 2022-08-13 op cat ./configure.local 1>&3
281 80189b3a 2022-08-13 op . ./configure.local
283 80189b3a 2022-08-13 op echo "configure.local: no (fully automatic configuration)" 1>&2
284 80189b3a 2022-08-13 op echo "configure.local: no (fully automatic configuration)" 1>&3
289 80189b3a 2022-08-13 op #----------------------------------------------------------------------
290 80189b3a 2022-08-13 op # Infrastructure for running tests.
291 80189b3a 2022-08-13 op # These consists of a series of functions that will attempt to run the
292 80189b3a 2022-08-13 op # given test file and record its exit into a HAVE_xxx variable.
293 80189b3a 2022-08-13 op # You DO NOT want to change this.
294 80189b3a 2022-08-13 op #----------------------------------------------------------------------
296 80189b3a 2022-08-13 op COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror"
298 80189b3a 2022-08-13 op # Check whether this HAVE_ setting is manually overridden.
299 80189b3a 2022-08-13 op # If yes, use the override, if no, do not decide anything yet.
300 80189b3a 2022-08-13 op # Arguments: lower-case test name, manual value
303 80189b3a 2022-08-13 op [ -z "${3}" ] && return 1
304 80189b3a 2022-08-13 op echo "${1}: manual (HAVE_${2}=${3})" 1>&2
305 80189b3a 2022-08-13 op echo "${1}: manual (HAVE_${2}=${3})" 1>&3
310 80189b3a 2022-08-13 op # Run a single autoconfiguration test.
311 80189b3a 2022-08-13 op # In case of success, enable the feature.
312 80189b3a 2022-08-13 op # In case of failure, do not decide anything yet.
313 80189b3a 2022-08-13 op # Arguments: lower-case test name, upper-case test name, additional
314 80189b3a 2022-08-13 op # CFLAGS, additional LIBS.
316 80189b3a 2022-08-13 op singletest() {
318 80189b3a 2022-08-13 op cat 1>&3 << __HEREDOC__
319 80189b3a 2022-08-13 op ${1}: testing...
320 80189b3a 2022-08-13 op ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${4}
322 80189b3a 2022-08-13 op if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${4} 1>&3 2>&3; then
323 80189b3a 2022-08-13 op echo "${1}: ${CC} succeeded" 1>&3
325 80189b3a 2022-08-13 op if [ -n "${5}" ] ; then
326 80189b3a 2022-08-13 op echo "${1}: ${CC} failed with $? (retrying)" 1>&3
327 80189b3a 2022-08-13 op cat 1>&3 << __HEREDOC__
328 80189b3a 2022-08-13 op ${1}: testing...
329 80189b3a 2022-08-13 op ${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${LDFLAGS} ${5}
331 80189b3a 2022-08-13 op if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${LDFLAGS} ${5} 1>&3 2>&3; then
332 80189b3a 2022-08-13 op echo "${1}: ${CC} succeeded" 1>&3
333 80189b3a 2022-08-13 op extralib="(with ${5})"
335 80189b3a 2022-08-13 op test -n "${6}" && ${PKG_CONFIG} "${6}"
336 80189b3a 2022-08-13 op if [ $? -eq 0 ]; then
337 80189b3a 2022-08-13 op echo "${1}: ${CC} failed with $? (retrying)" 1>&3
338 80189b3a 2022-08-13 op pkgcfs="$($PKG_CONFIG --cflags "$6")"
339 80189b3a 2022-08-13 op pkglib="$($PKG_CONFIG --libs "$6")"
340 80189b3a 2022-08-13 op cat 1>&3 <<EOF
341 80189b3a 2022-08-13 op ${1}: testing...
342 80189b3a 2022-08-13 op ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib}
344 80189b3a 2022-08-13 op if ${COMP} -DTEST_${2} ${3} ${pkgcfs} -o test-${1} tests.c ${LDFLAGS} ${pkglib} 1>&3 2>&3; then
345 80189b3a 2022-08-13 op echo "${1}: ${CC} succeeded" 1>&3
346 80189b3a 2022-08-13 op extralib="(with ${pkgcfs} ${pkglib})"
348 80189b3a 2022-08-13 op echo "${1}: ${CC} failed with $?" 1>&3
353 80189b3a 2022-08-13 op echo "${1}: ${CC} failed with $?" 1>&3
359 80189b3a 2022-08-13 op echo "${1}: ${CC} failed with $?" 1>&3
365 80189b3a 2022-08-13 op if [ -n "${pkgcfs}" -o -n "${pkglib}" ]
367 80189b3a 2022-08-13 op CFLAGS="${CFLAGS} ${pkgcfs}"
368 80189b3a 2022-08-13 op eval "LDADD_${2}=\"${pkglib}\""
369 80189b3a 2022-08-13 op elif [ -n "${extralib}" ]
371 80189b3a 2022-08-13 op eval "LDADD_${2}=\"${5}\""
372 80189b3a 2022-08-13 op elif [ -n "${4}" ]
374 80189b3a 2022-08-13 op eval "LDADD_${2}=\"${4}\""
377 80189b3a 2022-08-13 op echo "${1}: yes ${extralib}" 1>&2
378 80189b3a 2022-08-13 op echo "${1}: yes ${extralib}" 1>&3
380 80189b3a 2022-08-13 op eval HAVE_${2}=1
381 80189b3a 2022-08-13 op rm "test-${1}"
385 80189b3a 2022-08-13 op # Run a complete autoconfiguration test, including the check for
386 80189b3a 2022-08-13 op # a manual override and disabling the feature on failure.
387 80189b3a 2022-08-13 op # Arguments: lower case name, upper case name, additional CFLAGS,
388 80189b3a 2022-08-13 op # additional LDADD, alternative LDADD, pkg-config name.
391 80189b3a 2022-08-13 op eval _manual=\${HAVE_${2}}
392 80189b3a 2022-08-13 op ismanual "${1}" "${2}" "${_manual}" && return 0
393 80189b3a 2022-08-13 op singletest "${1}" "${2}" "${3}" "${4}" "${5}" && return 0
394 80189b3a 2022-08-13 op echo "${1}: no" 1>&2
395 80189b3a 2022-08-13 op eval HAVE_${2}=0
399 80189b3a 2022-08-13 op #----------------------------------------------------------------------
400 80189b3a 2022-08-13 op # Begin running the tests themselves.
401 80189b3a 2022-08-13 op # All of your tests must be defined here.
402 80189b3a 2022-08-13 op # Please sort as the HAVE_xxxx values were defined.
403 80189b3a 2022-08-13 op # You WANT to change this.
404 80189b3a 2022-08-13 op # It consists of the following columns:
406 80189b3a 2022-08-13 op # (1) test file
407 80189b3a 2022-08-13 op # (2) macro to set
408 80189b3a 2022-08-13 op # (3) argument to cc *before* -o
409 80189b3a 2022-08-13 op # (4) argument to cc *after*
410 80189b3a 2022-08-13 op # (5) alternative argument to cc *after*
411 80189b3a 2022-08-13 op #----------------------------------------------------------------------
413 80189b3a 2022-08-13 op runtest endian_h ENDIAN_H || true
414 80189b3a 2022-08-13 op runtest err ERR || true
415 80189b3a 2022-08-13 op runtest getdtablecount GETDTABLECOUNT || true
416 80189b3a 2022-08-13 op runtest getexecname GETEXECNAME || true
417 80189b3a 2022-08-13 op runtest getprogname GETPROGNAME || true
419 80189b3a 2022-08-13 op runtest libevent LIBEVENT "" "" "-levent" || \
420 80189b3a 2022-08-13 op runtest libevent2 LIBEVENT2 "" "" "-levent_extra -levent_core" "libevent" || true
422 80189b3a 2022-08-13 op runtest lib_socket LIB_SOCKET "" "" "-lsocket -lnsl" || true
423 80189b3a 2022-08-13 op runtest osbyteorder_h OSBYTEORDER_H || true
424 80189b3a 2022-08-13 op runtest PATH_MAX PATH_MAX || true
425 80189b3a 2022-08-13 op runtest pledge PLEDGE || true
426 80189b3a 2022-08-13 op runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true
427 80189b3a 2022-08-13 op runtest setresgid SETRESGID || true
428 80189b3a 2022-08-13 op runtest setresuid SETRESUID || true
429 80189b3a 2022-08-13 op runtest SOCK_NONBLOCK SOCK_NONBLOCK || true
430 80189b3a 2022-08-13 op runtest static STATIC "" "-static" || true
431 80189b3a 2022-08-13 op runtest strlcat STRLCAT || true
432 80189b3a 2022-08-13 op runtest strlcpy STRLCPY || true
433 80189b3a 2022-08-13 op runtest strtonum STRTONUM || true
434 80189b3a 2022-08-13 op runtest sys_byteorder_h SYS_BYTEORDER_H || true
435 80189b3a 2022-08-13 op runtest sys_endian_h SYS_ENDIAN_H || true
436 80189b3a 2022-08-13 op runtest sys_queue SYS_QUEUE || true
437 80189b3a 2022-08-13 op runtest WAIT_ANY WAIT_ANY || true
438 80189b3a 2022-08-13 op runtest __progname __PROGNAME || true
440 80189b3a 2022-08-13 op if [ "${HAVE_LIBEVENT}" -eq 0 -a "${HAVE_LIBEVENT2:-0}" -eq 0 ]; then
441 80189b3a 2022-08-13 op echo "Fatal: missing libevent" 1>&2
442 80189b3a 2022-08-13 op echo "Fatal: missing libevent" 1>&3
446 80189b3a 2022-08-13 op #----------------------------------------------------------------------
447 80189b3a 2022-08-13 op # Output writing: generate the config.h file.
448 80189b3a 2022-08-13 op # This file contains all of the HAVE_xxxx variables necessary for
449 80189b3a 2022-08-13 op # compiling your source.
450 80189b3a 2022-08-13 op # You must include "config.h" BEFORE any other variables.
451 80189b3a 2022-08-13 op # You WANT to change this.
452 80189b3a 2022-08-13 op #----------------------------------------------------------------------
454 80189b3a 2022-08-13 op exec > config.h
456 80189b3a 2022-08-13 op # Start with prologue.
458 80189b3a 2022-08-13 op cat << __HEREDOC__
459 80189b3a 2022-08-13 op #ifndef OCONFIGURE_CONFIG_H
460 80189b3a 2022-08-13 op #define OCONFIGURE_CONFIG_H
462 80189b3a 2022-08-13 op #ifdef __cplusplus
463 80189b3a 2022-08-13 op # error "Do not use C++: this is a C application."
465 80189b3a 2022-08-13 op #if !defined(__GNUC__) || (__GNUC__ < 4)
466 80189b3a 2022-08-13 op # define __attribute__(x)
468 80189b3a 2022-08-13 op #if defined(__linux__) || defined(__MINT__)
469 80189b3a 2022-08-13 op # define _GNU_SOURCE /* memmem, memrchr, setresuid... */
470 80189b3a 2022-08-13 op # define _DEFAULT_SOURCE /* le32toh, crypt, ... */
472 80189b3a 2022-08-13 op #if defined(__NetBSD__)
473 80189b3a 2022-08-13 op # define _OPENBSD_SOURCE /* reallocarray, etc. */
475 80189b3a 2022-08-13 op #if defined(__sun)
476 80189b3a 2022-08-13 op # ifndef _XOPEN_SOURCE /* SunOS already defines */
477 80189b3a 2022-08-13 op # define _XOPEN_SOURCE /* XPGx */
479 80189b3a 2022-08-13 op # define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
480 80189b3a 2022-08-13 op # ifndef __EXTENSIONS__ /* SunOS already defines */
481 80189b3a 2022-08-13 op # define __EXTENSIONS__ /* reallocarray, etc. */
484 80189b3a 2022-08-13 op #if !defined(__BEGIN_DECLS)
485 80189b3a 2022-08-13 op # define __BEGIN_DECLS
487 80189b3a 2022-08-13 op #if !defined(__END_DECLS)
488 80189b3a 2022-08-13 op # define __END_DECLS
493 80189b3a 2022-08-13 op # This is just for size_t, mode_t, and dev_t.
494 80189b3a 2022-08-13 op # Most of these functions, in the real world, pull in <string.h> or
495 80189b3a 2022-08-13 op # someting that pulls in support for size_t.
496 80189b3a 2022-08-13 op # Our function declarations are standalone, so specify them here.
498 80189b3a 2022-08-13 op if [ ${HAVE_SETRESGID} -eq 0 -o \
499 80189b3a 2022-08-13 op ${HAVE_SETRESUID} -eq 0 -o \
500 80189b3a 2022-08-13 op ${HAVE_STRLCAT} -eq 0 -o \
501 80189b3a 2022-08-13 op ${HAVE_STRLCPY} -eq 0 ]
503 80189b3a 2022-08-13 op echo "#include <sys/types.h> /* size_t, mode_t, dev_t */ "
507 80189b3a 2022-08-13 op if [ ${HAVE_SYS_QUEUE} -eq 1 ]
509 80189b3a 2022-08-13 op echo "#include <sys/queue.h>"
513 80189b3a 2022-08-13 op if [ ${HAVE_ERR} -eq 1 ]
515 80189b3a 2022-08-13 op echo "#include <err.h> /* err(3) */"
519 80189b3a 2022-08-13 op if [ ${HAVE_LIBEVENT2:-0} -eq 1 ]; then
521 80189b3a 2022-08-13 op #include <event2/event.h>
522 80189b3a 2022-08-13 op #include <event2/event_compat.h>
523 80189b3a 2022-08-13 op #include <event2/event_struct.h>
524 80189b3a 2022-08-13 op #include <event2/buffer.h>
525 80189b3a 2022-08-13 op #include <event2/buffer_compat.h>
526 80189b3a 2022-08-13 op #include <event2/bufferevent.h>
527 80189b3a 2022-08-13 op #include <event2/bufferevent_struct.h>
528 80189b3a 2022-08-13 op #include <event2/bufferevent_compat.h>
533 80189b3a 2022-08-13 op if [ ${HAVE_LIBEVENT} -eq 1 ]; then
535 80189b3a 2022-08-13 op #include <event.h>
540 80189b3a 2022-08-13 op # Now we handle our HAVE_xxxx values.
541 80189b3a 2022-08-13 op # Most will just be defined as 0 or 1.
543 80189b3a 2022-08-13 op if [ ${HAVE_PATH_MAX} -eq 0 ]
545 80189b3a 2022-08-13 op echo "#define PATH_MAX 4096"
549 80189b3a 2022-08-13 op if [ ${HAVE_WAIT_ANY} -eq 0 ]
551 80189b3a 2022-08-13 op echo "#define WAIT_ANY (-1) /* sys/wait.h */"
552 80189b3a 2022-08-13 op echo "#define WAIT_MYPGRP 0"
557 80189b3a 2022-08-13 op cat << __HEREDOC__
559 80189b3a 2022-08-13 op * Results of configuration feature-testing.
561 80189b3a 2022-08-13 op #define HAVE_ENDIAN_H ${HAVE_ENDIAN_H}
562 80189b3a 2022-08-13 op #define HAVE_ERR ${HAVE_ERR}
563 80189b3a 2022-08-13 op #define HAVE_GETDTABLECOUNT ${HAVE_GETDTABLECOUNT}
564 80189b3a 2022-08-13 op #define HAVE_GETEXECNAME ${HAVE_GETEXECNAME}
565 80189b3a 2022-08-13 op #define HAVE_GETPROGNAME ${HAVE_GETPROGNAME}
566 80189b3a 2022-08-13 op #define HAVE_OSBYTEORDER_H ${HAVE_OSBYTEORDER_H}
567 80189b3a 2022-08-13 op #define HAVE_PATH_MAX ${HAVE_PATH_MAX}
568 80189b3a 2022-08-13 op #define HAVE_PLEDGE ${HAVE_PLEDGE}
569 80189b3a 2022-08-13 op #define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME}
570 80189b3a 2022-08-13 op #define HAVE_SETRESGID ${HAVE_SETRESGID}
571 80189b3a 2022-08-13 op #define HAVE_SETRESUID ${HAVE_SETRESUID}
572 80189b3a 2022-08-13 op #define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK}
573 80189b3a 2022-08-13 op #define HAVE_STRLCAT ${HAVE_STRLCAT}
574 80189b3a 2022-08-13 op #define HAVE_STRLCPY ${HAVE_STRLCPY}
575 80189b3a 2022-08-13 op #define HAVE_STRTONUM ${HAVE_STRTONUM}
576 80189b3a 2022-08-13 op #define HAVE_SYS_BYTEORDER_H ${HAVE_SYS_BYTEORDER_H}
577 80189b3a 2022-08-13 op #define HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H}
578 80189b3a 2022-08-13 op #define HAVE_SYS_QUEUE ${HAVE_SYS_QUEUE}
579 80189b3a 2022-08-13 op #define HAVE_WAIT_ANY ${HAVE_WAIT_ANY}
580 80189b3a 2022-08-13 op #define HAVE___PROGNAME ${HAVE___PROGNAME}
584 80189b3a 2022-08-13 op # Compat for libkern/OSByteOrder.h in place of endian.h.
586 80189b3a 2022-08-13 op [ ${HAVE_OSBYTEORDER_H} -eq 1 -a \
587 80189b3a 2022-08-13 op ${HAVE_ENDIAN_H} -eq 0 -a \
588 80189b3a 2022-08-13 op ${HAVE_SYS_BYTEORDER_H} -eq 0 -a \
589 80189b3a 2022-08-13 op ${HAVE_SYS_ENDIAN_H} -eq 0 ] \
590 80189b3a 2022-08-13 op && cat << __HEREDOC__
592 80189b3a 2022-08-13 op * endian.h compatibility with libkern/OSByteOrder.h.
594 80189b3a 2022-08-13 op #define htobe16(x) OSSwapHostToBigInt16(x)
595 80189b3a 2022-08-13 op #define htole16(x) OSSwapHostToLittleInt16(x)
596 80189b3a 2022-08-13 op #define be16toh(x) OSSwapBigToHostInt16(x)
597 80189b3a 2022-08-13 op #define le16toh(x) OSSwapLittleToHostInt16(x)
598 80189b3a 2022-08-13 op #define htobe32(x) OSSwapHostToBigInt32(x)
599 80189b3a 2022-08-13 op #define htole32(x) OSSwapHostToLittleInt32(x)
600 80189b3a 2022-08-13 op #define be32toh(x) OSSwapBigToHostInt32(x)
601 80189b3a 2022-08-13 op #define le32toh(x) OSSwapLittleToHostInt32(x)
602 80189b3a 2022-08-13 op #define htobe64(x) OSSwapHostToBigInt64(x)
603 80189b3a 2022-08-13 op #define htole64(x) OSSwapHostToLittleInt64(x)
604 80189b3a 2022-08-13 op #define be64toh(x) OSSwapBigToHostInt64(x)
605 80189b3a 2022-08-13 op #define le64toh(x) OSSwapLittleToHostInt64(x)
609 80189b3a 2022-08-13 op [ ${HAVE_SYS_BYTEORDER_H} -eq 1 -a \
610 80189b3a 2022-08-13 op ${HAVE_ENDIAN_H} -eq 0 -a \
611 80189b3a 2022-08-13 op ${HAVE_OSBYTEORDER_H} -eq 0 -a \
612 80189b3a 2022-08-13 op ${HAVE_SYS_ENDIAN_H} -eq 0 ] \
613 80189b3a 2022-08-13 op && cat << __HEREDOC__
615 80189b3a 2022-08-13 op * endian.h compatibility with sys/byteorder.h.
617 80189b3a 2022-08-13 op #define htobe16(x) BE_16(x)
618 80189b3a 2022-08-13 op #define htole16(x) LE_16(x)
619 80189b3a 2022-08-13 op #define be16toh(x) BE_16(x)
620 80189b3a 2022-08-13 op #define le16toh(x) LE_16(x)
621 80189b3a 2022-08-13 op #define htobe32(x) BE_32(x)
622 80189b3a 2022-08-13 op #define htole32(x) LE_32(x)
623 80189b3a 2022-08-13 op #define be32toh(x) BE_32(x)
624 80189b3a 2022-08-13 op #define le32toh(x) LE_32(x)
625 80189b3a 2022-08-13 op #define htobe64(x) BE_64(x)
626 80189b3a 2022-08-13 op #define htole64(x) LE_64(x)
627 80189b3a 2022-08-13 op #define be64toh(x) BE_64(x)
628 80189b3a 2022-08-13 op #define le64toh(x) LE_64(x)
632 80189b3a 2022-08-13 op # Make endian.h easier by providing a COMPAT_ENDIAN_H.
634 80189b3a 2022-08-13 op cat << __HEREDOC__
636 80189b3a 2022-08-13 op * Make it easier to include endian.h forms.
638 80189b3a 2022-08-13 op #if HAVE_ENDIAN_H
639 80189b3a 2022-08-13 op # define COMPAT_ENDIAN_H <endian.h>
640 80189b3a 2022-08-13 op #elif HAVE_SYS_ENDIAN_H
641 80189b3a 2022-08-13 op # define COMPAT_ENDIAN_H <sys/endian.h>
642 80189b3a 2022-08-13 op #elif HAVE_OSBYTEORDER_H
643 80189b3a 2022-08-13 op # define COMPAT_ENDIAN_H <libkern/OSByteOrder.h>
644 80189b3a 2022-08-13 op #elif HAVE_SYS_BYTEORDER_H
645 80189b3a 2022-08-13 op # define COMPAT_ENDIAN_H <sys/byteorder.h>
647 80189b3a 2022-08-13 op # warning No suitable endian.h could be found.
648 80189b3a 2022-08-13 op # warning Please e-mail the maintainers with your OS.
649 80189b3a 2022-08-13 op # define COMPAT_ENDIAN_H <endian.h>
654 80189b3a 2022-08-13 op # Now we do our function declarations for missing functions.
656 80189b3a 2022-08-13 op [ ${HAVE_ERR} -eq 0 ] && \
657 80189b3a 2022-08-13 op cat << __HEREDOC__
659 80189b3a 2022-08-13 op * Compatibility functions for err(3).
661 80189b3a 2022-08-13 op extern void err(int, const char *, ...) __attribute__((noreturn));
662 80189b3a 2022-08-13 op extern void errc(int, int, const char *, ...) __attribute__((noreturn));
663 80189b3a 2022-08-13 op extern void errx(int, const char *, ...) __attribute__((noreturn));
664 80189b3a 2022-08-13 op extern void verr(int, const char *, va_list) __attribute__((noreturn));
665 80189b3a 2022-08-13 op extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
666 80189b3a 2022-08-13 op extern void verrx(int, const char *, va_list) __attribute__((noreturn));
667 80189b3a 2022-08-13 op extern void warn(const char *, ...);
668 80189b3a 2022-08-13 op extern void warnx(const char *, ...);
669 80189b3a 2022-08-13 op extern void warnc(int, const char *, ...);
670 80189b3a 2022-08-13 op extern void vwarn(const char *, va_list);
671 80189b3a 2022-08-13 op extern void vwarnc(int, const char *, va_list);
672 80189b3a 2022-08-13 op extern void vwarnx(const char *, va_list);
675 80189b3a 2022-08-13 op [ ${HAVE_GETDTABLECOUNT} -eq 0 ] && \
676 80189b3a 2022-08-13 op cat << __HEREDOC__
678 80189b3a 2022-08-13 op * Compatibility for getdtablecount(2).
680 80189b3a 2022-08-13 op /* on linux could be implemented by looking in /proc/self/fd */
681 80189b3a 2022-08-13 op #define getdtablecount() (0)
685 80189b3a 2022-08-13 op [ ${HAVE_GETPROGNAME} -eq 0 ] && \
686 80189b3a 2022-08-13 op cat << __HEREDOC__
688 80189b3a 2022-08-13 op * Compatibility for getprogname(3).
690 80189b3a 2022-08-13 op extern const char *getprogname(void);
694 80189b3a 2022-08-13 op [ ${HAVE_PLEDGE} -eq 0 ] && \
695 80189b3a 2022-08-13 op cat << __HEREDOC__
697 80189b3a 2022-08-13 op * Compatibility for pledge(2).
699 80189b3a 2022-08-13 op #define pledge(p, e) (0)
703 80189b3a 2022-08-13 op [ ${HAVE_STRLCAT} -eq 0 ] && \
704 80189b3a 2022-08-13 op cat << __HEREDOC__
706 80189b3a 2022-08-13 op * Compatibility for strlcat(3).
708 80189b3a 2022-08-13 op extern size_t strlcat(char *, const char *, size_t);
712 80189b3a 2022-08-13 op [ ${HAVE_STRLCPY} -eq 0 ] && \
713 80189b3a 2022-08-13 op cat << __HEREDOC__
715 80189b3a 2022-08-13 op * Compatibility for strlcpy(3).
717 80189b3a 2022-08-13 op extern size_t strlcpy(char *, const char *, size_t);
721 80189b3a 2022-08-13 op [ ${HAVE_STRTONUM} -eq 0 ] && \
722 80189b3a 2022-08-13 op cat << __HEREDOC__
724 80189b3a 2022-08-13 op * Compatibility for strotnum(3).
726 80189b3a 2022-08-13 op extern long long strtonum(const char *, long long, long long, const char **);
730 80189b3a 2022-08-13 op [ ${HAVE_SETRESGID} -eq 0 ] && \
731 80189b3a 2022-08-13 op cat << __HEREDOC__
733 80189b3a 2022-08-13 op * Compatibility for setresgid(2).
735 80189b3a 2022-08-13 op int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
739 80189b3a 2022-08-13 op [ ${HAVE_SETRESUID} -eq 0 ] && \
740 80189b3a 2022-08-13 op cat << __HEREDOC__
742 80189b3a 2022-08-13 op * Compatibility for setresuid(2).
744 80189b3a 2022-08-13 op int setresuid(uid_t ruid, uid_t euid, uid_t suid);
748 80189b3a 2022-08-13 op [ ${HAVE_SYS_QUEUE} -eq 0 ] && \
749 80189b3a 2022-08-13 op cat << __HEREDOC__
750 80189b3a 2022-08-13 op #include "queue.h"
754 80189b3a 2022-08-13 op cat << __HEREDOC__
755 80189b3a 2022-08-13 op #ifndef __dead
756 80189b3a 2022-08-13 op #define __dead __attribute__((noreturn))
759 80189b3a 2022-08-13 op #ifndef __packed
760 80189b3a 2022-08-13 op #define __packed __attribute__((packed))
763 80189b3a 2022-08-13 op #endif /*!OCONFIGURE_CONFIG_H*/
766 80189b3a 2022-08-13 op echo "config.h: written" 1>&2
767 80189b3a 2022-08-13 op echo "config.h: written" 1>&3
769 80189b3a 2022-08-13 op #----------------------------------------------------------------------
770 80189b3a 2022-08-13 op # Now we go to generate our Makefile.configure.
771 80189b3a 2022-08-13 op # This file is simply a bunch of Makefile variables.
772 80189b3a 2022-08-13 op # They'll work in both GNUmakefile and BSDmakefile.
773 80189b3a 2022-08-13 op # You MIGHT want to change this.
774 80189b3a 2022-08-13 op #----------------------------------------------------------------------
776 80189b3a 2022-08-13 op exec > Makefile.configure
778 80189b3a 2022-08-13 op [ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
779 80189b3a 2022-08-13 op [ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin"
780 80189b3a 2022-08-13 op [ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include"
781 80189b3a 2022-08-13 op [ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib"
782 80189b3a 2022-08-13 op [ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man"
783 80189b3a 2022-08-13 op [ -z "${SHAREDIR}" ] && SHAREDIR="${PREFIX}/share"
785 80189b3a 2022-08-13 op [ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
786 80189b3a 2022-08-13 op [ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444"
787 80189b3a 2022-08-13 op [ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444"
788 80189b3a 2022-08-13 op [ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444"
790 80189b3a 2022-08-13 op cat << __HEREDOC__
792 80189b3a 2022-08-13 op CFLAGS = ${CFLAGS}
793 80189b3a 2022-08-13 op CPPFLAGS = ${CPPFLAGS}
794 80189b3a 2022-08-13 op LDADD = ${LDADD} ${LDADD_LIB_SOCKET} ${LDADD_LIBEVENT} ${LDADD_LIBEVENT2}
795 80189b3a 2022-08-13 op LDADD_STATIC = ${LDADD_STATIC}
796 80189b3a 2022-08-13 op LDFLAGS = ${LDFLAGS}
797 80189b3a 2022-08-13 op STATIC = ${STATIC}
798 80189b3a 2022-08-13 op PREFIX = ${PREFIX}
799 80189b3a 2022-08-13 op BINDIR = ${BINDIR}
800 80189b3a 2022-08-13 op SHAREDIR = ${SHAREDIR}
801 80189b3a 2022-08-13 op SBINDIR = ${SBINDIR}
802 80189b3a 2022-08-13 op INCLUDEDIR = ${INCLUDEDIR}
803 80189b3a 2022-08-13 op LIBDIR = ${LIBDIR}
804 80189b3a 2022-08-13 op MANDIR = ${MANDIR}
805 80189b3a 2022-08-13 op INSTALL = ${INSTALL}
806 80189b3a 2022-08-13 op INSTALL_PROGRAM = ${INSTALL_PROGRAM}
807 80189b3a 2022-08-13 op INSTALL_LIB = ${INSTALL_LIB}
808 80189b3a 2022-08-13 op INSTALL_MAN = ${INSTALL_MAN}
809 80189b3a 2022-08-13 op INSTALL_DATA = ${INSTALL_DATA}
812 80189b3a 2022-08-13 op echo "Makefile.configure: written" 1>&2
813 80189b3a 2022-08-13 op echo "Makefile.configure: written" 1>&3