# Makefile.am
#
# Keepalived OpenSource project.
#
# Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>

export			DEBUG_CFLAGS
export			DEBUG_CPPFLAGS
export			DEBUG_LDFLAGS

edit = echo "  EDIT     $@"; \
	 @SED@ -e "/^\[\!\[/d"

SUBDIRS			= lib keepalived doc

SUBDIRS			+= bin_install

EXTRA_DIST		= AUTHOR CONTRIBUTORS snap README.md build_setup autogen.sh tools/timed_reload

doc_DATA		= README

MOSTLYCLEANFILES	= README

MAINTAINERCLEANFILES	= @MAINTAINERCLEANFILES@

ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}

README:	$(srcdir)/README.md
	@$(edit) '$(srcdir)/$@.md' >$@

if WITH_DBUS
install-data-hook:
	@if [ @sysconfdir@ != /etc ]; then \
		echo; \
		echo "NOTE:	To enable DBus to work you probably want to add:"; \
		echo "	  <includedir>@sysconfdir@/dbus1/system.d</includedir>"; \
		echo "	to /etc/dbus-1/system-local.conf and restart dbus or reboot."; \
		echo; \
		echo "	It should look something like:"; \
		echo; \
		echo "<!DOCTYPE busconfig PUBLIC \"-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN\""; \
		echo " \"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\">"; \
		echo "<busconfig>"; \
		echo ""; \
		echo "  <includedir>@sysconfdir@/dbus-1/system.d</includedir>"; \
		echo ""; \
		echo "</busconfig>"; \
		echo; \
	fi
endif

distclean-local:
	@rm -f aclocal.m4 keepalived-$(VERSION).tar.gz config.log config.status
	@rm -rf autom4te.cache

# If we are in a git tree, set the last modified date of each unmodified source file
# based on its git commit date. This will help repeatable builds.
dist-hook:
	@if [ -x `type -p git` ]; then \
		git rev-parse --is-inside-work-tree >/dev/null 2>&1; \
		if [ $$? -eq 0 ]; then \
			echo "  DATESET git tree"; \
			for f in `git ls-tree --full-tree -r --name-only HEAD`; \
			do \
				if [ -n "`git status --porcelain $$f`" ]; then continue; fi; \
				if [ ! -f $(top_distdir)/$$f ]; then continue; fi; \
				touch --date=@`git log -n 1 --format=%ct -- $$f` $(top_distdir)/$$f; \
			done \
		fi \
	fi
	@rm -f $(distdir)/README

.PHONY: docker
docker:	dist
	docker build -t keepalived --build-arg GIT_VER=`grep GIT_COMMIT lib/git-commit.h | sed -e 's/.*"v[^-]*\(.*\)"/\1/'` .

# clean all files that are generated by automake/autoconf etc
autoclean:
	@$(MAKE) distclean
	@rm -f configure `find . -name Makefile.in` lib/config.h.in lib/git-commit.h lib/stamp-h[12] m4/pkg.m4
	@rm -rf build-aux

git-clean:
	@$(MAKE) autoclean

clean-local: clean-local-snap

# clean files that are generated by snapcraft
.PHONY:	clean-local-snap
clean-local-snap:
	-rm -rf parts/ prime/ stage/ keepalived_*.snap

# Added targets to maintain compatibility with keepalived releases 1.2.22 and earlier
.PHONY: tarball rpm debug profile mrproper

tarball: dist

@RPM_TRUE@rpm:
@RPM_TRUE@			@$(MAKE) dist
@RPM_TRUE@			@cp -p keepalived-$(VERSION).tar.gz `rpm --eval "%{_sourcedir}"`
@RPM_TRUE@@RPM_BIP_TRUE@	rpmbuild -ba --build-in-place keepalived.spec
@RPM_TRUE@@RPM_BIP_FALSE@	rpmbuild -ba keepalived.spec

debug:
	@$(MAKE) DEBUG_LDFLAGS=-ggdb

profile:
	@$(MAKE) DEBUG_CFLAGS=-pg

mrproper:
	@echo Please use `make distclean`

AM_DISTCHECK_CONFIGURE_FLAGS = \
        --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
