From 96e2c0b590dd8cf09c91b1bbe1688de15e8e4791 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 11 Jan 2010 06:55:44 +0200 Subject: [PATCH] libusual: include into build system --- .gitmodules | 3 + Makefile | 57 +++++++++++------- config.mak.in | 4 +- configure.ac | 149 ++++++++++------------------------------------- include/system.h | 50 +--------------- include/util.h | 2 - lib | 1 + src/slab.c | 6 -- src/util.c | 8 --- 9 files changed, 74 insertions(+), 206 deletions(-) create mode 100644 .gitmodules create mode 160000 lib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1666183 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib"] + path = lib + url = git://github.com/markokr/libusual.git diff --git a/Makefile b/Makefile index 67a9966..da55a74 100644 --- a/Makefile +++ b/Makefile @@ -28,23 +28,27 @@ DIRS = doc etc include src debian test win32 srcdir ?= . builddir ?= . +local_hdrs = $(addprefix $(srcdir)/include/, $(HDRS)) +local_srcs = $(addprefix $(srcdir)/src/, $(SRCS)) + +USUAL_DIR = $(srcdir)/lib +USUAL_OBJDIR = $(builddir)/obj +USUAL_LOCAL_SRCS = $(local_srcs) $(local_hdrs) +include $(USUAL_DIR)/Setup.mk + # calculate full-path values OBJS = $(SRCS:.c=.o) -hdrs = $(addprefix $(srcdir)/include/, $(HDRS)) -srcs = $(addprefix $(srcdir)/src/, $(SRCS)) -objs = $(addprefix $(builddir)/lib/, $(OBJS)) +hdrs = $(local_hdrs) $(USUAL_HDRS) +srcs = $(local_srcs) +objs = $(addprefix $(builddir)/obj/, $(OBJS)) $(USUAL_OBJS) FULL = $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) DISTFILES = $(DIRS) $(DATA) $(DOCS) $(srcs) $(hdrs) $(MANPAGES) exe = $(builddir)/pgbouncer$(EXT) -CPPCFLAGS += -I$(srcdir)/include - -ifneq ($(builddir),$(srcdir)) -CPPCFLAGS += -I$(builddir)/include -endif +CPPFLAGS := -I$(srcdir)/include $(USUAL_CPPFLAGS) $(CPPFLAGS) ifeq ($(enable_debug),yes) -CPPCFLAGS += -DDBGVER="\"compiled by <$${USER}@`hostname`> at `date '+%Y-%m-%d %H:%M:%S'`\"" +CPPFLAGS += -DDBGVER="\"compiled by <$${USER}@`hostname`> at `date '+%Y-%m-%d %H:%M:%S'`\"" endif ifeq ($(PORTNAME),win32) @@ -57,11 +61,11 @@ WHDRS = win32support.h WOBJS = $(WSRCS:.c=.o) srcs += $(srcdir)/win32/win32support.c hdrs += $(srcdir)/win32/win32support.h -objs += $(builddir)/lib/win32support.o +objs += $(builddir)/obj/win32support.o dll = $(builddir)/pgbevent.dll -dlldef = $(builddir)/lib/pgbevent.def -dllobjs = $(builddir)/lib/eventmsg.o $(builddir)/lib/pgbevent.o +dlldef = $(builddir)/obj/pgbevent.def +dllobjs = $(builddir)/obj/eventmsg.o $(builddir)/obj/pgbevent.o DEFFLAGS = --export-all-symbols -A @@ -88,13 +92,18 @@ $(exe): $(builddir)/config.mak $(objs) $(Q) $(CC) -o $@ $(LDFLAGS) $(objs) $(LIBS) # objects depend on all the headers -$(builddir)/lib/%.o: $(srcdir)/src/%.c $(builddir)/config.mak $(hdrs) - @mkdir -p $(builddir)/lib +$(builddir)/obj/%.o: $(srcdir)/src/%.c $(builddir)/config.mak $(hdrs) + @mkdir -p $(builddir)/obj + $(E) " CC" $< + $(Q) $(CC) -c -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) + +$(builddir)/obj/%.o: $(srcdir)/win32/%.c $(builddir)/config.mak $(hdrs) + @mkdir -p $(builddir)/obj $(E) " CC" $< $(Q) $(CC) -c -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) -$(builddir)/lib/%.o: $(srcdir)/win32/%.c $(builddir)/config.mak $(hdrs) - @mkdir -p $(builddir)/lib +$(builddir)/obj/%.o: $(USUAL_DIR)/usual/%.c $(builddir)/config.mak $(hdrs) + @mkdir -p $(builddir)/obj $(E) " CC" $< $(Q) $(CC) -c -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) @@ -134,7 +143,7 @@ clean: doc-clean # clean configure results distclean: clean doc-distclean rm -f include/config.h include/config.h.in~ config.log config.status config.mak - rm -rf lib autom4te* + rm -rf obj autom4te* # clean autoconf results realclean: distclean doc-realclean @@ -143,7 +152,9 @@ realclean: distclean doc-realclean # generate configure script and config.h.in boot: - autoreconf -i -f + aclocal -I lib/m4 + autoheader -f + autoconf -f rm -rf autom4te* include/config.h.in~ # targets can depend on this to force ./configure @@ -181,8 +192,8 @@ pgbouncer.pg: pg: pgbouncer.pg # asm hacks -$(builddir)/lib/%.s: $(srcdir)/src/%.c config.mak $(hdrs) - @mkdir -p $(builddir)/lib +$(builddir)/obj/%.s: $(srcdir)/src/%.c config.mak $(hdrs) + @mkdir -p $(builddir)/obj $(E) " CC -S" $< $(Q) $(CC) -S -fverbose-asm -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) asms = $(objs:.o=.s) @@ -190,7 +201,7 @@ asm: $(asms) ifeq ($(PORTNAME),win32) -$(builddir)/lib/eventmsg.o: $(srcdir)/win32/eventmsg.rc +$(builddir)/obj/eventmsg.o: $(srcdir)/win32/eventmsg.rc $(E) " WINDRES" $< $(Q) $(WINDRES) $< -o $@ --include-dir=$(srcdir)/win32 @@ -208,3 +219,7 @@ endif stripped: $(exe) $(dll) $(STRIP) $(exe) $(dll) +tmp: + @echo CPPFLAGS=$(CPPFLAGS) + @echo USUAL_CPPFLAGS=$(USUAL_CPPFLAGS) + @echo USUAL_LDFLAGS=$(USUAL_LDFLAGS) diff --git a/config.mak.in b/config.mak.in index 15cf9fb..ddc9366 100644 --- a/config.mak.in +++ b/config.mak.in @@ -7,7 +7,7 @@ DEFS = @DEFS@ LIBS = @LIBS@ CC = @CC@ CPP = @CPP@ -CPPFLAGS = -I$(srcdir)/include @CPPFLAGS@ +CPPFLAGS = @CPPFLAGS@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ @@ -42,4 +42,4 @@ INSTALL = @INSTALL@ BININSTALL = @BININSTALL@ enable_debug = @enable_debug@ - +have_libevent = @have_libevent@ diff --git a/configure.ac b/configure.ac index 60ef8ba..08ad48d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,48 +2,14 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(pgbouncer, 1.3.3rc1) AC_CONFIG_SRCDIR(src/janitor.c) -AC_CONFIG_HEADER(include/config.h) +AC_CONFIG_HEADER(lib/usual/config.h) AC_PREREQ([2.59]) -dnl windows port check (Not use AC_CANONICAL_HOST) -AC_MSG_CHECKING([target host type]) -xhost="$host_alias" -if test "x$xhost" = "x"; then - xhost=`uname -s` -fi -case $xhost in -*cygwin* | *mingw* | *pw32* | *MINGW*) - LIBS="$LIBS -lws2_32" - PORTNAME=win32;; -*) PORTNAME=unix ;; -esac -AC_SUBST(PORTNAME) -AC_MSG_RESULT([$PORTNAME]) +dnl unix/win32 +AC_USUAL_PORT_CHECK dnl Checks for programs. -AC_PROG_CC -AC_PROG_CPP - -dnl Check if linker supports -Wl,--as-needed -dnl That helps to get rid of unnecessary -lrt -if test "$GCC" = "yes"; then - old_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS -Wl,--as-needed" - AC_MSG_CHECKING([whether linker supports --as-needed]) - AC_LINK_IFELSE([int main(void) { return 0; }], - [AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no]) - LDFLAGS="$old_LDFLAGS"]) -fi - -dnl Check if compiler supports __func__ -AC_CACHE_CHECK([whether compiler supports __func__], pgac_cv_funcname_func, - [AC_TRY_COMPILE([#include ], [printf("%s\n", __func__);], - [pgac_cv_funcname_func=yes], [pgac_cv_funcname_func=no])]) -if test x"$pgac_cv_funcname_func" = xyes ; then - AC_DEFINE(HAVE_FUNCNAME__FUNC, 1, - [Define to 1 if your compiler understands __func__.]) -fi +AC_USUAL_PROGRAM_CHECK dnl asciidoc >= 8.2 AC_CHECK_PROGS(ASCIIDOC, asciidoc) @@ -77,48 +43,13 @@ if test "$PORTNAME" = "win32"; then fi AC_CHECK_TOOL([STRIP], [strip]) -dnl Additional gcc tuning -if test x"$GCC" = xyes; then - AC_MSG_CHECKING([for working warning switches]) - good_CFLAGS="$CFLAGS" - warnings="" - flags="-Wall -Wextra" - # turn off noise from Wextra - flags="$flags -Wno-unused-parameter -Wno-missing-field-initializers" - # Wextra does not turn those on? - flags="$flags -Wmissing-prototypes -Wpointer-arith -Wendif-labels" - flags="$flags -Wdeclaration-after-statement -Wold-style-definition" - flags="$flags -Wstrict-prototypes -Wundef -Wformat -Wnonnull -Wstrict-overflow" - flags="$flags -Wformat-security -Wformat-nonliteral -Wformat-extra-args -Wformat-contains-nul" - for f in $flags; do - CFLAGS="$good_CFLAGS $warnings $f" - AC_COMPILE_IFELSE([void foo(void){}], [warnings="$warnings $f"]) - done - CFLAGS="$good_CFLAGS $warnings" - AC_MSG_RESULT([$warnings]) -fi - dnl Checks for header files. -AC_CHECK_HEADERS([crypt.h sys/param.h sys/socket.h sys/uio.h libgen.h pwd.h grp.h]) -AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/un.h arpa/inet.h]) -AC_CHECK_HEADERS([netinet/in.h netinet/tcp.h netdb.h regex.h]) - -dnl ucred.h may have prereqs -AC_CHECK_HEADERS([ucred.h sys/ucred.h], [], [], [ -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -]) +AC_USUAL_HEADER_CHECK +AC_CHECK_HEADERS([crypt.h regex.h]) +AC_CHECK_HEADERS([sys/resource.h sys/wait.h]) dnl Checks for typedefs, structures, and compiler characteristics. -AC_C_INLINE -AC_C_BIGENDIAN -AC_SYS_LARGEFILE -AC_TYPE_PID_T -AC_TYPE_SIZE_T +AC_USUAL_TYPE_CHECK dnl autoconf 2.59 does not have UINT macros nor docdir m4_ifdef([AC_TYPE_UINT8_T], [ @@ -133,22 +64,34 @@ m4_ifdef([AC_TYPE_UINT8_T], [ ]) dnl Checks for library functions. -AC_CHECK_FUNCS(strlcpy strlcat getpeereid getpeerucred basename) +AC_USUAL_FUNCTION_CHECK AC_SEARCH_LIBS(crypt, crypt) AC_SEARCH_LIBS(clock_gettime, rt) AC_SEARCH_LIBS(getsockname, socket) AC_SEARCH_LIBS(gethostbyname, nsl) AC_SEARCH_LIBS(hstrerror, resolv) AC_SEARCH_LIBS(regcomp, regex, [], AC_MSG_ERROR([regcomp not found])) -AC_CHECK_FUNCS(crypt inet_ntop lstat) +AC_CHECK_FUNCS(crypt lstat) dnl Find libevent +levent=yes AC_MSG_CHECKING([for libevent]) AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=prefix],[Specify where libevent is installed]), - [ test "$withval" = "no" && AC_MSG_ERROR("cannot work without libevent") - CPPFLAGS="$CPPFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" ]) + [ if test "$withval" = "no"; then + levent=no + else + CPPFLAGS="$CPPFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + fi + ]) + +if test "$levent" = "no"; then + AC_MSG_RESULT([using usual/event]) + AC_DEFINE(HAVE_EVENT_LOOPBREAK, 1, [usual/event.h has it.]) + have_libevent=no +else # libevent +AC_DEFINE(HAVE_LIBEVENT, 1, [Use real libevent.]) LIBS="-levent $LIBS" AC_LINK_IFELSE([ #include @@ -176,43 +119,13 @@ AC_EGREP_CPP([HTTP_SERVUNAVAIL], [AC_MSG_RESULT([yes])]) AC_CHECK_FUNCS(event_loopbreak) +have_libevent=yes +fi # libevent +AC_SUBST(have_libevent) -# autoconf does not want to find 'install', if not using automake... -INSTALL=install - -AC_ARG_ENABLE(debug, - AC_HELP_STRING([--disable-debug],[strip binary]), - [], [enable_debug=yes]) -AC_MSG_CHECKING([whether to build debug binary]) -if test "$enable_debug" = "yes"; then - LDFLAGS="-g $LDFLAGS" - BININSTALL="$INSTALL" - AC_MSG_RESULT([yes]) -else - BININSTALL="$INSTALL -s" - AC_MSG_RESULT([no]) -fi -AC_SUBST(enable_debug) -AC_SUBST(INSTALL) -AC_SUBST(BININSTALL) - -AC_ARG_ENABLE(cassert, AC_HELP_STRING([--enable-cassert],[turn on assert checking in code])) -AC_MSG_CHECKING([whether to enable asserts]) -if test "$enable_cassert" = "yes"; then - AC_DEFINE(CASSERT, 1, [Define to enable assert checking]) - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi - -AC_ARG_ENABLE(werror, AC_HELP_STRING([--enable-werror],[add -Werror to CFLAGS])) -AC_MSG_CHECKING([whether to fail on warnings]) -if test "$enable_werror" = "yes"; then - CFLAGS="$CFLAGS -Werror" - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi +AC_USUAL_DEBUG +AC_USUAL_CASSERT +AC_USUAL_WERROR if test \! "$srcdir" = "$builddir"; then CPPFLAGS="-I\$(builddir)/include $CPPFLAGS" diff --git a/include/system.h b/include/system.h index 9d42fe8..50df02b 100644 --- a/include/system.h +++ b/include/system.h @@ -20,19 +20,12 @@ * Required system headers */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include #ifdef WIN32 #include "win32support.h" #endif -/* glibc is useless without it */ -#define _GNU_SOURCE - -#include -#include #include #include @@ -57,21 +50,12 @@ #include #include -#include -#include #include -#include #include #include #include #include -#ifdef HAVE_INTTYPES_H -#include -#endif -#ifdef HAVE_STDINT_H -#include -#endif #ifdef HAVE_CRYPT_H #include #endif @@ -91,29 +75,6 @@ #define FLEX_ARRAY 1 #endif -#if defined(__GNUC__) && (__GNUC__ >= 4) - -/* gcc has hew positive aspects too */ -#define _MUSTCHECK __attribute__((warn_unused_result)) -#define _DEPRECATED __attribute__((deprecated)) -#define _PRINTF(fmtpos, argpos) __attribute__((format(printf, fmtpos, argpos))) -#define _MALLOC __attribute__((malloc)) - -/* those do not seem to work well */ -#define unlikely(x) __builtin_expect(!!(x), 0) -#define likely(x) __builtin_expect(!!(x), 1) - -#else - -#define _MUSTCHECK -#define _DEPRECATED -#define _PRINTF(x,y) -#define _MALLOC -#define unlikely(x) x -#define likely(x) x - -#endif - /* cant use assert() as we want to log too */ #ifdef CASSERT #define Assert(e) \ @@ -135,15 +96,6 @@ do { \ #define USEC (1000000LL) typedef uint64_t usec_t; - -/* - * bool type. - */ - -typedef unsigned char bool; -#define false 0 -#define true 1 - /* * PostgreSQL type OIDs for resultsets. */ diff --git a/include/util.h b/include/util.h index 850b6f1..29ca9ca 100644 --- a/include/util.h +++ b/include/util.h @@ -27,8 +27,6 @@ void reset_time_cache(void); */ char *load_file(const char *fn) _MUSTCHECK; -void *zmalloc(size_t len) _MUSTCHECK _MALLOC; - /* * generic logging */ diff --git a/lib b/lib new file mode 160000 index 0000000..b293971 --- /dev/null +++ b/lib @@ -0,0 +1 @@ +Subproject commit b29397130cb26942c05308e8c27c5aa12727256d diff --git a/src/slab.c b/src/slab.c index e62bd1d..d0ab965 100644 --- a/src/slab.c +++ b/src/slab.c @@ -27,12 +27,6 @@ #include "bouncer.h" -#define CUSTOM_ALIGN(x, a) (((unsigned long)(x) + ((a) - 1)) & ~((a) - 1)) - -#ifndef ALIGN -#define ALIGN(x) CUSTOM_ALIGN(x, sizeof(long)) -#endif - /* * Store for pre-initialized objects of one type. */ diff --git a/src/util.c b/src/util.c index eb9de5d..2815bb4 100644 --- a/src/util.c +++ b/src/util.c @@ -51,14 +51,6 @@ static struct FacName facility_names [] = { }; -void *zmalloc(size_t len) -{ - void *p = malloc(len); - if (p) - memset(p, 0, len); - return p; -} - /* * Generic logging */ -- 2.40.0