include ../Makefile.vars

ALLINC = -I../include ${DWMINC}
OBJFILES = DwmCountryCode.o \
	   DwmCountryCodes.o \
	   DwmIpv4CountryDb.o \
	   DwmRDAPBootstrap.o \
	   DwmRDAPFetcher.o \
	   DwmRDAPQuery.o \
	   DwmRDAPQuerySessions.o \
	   DwmRDAPRequestMessage.o \
	   DwmRDAPResponse.o \
	   DwmRDAPResponseMessage.o

shlib_version = $(shell ../getvers.sh -s)

SHARED_OBJFILES = $(OBJFILES:%.o=%.lo)
OBJDEPS  = $(OBJFILES:%.o=deps/%.d)

all:: ../lib/libDwmRDAP.la

../lib/libDwmRDAP.la: ${SHARED_OBJFILES}
	${LIBTOOL} --tag=CXX --mode=link ${CXX} -o $@ $^ -rpath ${INSTALLPREFIX}/lib -version-info ${shlib_version}

#	${LIBTOOL} --tag=CXX --mode=link ${CXX} -o $@ $^ -static -version-info ${shlib_version}


../lib/libDwm${SHARED_LIB_EXT}: ${OBJFILES}
	${CXX} ${LD_SHARED_FLAGS} -o $@ $^

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

%.o %.lo: %.cc
	${LIBTOOL} --mode=compile --tag=CXX ${CXX} ${CXXFLAGS} ${PTHREADCXXFLAGS} ${ALLINC} -c $< -o $@

tarprep: ${TARDIR}/lib/libDwmRDAP.la

${TARDIR}/lib/libDwmRDAP.la: ../lib/libDwmRDAP.la
	${LIBTOOL} --mode=install ../install-sh -s -c $< ${TARDIR}/lib/libDwmRDAP.la

clean:: clean-tarprep
	${LIBTOOL} --mode=clean rm -f ../lib/libDwmRDAP.la ${OBJFILES} \
	 ${SHARED_OBJFILES}

distclean:: clean
	rm -f deps/*.d

clean-tarprep::
	${LIBTOOL} --mode=clean rm -f ${TARDIR}/lib/libDwmRDAP.la

