Blob


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