#!/usr/bin/make -f
ABIM:=$(shell grep MAJVER Makefile|cut -d = -f 2|tr -d ' ')
ABIN:=$(shell grep MINVER Makefile|cut -d = -f 2|tr -d ' ')
ABIO:=$(shell grep RELVER Makefile|cut -d = -f 2|tr -d ' ')
ABI=$(ABIM).$(ABIN).$(ABIO)

export DPKG_GENSYMBOLS_CHECK_LEVEL=4

include /usr/share/dpkg/default.mk

clean:
	make clean
build:
	dh_update_autotools_config
	dh_auto_configure
	make
binary:
	dh_testroot
	dh_prep
	debian/rules override_dh_auto_install
	dh_install
	dh_installdocs
	dh_installchangelogs
	dh_installman
	dh_perl
	dh_link
	dh_strip_nondeterminism
	dh_compress
	dh_fixperms
	dh_missing
	dh_strip
	dh_makeshlibs
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

override_dh_auto_install:
	make install PREFIX=/usr DESTDIR=$(CURDIR)/debian/tmp/ MULTILIB=lib/$(DEB_HOST_MULTIARCH) LDCONFIG="/sbin/ldconfig -n"
	sed -i 's?^multilib=.*?multilib=lib/$(DEB_HOST_MULTIARCH)?' \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/*.pc
	# debian doesn't allow multiple luajit versions, just rename the binary to luajit
	mv $(CURDIR)/debian/tmp/usr/bin/luajit-* $(CURDIR)/debian/tmp/usr/bin/luajit
