#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie

liblzo2_source := $(shell dpkg-query -W -f='$${source:Package} (= $${source:Version})\n' liblzo2-dev | head -n 1)


%:
	dh $@

override_dh_auto_build:
	# Update MiniLZO
	cp src/compress/lzoconf.h src/compress/lzoconf.h.orig
	cp src/compress/lzodefs.h src/compress/lzodefs.h.orig
	cp src/compress/minilzo.c src/compress/minilzo.c.orig
	cp src/compress/minilzo.h src/compress/minilzo.h.orig
	cp /usr/share/lzo/minilzo/*.[ch] src/compress

	dh_auto_build

override_dh_auto_clean:
	# Restore MiniLZO
	[ ! -f src/compress/lzoconf.h.orig ] || mv src/compress/lzoconf.h.orig src/compress/lzoconf.h
	[ ! -f src/compress/lzodefs.h.orig ] || mv src/compress/lzodefs.h.orig src/compress/lzodefs.h
	[ ! -f src/compress/minilzo.c.orig ] || mv src/compress/minilzo.c.orig src/compress/minilzo.c
	[ ! -f src/compress/minilzo.h.orig ] || mv src/compress/minilzo.h.orig src/compress/minilzo.h

	dh_auto_clean

override_dh_auto_configure:
	dh_auto_configure -- --bindir=/usr/games --enable-psx --with-external-mpcdec --with-external-tremor --with-external-trio

override_dh_gencontrol-arch:
	dh_gencontrol -a -- '-Vbu:liblzo2=$(liblzo2_source)'
