#!/usr/bin/make -f

PATH    := /usr/bin/dh7:$(PATH)
SCORES	= var/games/kobo-deluxe/scores
PACKAGE	= $(firstword $(shell dh_listpackages))
DATAPKG	= $(PACKAGE)-data
TMP	= $(CURDIR)/debian/tmp
PKGDIR	= $(CURDIR)/debian/$(PACKAGE)

ifeq ($(DEB_BUILD_ARCH), armel)
CFLAGS = -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -O1
CXXFLAGS = -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -O1
endif

%:
	dh --with=quilt $@

override_dh_auto_configure:
	ln -sf /usr/share/misc/config.sub
	ln -sf /usr/share/misc/config.guess
	aclocal-1.7
	automake-1.7
	autoconf
	./configure --bindir=/usr/games --prefix=/usr --sysconfdir=/etc \
		--mandir=/usr/share/man --sharedstatedir=/usr/share \
		CFLAGS="$(CFLAGS)" CXXFLAGS="$(CFLAGS)"

override_dh_auto_build:
	$(MAKE) kobo_scoredir=/$(SCORES)

override_dh_auto_install:
	mkdir -p $(TMP)/$(SCORES)
	$(MAKE) DESTDIR=$(TMP) kobo_scoredir=/$(SCORES) install
	rm -rfv $(TMP)/usr/games/kobo-deluxe \
		$(TMP)/usr/share/kobodeluxe-data/scores

override_dh_fixperms:
	dh_fixperms
	chown root.games $(PKGDIR)/usr/games/kobodl \
		$(PKGDIR)/$(SCORES)
	chmod g+s $(PKGDIR)/usr/games/kobodl
	chmod 2775 $(PKGDIR)/$(SCORES)
