include ../../Makefile.vars

MCBLOCKINC = -I../include
ALLINC = ${JSONCPPINC} ${DWMINC} ${DWMAUTHINC} ${MCBLOCKINC}
MCBLOCKLIB = -L../lib -lDwmMcBlock
ALLLIB = ${MCBLOCKLIB} ${DWMAUTHLIB} ${DWMLIB} ${JSONCPPLIB} ${CRYPTOPPLIB} -lbz2 -lz -lpcap
OBJFILES = TestDwmMcBlockAuthLogParser.o \
           TestDwmMcBlockDb.o \
	   TestDwmMcBlockDbEntry.o \
	   TestDwmMcBlockRequestMessage.o \
	   TestDwmMcBlockResponseMessage.o
OBJDEPS  = $(OBJFILES:%.o=deps/%.d)
TESTS    = $(OBJFILES:%.o=%)

all: ${TESTS}

runtests: all
	@ for tp in ${TESTS} ; do \
	        printf "%-36s " $$tp ; \
	        out=`./$$tp` ; \
	        if [ $$? -eq 0 ]; then \
	          printf "%25s\n" "$$out" ; \
	        else \
	          printf "\n%s" "$$out" ; \
	        fi ; \
	done

../lib/libDwmMcBlock.a::
	${MAKE} -C ../src

deps/%.d: %.cc
	@echo "making dependencies for $<"
	@set -e; \
	${CXX} -MM ${CXXFLAGS} ${ALLINC} -c $< | \
	  sed 's/\($*\)\.o[ :]*/\1.o $(@D)\/$(@F) : /g' > $@ ; [ -s $@ ] || \
	  rm -f $@

#  only include dependency makefiles if target is not 'clean' or 'distclean'
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include ${OBJDEPS}
endif
endif

%.o: %.cc
	${CXX} -g ${CXXFLAGS} ${ALLINC} -c $<

%: %.o ../lib/libDwmMcBlock.a
	${CXX} -g ${LDFLAGS} -o $@ $< ${ALLLIB}

clean::
	rm -f ${TESTS} ${OBJFILES}

distclean: clean
	rm -f deps/*.d
