include ../../Makefile.vars

OBJFILES = mcpigdowatch.o
OBJDEPS  = $(OBJFILES:%.o=deps/%.d)
ALLINC   = -I../../include ${DWMAUTHINC} ${DWMINC} ${CRYPTOPPINC} ${JSONCPPINC} ${BZINC}
ALLLIB   = ${DWMAUTHLIB} ${DWMLIB} -lpcap ${CRYPTOPPLIB} ${JSONCPPLIB} ${ZLIB} ${BZLIB} ${OSLIBS}
TARTARGETS = ${TARDIR}/bin/mcpigdowatch \
	     ${TARDIR}/man/man1/mcpigdowatch.1
ifeq ("${MANDOC}", "mandoc")
MANHTML = ${MANDOC} -Thtml -Ostyle=../mcplexman.css -Oman=../html%S/%N.%S.html
TARTARGETS += ${TARDIR}/${HTMLMAN}/html1/mcpigdowatch.1.html
endif

mcpigdowatch: ${OBJFILES} ../../lib/libDwmPiGdoComm.a
	${LIBTOOL} --mode=link --tag=CXX ${CXX} ${LDFLAGS} -o $@ $^ ${ALLLIB} -static

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

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

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

tarprep: ${TARTARGETS}

${TARDIR}/bin/mcpigdowatch: mcpigdowatch
	../../install-sh -s -c -m 755 $< $@

${TARDIR}/man/man1/mcpigdowatch.1: mcpigdowatch.1
	../../install-sh -c -m 444 $< $@

${TARDIR}/${HTMLMAN}/html1/mcpigdowatch.1.html: mcpigdowatch.1
	${MANHTML} $< > $<.html
	../../install-sh -c -m 644 $<.html $@
	rm $<.html

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

clean: clean-tarprep
	rm -f mcpigdowatch ${OBJFILES}

distclean: clean
	rm -f deps/*.d

clean-tarprep::
	rm -f ${TARTARGETS}
