#!/usr/bin/make -f

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

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


CFLAGS = -g -Wall -D_REENTRANT

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

config.status: configure
	dh_testdir
	touch configure.in && \
	touch aclocal.m4 && \
	touch configure
	# Add here commands to configure the package.
	CFLAGS="$(CFLAGS)" ./configure $(confflags) \
	--prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man

build: build-stamp

build-stamp:  config.status
	dh_testdir

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

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	dh_clean 

        # Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) distclean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/polyxmass-bin.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	# Since we do not want to install COPYING and INSTALL we remove
	# them from the temporary install directory before dh_installdocs
	# is called. Same for ABOUT-NLS.
	rm $(CURDIR)/debian/tmp/usr/share/doc/polyxmass-bin/COPYING
	rm $(CURDIR)/debian/tmp/usr/share/doc/polyxmass-bin/INSTALL
	rm $(CURDIR)/debian/tmp/usr/share/doc/polyxmass-bin/ABOUT-NLS


# Build architecture-independent files here.
binary-indep: install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_install -i
	dh_installman -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: install
	dh_testdir
	dh_testroot
	dh_installchangelogs  -a ChangeLog
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_installmenu -a
	dh_installman -a
	dh_desktop -a
	dh_link -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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