.PHONY: help run run_once sanity clearlogs

CONF?=TestDaemon.conf.js
SETS?=.*(?<!_sanity)

help:
	@echo "Targets:"
	@echo "  run ........ run the test daemon"
	@echo "  run_once ... run the test daemon, but stop after every test is run"
	@echo "  sanity ..... run the sanity tests"
	@echo "  help ....... this screen"
	@echo "  clearlogs .. clear the logs (logs older then one week are deleted except"
	@echo "                               one run for every day) "
	@echo "Variables:"
	@echo "  SETS ....... run only testsets specified by this variable. For sanity"
	@echo "               target, the '_sanity' suffix is automatically appended."
	@echo "               By default all testsets are processed."
	@echo "  CONF ....... Test daemon configuration file, defaults to TestDaemon.conf.js"

### TARGET: run run_once sanity
run: libenvopen.so.1
	TestDaemon.pl -c    $(CONF) -t $(foreach set,$(SETS),-t '$(set)') | tee TestDaemon.log
run_once: libenvopen.so.1
	TestDaemon.pl -o -c $(CONF) -t $(foreach set,$(SETS),-t '$(set)') | tee TestDaemon.log
sanity: libenvopen.so.1
	[ -e /tmp/sanity ] && rm -rf /tmp/sanity
	mkdir -p /tmp/sanity/stats
	TestDaemon.pl -o -c $(CONF) $(foreach set,$(SETS),-t '$(set)_sanity') | tee TestDaemon.log
	@echo
	@cat /tmp/sanity/stats/*
libenvopen.so.1: envopen.o
	gcc -shared -Wl,-soname,$@ -o $@ $< -lc -ldl
envopen.o: envopen.c
	gcc -fPIC -rdynamic -g -c -Wall $<

### TARGET: clearlogs
clearlogs:
	perl -w clearlogs.pl $(CONF)
