#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed -lm

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_HOST_ARCH  ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

%:
	dh $@ --with autoreconf --parallel

CONFIGURE_FLAGS ?=--disable-mmx

ifeq ($(DEB_HOST_ARCH), i386 )
	CONFIGURE_FLAGS =--enable-mmx
endif
ifeq ($(DEB_HOST_ARCH), amd64)
	CONFIGURE_FLAGS =--enable-mmx
endif

override_dh_autoreconf:
	AUTOMAKE="automake --foreign" dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_FLAGS)

override_dh_install:
	dh_install --fail-missing -XlibSDL2_gfx.la -Xjquery.js

override_dh_auto_build:
	dh_auto_build
	tar -cvz --transform='s,^test,examples,' -f debian/examples.tar.gz test

override_dh_link:
	# fix lintian warning embedded-javascript-library
	dh_link -plibsdl2-gfx-doc usr/share/javascript/jquery/jquery.js usr/share/doc/libsdl2-gfx-doc/jquery.js
	# fix lintian warning dev-pkg-without-shlib-symlink
	dh_link -plibsdl2-gfx-dev usr/lib/$(DEB_HOST_MULTIARCH)/libSDL2_gfx-1.0.so.0.0.0 usr/lib/$(DEB_HOST_MULTIARCH)/libSDL2_gfx-1.0.so
	dh_link --remaining-packages

override_dh_strip:
	dh_strip --dbg-package=libsdl2-gfx-dbg
