# Note: we include the additional tweaking of top_builddir, so that LIBTOOL
# resolves to the correct place.
top_builddir=@top_builddir@/../..
top_srcdir=@top_srcdir@
srcdir=@srcdir@

include $(top_builddir)/Make.rules

.SUFFIXES: .la .lo

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

MODULE_NAME=mod_load
MODULE_OBJS=mod_load.o \
  getloadavg.o
SHARED_MODULE_OBJS=mod_load.lo \
  getloadavg.lo
MODULE_LIBS=@MODULE_LIBS@

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

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

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

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 $(top_srcdir)/$(MODULE_NAME).c | grep '$$Libraries:' | sed -e 's/^.*\$$Libraries: \(.*\)\\$$/\1/'`

static: $(MODULE_OBJS)
	test -z "$(MODULE_LIBS)" || echo "$(MODULE_LIBS)" >> $(MODULE_LIBS_FILE)
	$(AR) rc $(MODULE_NAME).a $(MODULE_OBJS)
	$(RANLIB) $(MODULE_NAME).a

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

# BSD install -d doesn't work, so ...
$(DESTDIR)$(includedir) $(DESTDIR)$(includedir)/proftpd:
	@if [ ! -d $@ ]; then \
		mkdir -p $@; \
		chown $(INSTALL_USER):$(INSTALL_GROUP) $@; \
		chmod 0755 $@; \
	fi

install-headers: $(DESTDIR)$(includedir)/proftpd
	$(INSTALL_MAN) $(MODULE_NAME).h $(DESTDIR)$(includedir)/proftpd/$(MODULE_NAME).h

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

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