#!/usr/bin/make -f
# -*- makefile -*-
# Makefile for MRPT Debian package.

# Uncomment this to turn on verbose mode.
export DH_DEBUG=1
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)


config.status: configure
	dh_testdir
	# Add here commands to configure the package.
	./configure MRPT_IS_DEB_PACKAGE=1 --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

build: build-stamp

build-stamp:  config.status
	dh_testdir

	touch $@

distclean:
    # Nothing to do (do not remove this line!)

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp 

	# Add here commands to clean up after the build process.
	rm -f config.sub config.guess

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/mrpt.
	./configure MRPT_IS_DEB_PACKAGE=1 --prefix=$(CURDIR)/debian/ CMAKE_MRPT_USE_DEB_POSTFIXS="1"

	# Create mrpt documentation
	make documentation_html
	# Create man pages:
	make man_pages_all
	# Build all
	$(MAKE) VERBOSE=1
	# Run tests
	make test

	# Install
	$(MAKE) install
	
	# Move all the ".so" files to the proper place: the -dev package:
	mkdir -p $(CURDIR)/debian/libmrpt-dev/usr/lib/
	find $(CURDIR)/debian/ -name "*.so" | xargs -I FIL mv -f FIL $(CURDIR)/debian/libmrpt-dev/usr/lib/

	
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installmenu
	dh_installmime -p mrpt-core
	dh_installman -p mrpt-apps $(CURDIR)/man-pages/*.1*
	# Register .desktop files with a MIME type:
#	dh_desktop -p mrpt-apps
	dh_link
#	dh_strip --dbg-package=libmrpt-core-dbg
	dh_strip
	dh_compress
	dh_fixperms
	export LD_LIBRARY_PATH=$(CURDIR)/debian/libmrpt-core0.7/usr/lib:$(CURDIR)/debian/libmrpt-hwdrivers0.7/usr/lib:$(CURDIR)/debian/libmrpt-aria0.7/usr/lib
	dh_makeshlibs -a
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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