#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_PREPEND := -Wl,-z,defs -Wl,--as-needed

%:
	dh $@ --with autotools_dev,python2,tex --builddirectory

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-rpath \
		--enable-warnings \
		--enable-nls \
		--with-gnu-ld \
		--without-aspell \
		--without-hunspell \
		--with-enchant \
		--with-x \
		--without-included-gettext \
		--without-included-boost \
		--without-included-mythes \

override_dh_auto_install:
	dh_auto_install --destdir=debian/lyx-common

# move binaries to arch package
	mkdir -p debian/lyx/usr/share
	mv debian/lyx-common/usr/bin debian/lyx/usr/bin
	mv debian/lyx-common/usr/share/man debian/lyx/usr/share/man

# move fonts to font package
	mkdir -p debian/fonts-lyx/usr/share/fonts/truetype
	mv debian/lyx-common/usr/share/lyx/fonts \
		debian/fonts-lyx/usr/share/fonts/truetype/lyx

# move tex files to correct place
	mkdir -p debian/lyx-common/usr/share/texmf/tex/latex
	mv debian/lyx-common/usr/share/lyx/tex \
		debian/lyx-common/usr/share/texmf/tex/latex/lyx

# make script executable
	chmod 755 debian/lyx-common/usr/share/lyx/scripts/listerrors

# handle font documentation
	mkdir -p debian/fonts-lyx/usr/share/doc/fonts-lyx
	mv debian/fonts-lyx/usr/share/fonts/truetype/lyx/ReadmeBaKoMa4LyX.txt \
		debian/fonts-lyx/usr/share/doc/fonts-lyx/
	rm debian/fonts-lyx/usr/share/fonts/truetype/lyx/BaKoMaFontLicense.txt

override_dh_installdocs:
	mkdir -p debian/lyx/usr/share/doc
	ln -s lyx-common debian/lyx/usr/share/doc/lyx

	mkdir -p debian/lyx-dbg/usr/share/doc
	ln -s lyx debian/lyx-dbg/usr/share/doc/lyx-dbg

	dh_installdocs

override_dh_python2:
	dh_python2 /usr/share/lyx

override_dh_installtex:
	dh_installtex -plyx-common

override_dh_strip:
	dh_strip --dbg-package=lyx-dbg

override_dh_builddeb:
	dh_builddeb -- -Z xz
