diff --git a/.gitignore b/.gitignore index d7e48cf..e059578 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,28 @@ -.*.d +*~ *.o +*.lo +DEADJOE +Makefile +Makefiles +Makefile.in +autom4te.cache +aclocal.m4 +config.log +config.cache +config.status +config.sub +config.guess +config.h* +configure +missing +libtool +install-sh +.*.d beanstalkd gmon.out tags +cscope.out tests/cutcheck* tests/cutgen +stamp-h1 + diff --git a/Makefile b/Makefile deleted file mode 100644 index 8efa449..0000000 --- a/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -program := beanstalkd -export CFLAGS := $(CFLAGS) -Wall -Werror -export LDFLAGS := $(LDFLAGS) -levent - -sources := $(shell ls *.c | fgrep -v $(program)) -objects := $(sources:.c=.o) -tests := $(sources:%=tests/test_%) - -all: export CFLAGS := $(CFLAGS) -O2 -all: $(program) - -debug: export CFLAGS := $(CFLAGS) -g -pg -DDEBUG -debug: export LDFLAGS := $(LDFLAGS) -pg -debug: $(program) - -check: export CFLAGS := $(CFLAGS) -g -pg -check: export LDFLAGS := $(LDFLAGS) -pg -levent -check: tests/cutcheck $(objects) - ./tests/cutcheck - @echo - -#ifneq ($(MAKECMDGOALS),clean) --include $(sources:%.c=.%.d) .$(program).d -#endif - -$(program): $(objects) $(program).o - -check: export CFLAGS := $(CFLAGS) -D__LINUX__ -tests/cutgen: tests/cutgen.c - -tests/cutcheck.c: $(tests) tests/cutgen - ./tests/cutgen -o tests/cutcheck.c $(tests) - -tests/cutcheck: tests/cutcheck.o $(objects) $(tests:.c=.o) - -pkg: check-for-version $(program)-$(VERSION).tar.gz - -check-for-version: - @test "$(VERSION)" || { echo Usage: make pkg 'VERSION='; false; } - -$(program)-%.tar.gz: - ./pkg.sh $(program) $* $@ - -clean: - rm -f $(program) *.o .*.d tests/*.o core core.* gmon.out - rm -f $(program) tests/cutcheck* tests/cutgen - rm -f $(program)-*.tar.gz - -# .DELETE_ON_ERROR: -.PHONY: all debug check pkg check-for-version clean - -# This tells make how to generate dependency files -.%.d: %.c - @$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \ - | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \ - [ -s $@ ] || rm -f $@' - diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..28e6a74 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,52 @@ +AUTOMAKE_OPTIONS = foreign no-dependencies + +program = beanstalkd + +bin_PROGRAMS = $(program) +beanstalkd_SOURCES = beanstalkd.c \ + conn.c \ + job.c \ + ms.c \ + net.c \ + pq.c \ + prot.c \ + tube.c \ + util.c + +cutgen_CFLAGS = -D__LINUX__ + +EXTRA_DIST = conn.h job.h ms.h net.h pq.h prot.h stat.h tube.h util.h + +tests = $(abs_srcdir)/tests/test_conn.c \ + $(abs_srcdir)/tests/test_job.c \ + $(abs_srcdir)/tests/test_ms.c \ + $(abs_srcdir)/tests/test_net.c \ + $(abs_srcdir)/tests/test_pq.c \ + $(abs_srcdir)/tests/test_prot.c \ + $(abs_srcdir)/tests/test_reserve.c \ + $(abs_srcdir)/tests/test_tube.c \ + $(abs_srcdir)/tests/test_util.c + +check: $(program) tests/cutcheck + tests/cutcheck + @echo + +tests/cutcheck.c: $(tests) tests/cutgen + tests/cutgen -o tests/cutcheck.c $(tests) + +tests/cutcheck.o: tests/cutcheck.c + $(CC) $(CFLAGS) -I$(abs_srcdir)/tests/ -c tests/cutcheck.c -o tests/cutcheck.o + +tests/cutcheck: tests/cutcheck.o + for file in `ls $(abs_srcdir)/tests/test_*.c`; do cd $(abs_builddir)/tests/ && $(CC) $(CFLAGS) -I$(abs_srcdir)/tests/ -c $$file; done; + $(CC) $(CFLAGS) -I$(abs_srcdir)/tests/ $(LDFLAGS) $(LIBS) -pg `ls *.o | grep -v $(program)` `ls $(abs_builddir)/tests/test_*.o` tests/cutcheck.o -o tests/cutcheck + +tests/cutgen: $(abs_srcdir)/tests/cutgen.c + @if ! test -d tests; then mkdir tests; fi + $(CC) $(CFLAGS) $(cutgen_CFLAGS) -I$(abs_srcdir)/tests/ $(LDFLAGS) $(abs_srcdir)/tests/cutgen.c -o tests/cutgen + +clean: + rm -f *.o tests/*.o tests/cutgen tests/cutcheck* + rm -f $(program) .*.d core core.* gmon.out + rm -f $(program)-*.tar.gz + diff --git a/beanstalkd.c b/beanstalkd.c index 46d4453..4ce3ed9 100644 --- a/beanstalkd.c +++ b/beanstalkd.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "net.h" #include "util.h" diff --git a/build.mk b/build.mk new file mode 100644 index 0000000..ac3c101 --- /dev/null +++ b/build.mk @@ -0,0 +1,37 @@ + +SUPPRESS_WARNINGS = 2>&1 | (egrep -v '(AC_TRY_RUN called without default to allow cross compiling|AC_PROG_CXXCPP was called before AC_PROG_CXX|defined in acinclude.m4 but never used|AC_PROG_LEX invoked multiple times|AC_DECL_YYTEXT is expanded from...|the top level)'||true) + +AUTOCONF ?= 'autoconf' +ACLOCAL ?= 'aclocal' +AUTOHEADER ?= 'autoheader' +AUTOMAKE ?= 'automake' +AUTOUPDATE ?= 'autoupdate' + +config_h_in = config.h.in +targets = $(config_h_in) configure makefiles + +all: $(targets) + +aclocal.m4: + $(ACLOCAL) + +$(config_h_in): configure + @echo rebuilding $@ + @rm -f $@ + $(AUTOHEADER) $(SUPPRESS_WARNINGS) + +configure: aclocal.m4 configure.in + @echo rebuilding $@ + $(AUTOUPDATE) + $(AUTOCONF) $(SUPPRESS_WARNINGS) + +makefiles: configure Makefile.am + @echo rebuilding Makefile.in files + $(AUTOMAKE) --add-missing --copy + +clean: + @rm -rf *.lo *.la *.o *.a .libs Makefile Makefile.in stamp-h1 gmon.out beanstalkd + @rm -rf tests/*.lo tests/*.la tests/*.o tests/*.a tests/.libs tests/Makefile tests/Makefile.in tests/gmon.out tests/cutcheck* tests/cutgen + rm -rf aclocal.m4 autom4te.cache install.sh libtool 'configure.in~' missing config.h* configure + rm -f config.guess config.log config.status config.sub cscope.out install-sh + diff --git a/buildconf.sh b/buildconf.sh new file mode 100755 index 0000000..b619ba7 --- /dev/null +++ b/buildconf.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +eval `grep '^EXTRA_VERSION=' configure.in` +case "$EXTRA_VERSION" in + *-dev) + rebuildok=1 + ;; + *) + rebuildok=0 + ;; +esac + +clean=0 + +while test $# -gt 0; do + if test "$1" = "--force"; then + rebuildok=1 + echo "Forcing buildconf" + fi + if test "$1" = "--clean"; then + clean=1 + fi + shift +done + +if test "$rebuildok" = "0"; then + echo "You should not run buildconf in a release package." + echo "use buildconf --force to override this check." + exit 1 +fi + +if test "$clean" = "1"; then + echo "Cleaning autogenerated files" + ${MAKE:-make} -s -f build.mk clean +else + ${MAKE:-make} -s -f build.mk +fi + diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..a82951e --- /dev/null +++ b/configure.in @@ -0,0 +1,183 @@ +dnl this files has to be processed by autoconf +AC_PREREQ(2.61) + +AC_INIT +AC_CONFIG_SRCDIR([README]) +AC_CONFIG_SRCDIR(job.c) +AC_CONFIG_HEADERS(config.h) +AM_INIT_AUTOMAKE(beanstalkd,1.2) +AM_MAINTAINER_MODE + +AC_PROG_CC +AC_PROG_LD +AC_PROG_INSTALL + +DEFAULT_INSTALL_PREFIX="/usr/local" +STANDARD_PREFIXES="/usr /usr/local /opt /local" + +MAJOR_VERSION=1 +MINOR_VERSION=2 +EXTRA_VERSION="-dev" + +BEAN_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}${EXTRA_VERSION}" + +dnl generate version.h {{{ +echo "/* automatically generated by configure */" > version.h.new +echo "/* edit configure.in to change the version number */" >> version.h.new +echo "#define BEAN_VERSION \"$BEAN_VERSION\"" >> version.h.new +cmp version.h.new $srcdir/version.h >/dev/null 2>&1 +if test $? -ne 0 ; then + rm -f $srcdir/version.h && mv version.h.new $srcdir/version.h && \ + echo 'Updated version.h' +else + rm -f version.h.new +fi +dnl }}} + +dnl {{{ --with-libdir +AC_ARG_WITH(libdir, + [AS_HELP_STRING([--with-libdir],[look for libraries in .../NAME rather than .../lib]) + ], + [LIBDIR=$with_libdir], + [LIBDIR=lib] +) +dnl }}} + +dnl {{{ --disable-rpath +AC_ARG_ENABLE(rpath, + [AS_HELP_STRING([--disable-rpath],[disable passing additional runtime library search paths]) + ], + [BEAN_RPATH=no], + [BEAN_RPATH=yes] +) +dnl }}} + +dnl {{{ check for rpath support +AC_MSG_CHECKING([if compiler supports -R]) +AC_CACHE_VAL(bt_cv_cc_dashr,[ + SAVE_LIBS=$LIBS + LIBS="-R /usr/$LIBDIR $LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[bt_cv_cc_dashr=yes],[bt_cv_cc_dashr=no]) + LIBS=$SAVE_LIBS]) +AC_MSG_RESULT([$bt_cv_cc_dashr]) +if test $bt_cv_cc_dashr = "yes"; then + ld_runpath_switch=-R +else + AC_MSG_CHECKING([if compiler supports -Wl,-rpath,]) + AC_CACHE_VAL(bt_cv_cc_rpath,[ + SAVE_LIBS=$LIBS + LIBS="-Wl,-rpath,/usr/$LIBDIR $LIBS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[bt_cv_cc_rpath=yes],[bt_cv_cc_rpath=no]) + LIBS=$SAVE_LIBS]) + AC_MSG_RESULT([$bt_cv_cc_rpath]) + if test $bt_cv_cc_rpath = "yes"; then + ld_runpath_switch=-Wl,-rpath, + else + ld_runpath_switch=-L + fi +fi +if test "$BEAN_RPATH" = "no"; then + ld_runpath_switch= +fi +dnl }}} + +dnl {{{ --with-event +AC_ARG_WITH(event, + [AS_HELP_STRING([--with-event],[specify libevent install prefix]) + ], + [ ], + [with_event=yes] +) + +if test "x$with_event" = "xno"; then + AC_MSG_ERROR([can't continue without libevent]) +else + AC_MSG_CHECKING([libevent install prefix]) + + if test "x$with_event" = "xyes"; then + for i in `echo "$STANDARD_PREFIXES"`; do + if test -f "$i/include/event.h"; then + LIBEVENT_DIR="$i" + break; + fi + done + else + if test -f "$with_event/include/event.h"; then + LIBEVENT_DIR="$with_event" + break; + else + AC_MSG_ERROR([Can't find libevent headers under $with_event directory]) + fi + fi + + if test "x$LIBEVENT_DIR" = "x"; then + AC_MSG_ERROR([Unable to locate libevent headers, please use --with-event=]) + fi + + AC_MSG_RESULT([$LIBEVENT_DIR]) + LDFLAGS="$LDFLAGS -L$LIBEVENT_DIR/$LIBDIR" + CFLAGS="$CFLAGS -I$LIBEVENT_DIR/include" + LIBS="$LIBS -levent" + + if test "$BEAN_RPATH" != "no"; then + LDFLAGS="$LDFLAGS $ld_runpath_switch$LIBEVENT_DIR/$LIBDIR" + fi + + AC_CHECK_LIB([event], [event_get_version], [], [ + AC_MSG_ERROR([event_get_version() is missing, check config.log for more details]) + ]) + + if test -f "$LIBEVENT_DIR/$LIBDIR/libevent.so"; then + LIBEVENT="$LIBEVENT_DIR/$LIBDIR/libevent.so"; + else + if test -f "$LIBEVENT_DIR/lib/libevent.so"; then + LIBEVENT="$LIBEVENT_DIR/lib/libevent.so"; + else + if test -f "$LIBEVENT_DIR/lib64/libevent.so"; then + LIBEVENT="$LIBEVENT_DIR/lib64/libevent.so"; + fi + fi + fi +fi + +dnl }}} + +dnl {{{ --enable-debug +AC_ARG_ENABLE(debug, + [AS_HELP_STRING([--enable-debug],[enable debugging symbols and compile flags]) + ], + [ + if test x"$enableval" = xyes ; then + debug="yes" + else + debug="no" + fi + ] +) + +if test x"$debug" = xyes ; then + AC_DEFINE([BEAN_DEBUG], [], [debug build]) + + if test x"$GCC" = xyes; then + dnl Remove any optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | sed -e 's/-O[0-9s]*//g'` + CFLAGS=`echo "$CFLAGS" | sed -e 's/-g[0-2]\? //g'` + changequote([,]) + CFLAGS="$CFLAGS -g3 -Wall -O0" + fi + + dnl Do not strip symbols from developer object files. + INSTALL_STRIP_FLAG="" +else + dnl Make sure to strip symbols from non-developer object files. + INSTALL_STRIP_FLAG="-s" +fi +dnl }}} + +AC_SUBST(INSTALL_STRIP_FLAG) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT + +dnl vim700: ts=2 sw=2 et diff --git a/conn.h b/conn.h index 3d7d4c4..1f35b07 100644 --- a/conn.h +++ b/conn.h @@ -19,7 +19,9 @@ #ifndef conn_h #define conn_h -#include "event.h" +#include +#include +#include #include "ms.h" #include "tube.h" #include "job.h" diff --git a/event.h b/event.h deleted file mode 100644 index 32401c2..0000000 --- a/event.h +++ /dev/null @@ -1,28 +0,0 @@ -/* event.h - wrapper for libevent's event.h */ - -/* Copyright (C) 2007 Keith Rarick and Philotic Inc. - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef event_h -#define event_h - -#include -#include -#include - -typedef void(*evh)(int, short, void *); - -#endif /*event_h*/ diff --git a/prot.c b/prot.c index aadc6fa..8fe62dc 100644 --- a/prot.c +++ b/prot.c @@ -842,7 +842,7 @@ fmt_stats(char *buf, size_t size, void *x) global_stat.waiting_ct, count_tot_conns(), getpid(), - VERSION, + BEAN_VERSION, (int) ru.ru_utime.tv_sec, (int) ru.ru_utime.tv_usec, (int) ru.ru_stime.tv_sec, (int) ru.ru_stime.tv_usec, uptime()); diff --git a/tube.h b/tube.h index 874cccf..0abe85e 100644 --- a/tube.h +++ b/tube.h @@ -21,6 +21,8 @@ typedef struct tube *tube; +typedef void(*evh)(int, short, void *); + #include "stat.h" #include "job.h" #include "pq.h" diff --git a/version.h b/version.h deleted file mode 100644 index fc27c6f..0000000 --- a/version.h +++ /dev/null @@ -1,22 +0,0 @@ -/* version.h - beanstalkd version header */ - -/* Copyright (C) 2007 Keith Rarick and Philotic Inc. - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* This file should be updated on each release branch; it should remain - * unchanged in master. */ - -#define VERSION "dev"