include ../../Makefile.vars

MCBLOCKINC = -I../../classes/include
ALLINC =  ${MCBLOCKINC} ${JSONCPPINC} ${CRYPTOPPINC} ${DWMRDAPINC} ${DWMAUTHINC} ${DWMINC}
MCBLOCKLIB = -L../../classes/lib -lDwmMcBlock
ALLLIB = ${MCBLOCKLIB} ${DWMRDAPLIB} ${DWMAUTHLIB} ${DWMLIB} ${JSONCPPLIB} ${CRYPTOPPLIB} -lbz2 -lz -lpcap
OBJFILES = mcblock.o
OBJDEPS  = $(OBJFILES:%.o=deps/%_deps)
TESTS    = $(OBJFILES:%.o=%)

all: mcblock

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

deps/%_deps: %.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 $<

mcblock: ${OBJFILES} ../../classes/lib/libDwmMcBlock.la
	${LIBTOOL} --mode=link --tag=CXX ${CXX} -static -g ${LDFLAGS} -o $@ $< ${ALLLIB}

clean::
	rm -f mcblock ${OBJFILES}

distclean: clean
	rm -f deps/*_deps
