#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.
#export DH_VERBOSE=1
# This is the debhelper compatability version to use.
export DH_COMPAT=4

package:= mileage
prefix := $(shell pwd)/debian/$(package)
CFLAGS := -O2

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
PKG_VER = $(shell dpkg-parsechangelog | sed -n 's/Version: //p')
NEW_VER = $(PKG_VER)

ifneq (,$(findstring armel,$(DEB_BUILD_ARCH)))
	CONF_OPTIONS += --target=arm-linux
endif

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
	CONF_OPTIONS += --enable-debug=3
endif

configure: changever configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	# commands to compile the package.
	${MAKE} 
	touch build-stamp

changever:
	@echo "$(BUILDMSG)"
	# set hardware suffix
	@ [ $(PKG_VER) == $(NEW_VER) ] || @sed -ie "s/$(PKG_VER)/$(NEW_VER)/" debian/changelog
	@rm -f debian/changeloge

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# set hardware suffix if needed
	@ [ "$(PKG_VER)" == "$(NEW_VER)" ] || sed -ie "s/$(PKG_VER)/$(NEW_VER)/" debian/changelog
	@rm -f debian/changeloge

	# commands to clean up after the build process.
	-$(MAKE) clean
	dh_clean

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# commands to install the package into debian/<packagename>
	$(MAKE) BINDIR=$(prefix)/usr/bin install

	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean install
