#!/usr/bin/make -f

%:
	dh $@ --with autoreconf

export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
# -fPIE doesn't work, but at least get -fPIC as we used to have with
# hardening-wrapper
export DEB_CFLAGS_MAINT_APPEND = -no-pie -fno-pie -fno-PIE -fPIC
export DEB_CXXFLAGS_MAINT_APPEND = -no-pie -fno-pie -fno-PIE -fPIC
#fix FTBFS with binutils-gold
export DEB_LDFLAGS_MAINT_APPEND = -lm

DEB_BUILD_ARCH_OS ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
DEB_HOST_MULTIARCH  ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# If it's a linux OS use alsa, else use oss.
ifeq ($(DEB_BUILD_ARCH_OS),linux)
AUDIO=alsa
else
AUDIO=oss
endif

override_dh_auto_configure:
	dh_auto_configure -- --with-audio=$(AUDIO) \
		--with-vox=cmu_us_kal16 --enable-shared

override_dh_auto_build:
	$(MAKE)
	(set -e; cd doc; $(MAKE) flite.pdf flite.html; makeinfo flite.texi)

override_dh_auto_clean:
	for i in aux cp dvi fn info ky log pdf pg ps toc tp vr; do \
		rm -f doc/flite.$$i; \
	done

	rm -Rf doc/html
	rm -rf build/
	rm -rf lib/
	rm -rf bin/
	rm -f config.log
	rm -f config.status
	rm -f config.cache
	rm -f config/config
	rm -f config/system.mak
	rm -f include/flite_version.h
	rm -f configure
	rm -f main/flite_voice_list.c

override_dh_install:
	dh_install
	dh_install -plibflite1 build/*/lib/*.so.* usr/lib/$(DEB_HOST_MULTIARCH)
	rm -f build/*/lib/*.shared.a
	dh_install -pflite1-dev build/*/lib/*.so build/*/lib/*.a usr/lib/$(DEB_HOST_MULTIARCH)
