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)
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
$(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)
# 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
# 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
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)
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
stripped: $(exe) $(dll)
$(STRIP) $(exe) $(dll)
+tmp:
+ @echo CPPFLAGS=$(CPPFLAGS)
+ @echo USUAL_CPPFLAGS=$(USUAL_CPPFLAGS)
+ @echo USUAL_LDFLAGS=$(USUAL_LDFLAGS)
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)
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], [
])
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>
[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"