# ----------
# Makefile for Slony-I
#
#	Copyright (c) 2003-2009, PostgreSQL Global Development Group
#	Author: Jan Wieck, Afilias USA INC.
#
# 
# ----------

top_builddir = .
include $(top_builddir)/Makefile.global
BZIP = bzip2 --best

DEFAULTBUILDS=src tools

ifeq (@with_docs@, yes)
DEFAULTBUILDS+=" doc"
endif

DISTFILES = aclocal.m4 \
  config.h.in \
  configure \
  COPYRIGHT \
  README \
  UPGRADING \
  HISTORY-1.1 \
  INSTALL \
  SAMPLE \
  Makefile \
  Makefile.global.in \
  GNUmakefile.in \
  @PACKAGE_NAME@.spec \
  @PACKAGE_NAME@.spec.in \
  $(wildcard config/*) \
  $(wildcard src/*) \
  $(wildcard doc/*) \
  $(wildcard share/*) \
  $(wildcard makefiles/*)


all:
	@for subdir in $(DEFAULTBUILDS) ; do \
	  $(MAKE) -C $$subdir $@ || exit; \
    done && \
	echo "All of Slony-I is successfully made. Ready to install"

install	installdirs:
	@for subdir in $(DEFAULTBUILDS) ; do \
	  $(MAKE) -C $$subdir $@ || exit; \
    done && \
	echo "All of Slony-I is successfully installed"

clean:
	@for subdir in $(DEFAULTBUILDS) ; do \
	  $(MAKE) -C $$subdir $@ || exit; \
    done ;\
      rm -f postgres.imp

distclean: 
	@for subdir in $(DEFAULTBUILDS) ; do \
	  $(MAKE) -C $$subdir $@ || exit; \
	done ;\
	rm -f Makefile.global Makefile.port
	rm -f GNUmakefile
	rm -f config.log config.status config.h
	rm -f @PACKAGE_NAME@.spec
	rm -f @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.bz2
	rm -f postgres.imp
	rm -rf autom4te.cache

maintainer-clean-internal:
	@for subdir in $(DEFAULTBUILDS) ; do \
	  $(MAKE) -C $$subdir maintainer-clean || exit; \
	done ;\
	rm -rf configure autom4te.cache

maintainer-clean: maintainer-clean-internal distclean

dist:	distdir

distdir := @PACKAGE_NAME@-@PACKAGE_VERSION@
dummy	:= =install=
garbage := =*  "#"*  ."#"*  *~*  *.orig  *.rej  core  @PACKAGE_NAME@-*

dist 	:= $(distdir).tar.bz2

distdir:
	-rm -rf $(distdir)* $(dummy)
	for x in `cd $(top_builddir) && find . -name CVS -prune -o -print`; do \
	  file=`expr X$$x : 'X\./\(.*\)'`; \
	  if test -d "$(top_builddir)/$$file" ; then \
	    mkdir "$(distdir)/$$file" && chmod 777 "$(distdir)/$$file"; \
	  else \
	    ln "$(top_builddir)/$$file" "$(distdir)/$$file" >/dev/null 2>&1 \
	      || cp "$(top_builddir)/$$file" "$(distdir)/$$file"; \
	  fi || exit; \
	done

dist:	distdir
	$(TAR) cf @PACKAGE_NAME@-@PACKAGE_VERSION@.tar $(distdir)
	$(BZIP) @PACKAGE_NAME@-@PACKAGE_VERSION@.tar
	-rm -rf $(distdir)

rpm: dist

	rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.bz2

.PHONY: install
