#!/usr/bin/make -f
# -*- makefile -*-

# For PKG_CONFIG
-include /usr/share/dpkg/buildtools.mk
PKG_CONFIG ?= pkg-config

%:
	dh $@ --sourcedirectory=src

override_dh_auto_configure:

override_dh_auto_build:
	dh_auto_build -- USE_VOMS=yes WITH_CPP_LIBS=yes \
		CFLAGS="$(CFLAGS) $(CPPFLAGS) -fPIC -I. `$(PKG_CONFIG) --cflags gsoap`" \
		SHLIBLDFLAGS="$(LDFLAGS) -shared" \
		LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		all doc

override_dh_auto_clean:
	dh_auto_clean -- USE_VOMS=yes WITH_CPP_LIBS=yes

override_dh_auto_install:
	dh_auto_install -- USE_VOMS=yes WITH_CPP_LIBS=yes \
		LIBDIR=lib/$(DEB_HOST_MULTIARCH) \
		DOCDIR=share/doc/libcgsi-gsoap-dev \
		install.man

override_dh_missing:
	dh_missing --fail-missing

override_dh_strip:
	dh_strip --dbgsym-migration='libcgsi-gsoap-dbg (<< 1.3.12)'

override_dh_gencontrol:
	if [ -r /usr/lib/$(DEB_HOST_MULTIARCH)/libgsoap.so ] ; then \
	GSOAPLIB=`realpath /usr/lib/$(DEB_HOST_MULTIARCH)/libgsoap.so` ; else \
	GSOAPLIB=`realpath /usr/lib/libgsoap.so` ; fi && \
	GSOAPPKG=`dpkg -S $$GSOAPLIB | sed 's/:.*//'` && \
	echo "gsoap:Depends=$$GSOAPPKG" >> debian/libcgsi-gsoap1.substvars

	MINGSOAPVER=`dpkg-query -W -f '$${source:Upstream-Version}' libgsoap-dev:$(DEB_HOST_ARCH)` && \
	LASTNUM=`echo $$MINGSOAPVER | sed 's/.*\.//'` && \
	LASTNUMP1=$$(($$LASTNUM + 1)) && \
	MAXGSOAPVER=`echo $$MINGSOAPVER | sed s/$$LASTNUM$$/$$LASTNUMP1/` && \
	echo "gsoap:Depends=libgsoap-dev (>= $$MINGSOAPVER), libgsoap-dev (<< $$MAXGSOAPVER)" \
	   >> debian/libcgsi-gsoap-dev.substvars

	dh_gencontrol
