
COMPONENTS:=filtersyswarn binstrswap mon mipaltools easytrain

.PHONY: all clean releaseCheck $(COMPONENTS)

TOOLS_BUILT_FLAG?=.toolsBuilt

all: $(COMPONENTS)
	@if [ ! -f $(TOOLS_BUILT_FLAG) ] ; then \
		touch $(TOOLS_BUILT_FLAG); \
	fi

clean: $(COMPONENTS)
	@rm -f $(TOOLS_BUILT_FLAG)

$(COMPONENTS):
	@printf "Making tool $@: "
	@$(MAKE) -C "$@" $(MAKECMDGOALS)

releaseCheck:
	@for dir in $(dir $(shell find * test/* -maxdepth 1 -name Makefile)) ; do \
		printf "Checking tool $$dir:\n"; \
		$(MAKE) -C "$$dir" clean; \
		if [ $$? -ne 0 ] ; then \
			exit 1; \
		fi; \
		$(MAKE) -C "$$dir"; \
		if [ $$? -ne 0 ] ; then \
			exit 1; \
		fi; \
		$(MAKE) -C "$$dir" test; \
		if [ $$? -ne 0 ] ; then \
			exit 1; \
		fi; \
	done
