MODS = $(wildcard src/*.erl)
BEAMS = $(MODS:src/%.erl=ebin/%.beam)
TEST_MODS = $(wildcard test/*.erl)
TEST_BEAMS = $(TEST_MODS:test/%.erl=test/%.beam)

all : compile test

compile : $(BEAMS)

compile-test : $(TEST_BEAMS)

test : start-test-server run-test stop-test-server

test-shell : compile compile-test
	@echo Starting an interactive YAWS shell with test paths loaded.
	@yaws -i --pa test --id test_inst

run-test : compile compile-test
	@erl -pa ./ebin -pa ./test -run timestamper_api_tests test -run init stop -noshell

start-test-server :
	@yaws -D --id test_inst

stop-test-server :
	@yaws --stop --id test_inst

clean:
	rm -rf ebin/* erl_crash.dump test/*.beam

init:
	-mkdir ebin

ebin/%.beam : src/%.erl
	erlc -W -o ebin $<

test/%.beam : test/%.erl
	@echo Compiling sources...
	erlc -W -o test $<