#! /usr/bin/make -f
# -*- makefile -*-
export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

export DEB_CFLAGS_MAINT_APPEND := -Wall
export DEB_LDFLAGS_MAINT_APPEND := -Wl,-z,defs

CXXFLAGS += -std=gnu++98

# shared library versions,
version=`ls src/.libs/lib*.so.* | \
awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
major=`ls src/.libs/lib*.so.* | \
awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`

libpackage=libnewmat10ldbl

%:
	dh $@

override_dh_autoreconf:
	libtoolize --force --copy
	libtoolize --ltdl --force --copy
	autoheader
	touch NEWS ChangeLog
	aclocal
	autoconf
	automake --add-missing
	dh_autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	./example
	./tmt
	./test_exc
endif

override_dh_clean:
	rm -rf libltdl
	rm -f *.lo NEWS INSTALL *~
	dh_clean

override_dh_install:
	dh_install
	d-shlibmove --commit \
		    --ldbl \
		    --multiarch \
		    --exclude-la \
		    --movedev debian/tmp/usr/include/* usr/include \
		    debian/tmp/usr/lib/*/*.so

debian/${libpackage}.symbols:
	debuild -uc -us
	dpkg-gensymbols -p${libpackage} -O$@ -q
	sed -e 's/\( [0-9\.]\+\)\-.\+$$/\1/g' -i $@
