@SET_MAKE@

INSTALL = @INSTALL@
SHELL	= /bin/sh

# set prefix values
prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = $(exec_prefix)/bin
etcdir      = $(exec_prefix)/etc

srcdir	    = @srcdir@
VPATH       = @srcdir@

RWHOIS_ROOT_DIR = $(prefix)

# these are for tcpd_wrapper 7.4
LIBWRAP_MFLAGS = REAL_DAEMON_DIR="/" LIBS="@LIBS@" RANLIB=@RANLIB@ TLI= CC="@CC@" EXTRA_CFLAGS="@TCPD_EXTRA_CFLAGS@"

#### end of configuration section ####

LIBWRAP_DIR     = tools/tcpd_wrapper
SAMPLE_DATA_DIR = sample.data
LIB_SUBDIRS     = common mkdb regexp
BIN_SUBDIRS	= server tools
ALL_SUBDIRS	= $(LIB_SUBDIRS) $(BIN_SUBDIRS) $(SAMPLE_DATA_DIR)

all: libraries @LIBWRAP@ binaries

libraries:
	@for dir in $(LIB_SUBDIRS); do \
	  echo "making all in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) all) || exit 1; \
	done

libwrap:
	@echo "Making $(LIBWRAP)"
	(cd $(LIBWRAP_DIR); $(MAKE) $(MFLAGS) $(LIBWRAP_MFLAGS) config-check; \
	$(MAKE) $(MFLAGS) $(LIBWRAP_MFLAGS) libwrap.a)

binaries:
	@for dir in $(BIN_SUBDIRS); do \
	  echo "making all in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) all) || exit 1; \
	done


install: install-bin install-sample-data

install-bin: 
	@for dir in $(BIN_SUBDIRS); do \
	  echo "making install in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) install) || exit 1; \
	done


install-sample-data: sample-data-install

sample-data-install:
	(cd $(SAMPLE_DATA_DIR); $(MAKE) $(MFLAGS) install) || exit 1

uninstall: uninstall-bin uninstall-sample-data

uninstall-bin:
	@for dir in $(BIN_SUBDIRS); do \
	  echo "making uninstall in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) uninstall) || exit 1; \
	done

uninstall-sample-data:
	(cd $(SAMPLE_DATA_DIR); $(MAKE) $(MFLAGS) uninstall) || exit 1

clean:
	@for dir in $(ALL_SUBDIRS); do \
	  echo "making $@ in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) $@) || exit 1; \
	done
	(cd $(LIBWRAP_DIR); $(MAKE) $(MFLAGS) $@)

distclean: config-clean
	@for dir in $(ALL_SUBDIRS); do \
	  echo "making $@ in $$dir"; \
	  (cd $$dir; $(MAKE) $(MFLAGS) $@) || exit 1; \
	done

config-clean:
	rm -f config.h config.cache config.status config.log
	rm -f Makefile

dist:
	@echo "Cleaning first"
	($(MAKE) distclean)
	@echo "makeing tar file"
	make_dist.sh . $(VERSION)


