diff --git a/configure b/configure index fa391f2..6e8660d 100755 --- a/configure +++ b/configure @@ -4,19 +4,22 @@ OS=`uname -s` DEBUG=0 PREFIX=/usr/local -create_generic_config_h() { - cat < src/config.h -#ifndef _CONFIG_H -#define _CONFIG_H +config_h_append_generic_endian() { + cat <> "$1" + +/* + * Generic compatibility + */ #include -#endif /* _CONFIG_H */ EOF } -create_darwin_config_h() { - cat < src/config.h -#ifndef _CONFIG_H -#define _CONFIG_H +config_h_append_darwin_endian() { + cat <> "$1" + +/* + * Darwin compatibility + */ #include #define htobe16(n) OSSwapHostToBigInt16(n) @@ -33,32 +36,55 @@ create_darwin_config_h() { #define htole64(n) OSSwapHostToLittleInt64(n) #define be64toh(n) OSSwapBigToHostInt64(n) #define le64toh(n) OSSwapLittleToHostInt64(n) +EOF +} + +config_h_append_bsd_pty() { + cat <> "$1" + +/* + * BSD openpty(3) compatibility + */ +#include +EOF +} + +config_h_append_linux_pty() { + cat <> "$1" + +/* + * Linux openpty(3) compatibility + */ +#include +EOF +} + +config_h_create() { + cat < "$1" +#ifndef _CONFIG_H +#define _CONFIG_H +EOF + + if [ "$OS" = "Darwin" ]; then + config_h_append_darwin_endian "$1" + else + config_h_append_generic_endian "$1" + fi + + if [ "$OS" = "Linux" ]; then + config_h_append_linux_pty "$1" + else + config_h_append_bsd_pty "$1" + fi + + cat <> "$1" + #endif /* _CONFIG_H */ EOF } -create_common_build_mk() { - if [ "$DEBUG" = 1 ]; then - cat <<'EOF' > mk/build.mk -CGFLAGS = -g -fno-inline -EOF - else - cat <<'EOF' > mk/build.mk -CGFLAGS = -EOF - fi - - cat <<'EOF' >> mk/build.mk -CWFLAGS = -Wall -COFLAGS = -O2 -CFLAGS = $(CGFLAGS) $(CWFLAGS) $(COFLAGS) -EOF -} - -create_generic_build_mk() { - create_common_build_mk $@ - - cat <<'EOF' >> mk/build.mk +build_mk_append_generic() { + cat <<'EOF' >> "$1" LLFLAGS = -shared -Wl,-soname=$(SONAME) STATIC = lib$(LIBNAME).a @@ -74,8 +100,8 @@ PREFIX = $PREFIX EOF } -create_darwin_build_mk() { - create_common_build_mk $@ +build_mk_append_darwin() { + build_mk_create_common $@ cat <<'EOF' >> mk/build.mk LLFLAGS = -dynamiclib -current_version $(VERSION) @@ -93,6 +119,30 @@ PREFIX = $PREFIX EOF } +build_mk_create() { + if [ "$DEBUG" = 1 ]; then + cat <<'EOF' > "$1" +CGFLAGS = -g -fno-inline +EOF + else + cat <<'EOF' > "$1" +CGFLAGS = +EOF + fi + + if [ "$OS" = "Darwin" ]; then + build_mk_append_darwin "$1" + else + build_mk_append_generic "$1" + fi + + cat <<'EOF' >> mk/build.mk +CWFLAGS = -Wall +COFLAGS = -O2 +CFLAGS = $(CGFLAGS) $(CWFLAGS) $(COFLAGS) +EOF +} + for arg in $@; do case $arg in "--enable-debug") @@ -105,14 +155,5 @@ if [ ! -d "mk" ]; then mkdir -m 0755 mk fi -case $OS in - Darwin) - create_darwin_config_h - create_darwin_build_mk - ;; - - *) - create_generic_config_h - create_generic_build_mk - ;; -esac +config_h_create "src/config.h" +build_mk_create "src/build.mk" diff --git a/examples/daemon.c b/examples/daemon.c index 72197ba..1d29cbc 100644 --- a/examples/daemon.c +++ b/examples/daemon.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -13,6 +12,8 @@ #include #include +#include "../src/config.h" + static void usage(int argc, char **argv, const char *message, ...) { if (message != NULL) { va_list args; diff --git a/src/sock.c b/src/sock.c index bb6b974..219b6ab 100644 --- a/src/sock.c +++ b/src/sock.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,8 @@ #include +#include "config.h" + struct slot { size_t len; int ack;