#! /usr/bin/make -f
# Build the libgcrypt package for Debian.

export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH      ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

DEBVERSION := $(shell dpkg-parsechangelog | \
	sed -n '/^Version: /s/^Version: //p')

export DEB_BUILD_MAINT_OPTIONS := hardening=+bindnow

#WIN_FLAGS=LDFLAGS="-Xlinker --no-insert-timestamp" CFLAGS="-g -Os" CPPFLAGS=

SPARC=
ifeq ($(DEB_HOST_ARCH),solaris-sparc)
	SPARC = --disable-asm
endif

override_dh_auto_configure:
	dh_auto_configure --verbose --builddirectory=build -- \
		--enable-static \
		--libdir=/lib/$(DEB_HOST_MULTIARCH) \
		$(SPARC)

		#--enable-noexecstack
		#--enable-ld-version-script

override_dh_makeshlibs:
	dh_makeshlibs -V 'libgcrypt20 (>=1.7.0-0)' -- -c4
#	dh_makeshlibs -V 'libgcrypt20 (>=1.7.0-0)' \
#		--add-udeb=libgcrypt20-udeb -- -c4

override_dh_auto_build-indep:
	# use current version in /usr/share/texmf/tex/texinfo/, see #803081
	rm -f build-aux/texinfo.tex
	cd build/doc && $(MAKE) stamp-vti
	cd build/doc && $(MAKE) pdf html
#	for cpu in i686 x86_64; do \
#	 mkdir -p build-$$cpu-w64-mingw32 && \
#	 cd build-$$cpu-w64-mingw32 && $(WIN_FLAGS) ../configure \
#	    --prefix=/usr/$$cpu-w64-mingw32 \
#	    --with-libgpg-error-prefix=/usr/$$cpu-w64-mingw32 \
#	    --disable-padlock-support --disable-asm \
#	    --enable-static \
#	    --host $$cpu-w64-mingw32 && \
#	  $(WIN_FLAGS) $(MAKE) \
#	  || exit 1 ; \
#	  cd .. ; \
#	done

override_dh_auto_install-indep:
#	for cpu in i686 x86_64; do \
#	  cd build-$$cpu-w64-mingw32 && \
#	  $(MAKE) install DESTDIR=$(shell pwd)/debian/tmp \
#	  || exit 1 ; \
#	  cd .. ; \
#	done
	find debian/tmp -name libgcrypt.la -type f -delete

override_dh_auto_install-arch:
	dh_auto_install --verbose --builddirectory=build
	mkdir -p -m755 debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
	cd debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH) \
		&& ln -v -s /lib/$(DEB_HOST_MULTIARCH)/`readlink ../../../lib/*/*.so` libgcrypt.so
	rm -v debian/tmp/lib/$(DEB_HOST_MULTIARCH)/*.so
	mv -v debian/tmp/lib/$(DEB_HOST_MULTIARCH)/*.a \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/

override_dh_strip:
	dh_strip --ddeb-migration='libgcrypt20-dbg (<< 1.6.4-4~)'

override_dh_installinfo:
	dh_installinfo
	if test -e debian/libgcrypt20-doc ; then \
		cd debian/libgcrypt20-doc/usr/share/info && \
		sed -i -e 's:image src="\([^"]*.png"\):image src="/usr/share/doc/libgcrypt20-doc/html/\1:g' *.info* ; \
	fi

override_dh_link:
	rm -rf debian/libgcrypt20-dbg/usr/share/doc/libgcrypt20-dbg
	dh_link

override_dh_gencontrol:
	dh_gencontrol -plibgcrypt11-dev -- -v1.5.4-3+really$(DEBVERSION)
	dh_gencontrol --remaining-packages

%:
	dh $@ --parallel --builddirectory=build --with autoreconf
