top_builddir=../..
top_srcdir=../..
srcdir=@srcdir@

include $(top_srcdir)/Make.rules

.SUFFIXES: .la .lo

SHARED_CFLAGS=-DPR_SHARED_MODULE
SHARED_LDFLAGS=-avoid-version -export-dynamic -module
VPATH=@srcdir@

MODULE_NAME=mod_statsd
MODULE_OBJS=mod_statsd.o \
  statsd.o \
  metric.o

SHARED_MODULE_OBJS=mod_statsd.lo \
  statsd.lo \
  metric.lo

# Necessary redefinitions
INCLUDES=-I. -I./include -I../.. -I../../include @INCLUDES@
CPPFLAGS= $(ADDL_CPPFLAGS) -DHAVE_CONFIG_H $(DEFAULT_PATHS) $(PLATFORM) $(INCLUDES)
LDFLAGS=-L../../lib @LIBDIRS@

.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

.c.lo:
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CPPFLAGS) $(CFLAGS) $(SHARED_CFLAGS) -c $< -o $@

shared: $(SHARED_MODULE_OBJS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $(MODULE_NAME).la $(SHARED_MODULE_OBJS) -rpath $(LIBEXECDIR) $(LDFLAGS) $(SHARED_LDFLAGS) $(SHARED_MODULE_LIBS) `cat $(MODULE_NAME).c | grep '$$Libraries:' | sed -e 's/^.*\$$Libraries: \(.*\)\\$$/\1/'`

static: $(MODULE_OBJS)
	$(AR) rc $(MODULE_NAME).a $(MODULE_OBJS)
	$(RANLIB) $(MODULE_NAME).a

install:
	if [ -f $(MODULE_NAME).la ] ; then \
		$(LIBTOOL) --mode=install --tag=CC $(INSTALL_BIN) $(MODULE_NAME).la $(DESTDIR)$(LIBEXECDIR) ; \
	fi

clean:
	$(LIBTOOL) --mode=clean $(RM) $(MODULE_NAME).a $(MODULE_NAME).la *.o *.gcno *.lo .libs/*.o

dist: clean
	$(RM) Makefile $(MODULE_NAME).h config.status config.cache config.log *.gcda *.gcno
	-$(RM) -r .libs/ .git/ CVS/ RCS/

# Run the API unit tests
check:
	test -z "$(ENABLE_TESTS)" || (cd t/ && $(MAKE) api-tests)
