]> granicus.if.org Git - pgbouncer/commitdiff
libusual: include into build system
authorMarko Kreen <markokr@gmail.com>
Mon, 11 Jan 2010 04:55:44 +0000 (06:55 +0200)
committerMarko Kreen <markokr@gmail.com>
Tue, 4 May 2010 11:30:44 +0000 (14:30 +0300)
.gitmodules [new file with mode: 0644]
Makefile
config.mak.in
configure.ac
include/system.h
include/util.h
lib [new submodule]
src/slab.c
src/util.c

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..1666183
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "lib"]
+       path = lib
+       url = git://github.com/markokr/libusual.git
index 67a9966fa576b3a2956bdc086baaf6d5604a6bc8..da55a74db4aca18702d84ccbe02b846f2e6e50f7 100644 (file)
--- 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)
index 15cf9fb7231ce8510914c475d18457ab72ebc307..ddc936617743961fe9b9606cf5e0c2a10b4907cf 100644 (file)
@@ -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@
index 60ef8ba0cf4d177b22c1c12583baf64a451030e3..08ad48d53c27fb59e90e7e4ce9eb6756b258e3f8 100644 (file)
@@ -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 <stdio.h>], [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 <sys/types.h>
-#endif
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#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 <sys/types.h>
@@ -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"
index 9d42fe872331125b69bd3dedeb07764e2f94b0c0..50df02bb07804b96e74141edc3c52e98e68caddb 100644 (file)
  * Required system headers
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include <usual/base.h>
 
 #ifdef WIN32
 #include "win32support.h"
 #endif
 
-/* glibc is useless without it */
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 
 
 #include <time.h>
 #include <fcntl.h>
-#include <unistd.h>
-#include <stddef.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
 #include <limits.h>
 
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
 #endif
 #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.
  */
index 850b6f1ae2a3140d78ef5ac440754e5f1e437155..29ca9ca5d7b1189832f829429b9c145662bd3196 100644 (file)
@@ -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 (submodule)
index 0000000..b293971
--- /dev/null
+++ b/lib
@@ -0,0 +1 @@
+Subproject commit b29397130cb26942c05308e8c27c5aa12727256d
index e62bd1d43019e1e7a33b6fb34a41beaae139e265..d0ab965f0565f5fcef24aa582e5458d2f8440cee 100644 (file)
 
 #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.
  */
index eb9de5d301a31414cc0dfe78b4022f0e56a5b3af..2815bb41214cc8c7d0cb5968a45b564053ebf92c 100644 (file)
@@ -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
  */