include ../../Makefile.vars

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

getpfx2as: getpfx2as.o ../../lib/libDwmRDAP.la
	${LIBTOOL} --mode=link --tag=CXX ${CXX} ${CXXFLAGS} -o $@ $^  -static ${DWMLIB} ${ALLLIB}

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

tarprep: ${TARTARGETS}

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

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

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

#  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' or 'distclean'
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include ${OBJDEPS}
endif
endif

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

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

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

