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

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

DEB_CONFIGURE_EXTRA_FLAGS = --enable-ld-version-script --enable-cxx \
	--without-lzo --disable-guile \
	--cache-file=$(CURDIR)/config.cache --with-libgcrypt \
	--disable-openssl-compatibility \
	--with-packager=Debian \
	--with-packager-bug-reports=http://bugs.debian.org/ \
	--with-packager-version="$(DEB_VERSION)" \
	--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  DEB_CONFIGURE_EXTRA_FLAGS += CC=$(DEB_HOST_GNU_TYPE)-gcc
endif
DEB_MAKE_CHECK_TARGET = check
DEB_DH_MAKESHLIBS_ARGS_libgnutls26 := -V 'libgnutls26 (>= 2.12.17-0)'
DEB_DH_MAKESHLIBS_ARGS_libgnutlsxx27 := -V 'libgnutlsxx27 (>= 2.12.17-0)'
DEB_COMPRESS_EXCLUDE := gnutls.pdf

# If the architecture does not have libffi then p11-kit will not be
# available either.
p11_no_cpus := or1k
ifneq (,$(findstring $(DEB_HOST_ARCH_CPU),$(p11_no_cpus)))
DEB_CONFIGURE_EXTRA_FLAGS += --without-p11-kit
endif

# pre-clean rule: save gnutls.pdf since it is expensive to regenerate.
# See README.source
cleanbuilddir/gnutls26-doc::
	if [ -e doc/gnutls.pdf ] ; then mv doc/gnutls.pdf doc/gnutls.pdf.debbackup ; fi


# additional commands for clean
clean::
	mkdir -p m4

	-rm -rf autom4te.cache

	-rm -f tests/stamp-tests
	# stupid conflicts
	-rm -f doc/*.info* lib/po/libgnutls26.pot
	# restore gnutls.pdf
	if [ -e doc/gnutls.pdf.debbackup ] && [ ! -e doc/gnutls.pdf ] ; then mv doc/gnutls.pdf.debbackup doc/gnutls.pdf ; fi

# additional comands for build rule
build/gnutls26-doc::
	$(MAKE) html

common-install-arch::
	printenv
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	find debian/tmp/usr/lib/* -name '*.so.*.*' -type f -exec \
		chrpath -d {} +
	find debian/tmp/usr/bin/ -type f -exec \
		chrpath -d {} +
endif
	if ! test -e debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libgnutls26 ; \
		then \
		install -d -m755 \
			debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libgnutls26 &&\
		mv -v debian/tmp/usr/bin/* \
			debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libgnutls26 ;\
		fi
