include ../../Makefile.vars

OBJFILES = dwmauth.o
OBJDEPS	 = $(OBJFILES:%.o=deps/%_deps)
PROGS	 = $(OBJFILES:%.o=%)
ALLINC   = -I../../include ${DWMINC} ${CRYPTOPPINC} ${BZINC}
TARTARGETS = ${TARDIR}/bin/dwmauth \
	     ${TARDIR}/man/man1/dwmauth.1
ifeq ("${MANDOC}", "mandoc")
MANHTML = ${MANDOC} -Thtml -Ostyle=../mcplexman.css -Oman=../html%S/%N.%S.html
TARTARGETS += ${TARDIR}/${HTMLMAN}/html1/dwmauth.1.html
endif

all: ${PROGS}

#  dependency rule
deps/%_deps: %.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 'clean'
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include ${OBJDEPS}
endif
endif

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

%: %.o ../../lib/libDwmAuth.la
	${LIBTOOL} --mode=link --tag=CXX ${CXX} ${LDFLAGS} -o $@ $^ ${PTHREADLDFLAGS} ${DWMLIB} -lpcap ${CRYPTOPPLIB} ${BOOSTLIB} ${ZLIB} ${BZLIB} ${OSLIBS} -static

tarprep: ${TARTARGETS}

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

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

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

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

clean: clean-tarprep
	${LIBTOOL} --mode=clean rm -f ${PROGS} ${OBJFILES}

clean-tarprep::
	${LIBTOOL} --mode=clean rm -f ${TARTARGETS}

distclean: clean
	rm -f ${OBJDEPS}
