#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
	build_flags = --build=$(DEB_BUILD_GNU_TYPE)
else
	build_flags = --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif


CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

LDFLAGS = -Wl,-z,defs

SHARED_PKG := libthai0
SHLIB_VER := 0.1.12

config.status: configure.in
	dh_testdir

	[ -d m4 ] || mkdir m4
	autoreconf --install

	# Add here commands to configure the package.
	./configure $(build_flags) --prefix=/usr \
	  --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info \
	  --enable-shared CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"


build-indep: build-indep-stamp
build-indep-stamp:  config.status
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) -C data
	$(MAKE) -C doc

	touch $@

build-arch: build-arch-stamp
build-arch-stamp:  config.status
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) -C src

	touch $@

build: build-indep build-arch

clean:
	dh_testdir
	dh_testroot

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) maintainer-clean
	rm -f aclocal.m4 configure ltmain.sh
	find . -name Makefile.in -exec rm -f {} \;
	rm -rf m4

	dh_clean

install-indep: build-indep
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -i

	# Add here commands to install the package into debian/tmp
	$(MAKE) -C data install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) -C doc  install DESTDIR=$(CURDIR)/debian/tmp

install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs -s

	# Add here commands to install the package into debian/tmp
	$(MAKE) -C include install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) -C src     install DESTDIR=$(CURDIR)/debian/tmp
	$(MAKE) install-am DESTDIR=$(CURDIR)/debian/tmp

# Build architecture-independent files here.
binary-indep: build-indep install-indep
	dh_testdir
	dh_testroot
	dh_installchangelogs -i ChangeLog
	dh_installdocs -i
	dh_install -i --sourcedir=debian/tmp
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build-arch install-arch
	dh_testdir
	dh_testroot
	dh_installchangelogs -s ChangeLog
	dh_installdocs -s
	dh_install -s --sourcedir=debian/tmp
	dh_link -s
	dh_strip -s
	dh_compress -s
	dh_fixperms -s
	dh_makeshlibs -s -p$(SHARED_PKG) -V '$(SHARED_PKG) (>= $(SHLIB_VER))'
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

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