#
#    realtime test suite Makefile.
#
#    Copyright (C) 2009, Cisco Systems Inc.
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Ngie Cooper, September 2009
#

top_srcdir		?= ../..

# Override these variables to use non-system available tools.
ACLOCAL			?= aclocal
AUTOCONF		?= autoconf
AUTOHEADER		?= autoheader
AUTOMAKE		?= automake

include $(top_srcdir)/include/mk/env_pre.mk
# Ensure that this error / warning only applies for build targets.
#
# NOTE (garrcoop): this criterium should be in-sync with include/mk/env_pre.mk
# (minus help as that's only invoked in the top-level Makefile).
ifeq ($(filter autotools %clean .gitignore gitignore.%,$(MAKECMDGOALS)),)
include $(abs_srcdir)/config.mk
endif
include $(top_srcdir)/include/mk/gitignore.mk

LIBDIR			:= lib
FILTER_OUT_DIRS		:= $(LIBDIR) m4
LIB			:= $(LIBDIR)/librealtime.a

# START autotools junk
AUTOGENERATED_FILES	= \
			m4/Makefile

AUTOMAKE_FILES := config.guess config.sub install-sh missing stamp-h1

.PHONY: autotools aclocal autoconf autoheader automake
autotools: aclocal autoconf autoheader automake

.PHONY: ac-clean ac-distclean ac-maintainer-clean
ac-clean::
	$(RM) -rf autom4te.cache
	$(RM) -f aclocal.m4 config.log config.status
	$(RM) -f include/realtime_config.h include/stamp-h1

ac-distclean:: ac-clean
ac-maintainer-clean:: ac-distclean
	$(RM) -f aclocal.m4 configure $(AUTOMAKE_FILES) m4/Makefile.in
	$(RM) -f include/realtime_config.h.in

aclocal.m4:
	$(ACLOCAL) -I $(abs_srcdir)/m4

autoconf: configure

include/realtime_config.h.in: configure.ac $(wildcard m4/*.m4) aclocal.m4
	$(AUTOHEADER)

configure: configure.ac aclocal.m4
	$(AUTOCONF)
automake: $(AUTOMAKE_FILES)
$(AUTOMAKE_FILES): m4/Makefile.in
m4/Makefile.in: m4/Makefile.am aclocal.m4
	$(AUTOMAKE) -c -a

.PHONY: autoheader
autoheader: include/realtime_config.h.in
	$(AUTOHEADER)

distclean:: %: clean ac-distclean
	$(RM) -f $(AUTOGENERATED_FILES)

maintainer-clean:: distclean ac-maintainer-clean

$(AUTOGENERATED_FILES): $(top_builddir)/config.status
	$(SHELL) $^

# END autotools junk

$(LIBDIR):
	mkdir -p "$@"

$(LIB): $(LIBDIR)
	$(MAKE) -C $^ -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all

trunk-all: $(LIB)

trunk-clean:: | lib-clean

lib-clean:: $(LIBDIR)
	$(MAKE) -C $^ -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean

# Stub reference for config.mk
$(abs_srcdir)/config.mk:
	$(MAKE) -C $(top_srcdir) help; false

include $(top_srcdir)/include/mk/generic_trunk_target.mk