#!/usr/bin/make -f
# -*- makefile -*-

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

# For testing: fakeroot debian/rules binary

# 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)

CFLAGS = -Wall -g

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

configure:
	dh_testdir
	cmake . \
-DFREECAD_BUILD_DEBIAN=ON \
-DCMAKE_INSTALL_PREFIX=/usr/lib/freecad \
-DCMAKE_INSTALL_MANDIR=/usr/share/man \
-DCMAKE_INSTALL_INFODIR=/usr/share/info \
-DCMAKE_INSTALL_DATADIR=/usr/share/freecad \
-DCMAKE_INSTALL_INCLUDEDIR=/usr/include/freecad \
-DCMAKE_INSTALL_DOCDIR=/usr/share/doc/freecad

build: build-stamp

build-stamp: configure
	dh_testdir
	$(MAKE)
	touch $@

clean:
	dh clean
	rm -f build-stamp
	find -name '*.pyc' | xargs rm -f
	find -name 'moc_*.cpp' | xargs rm -f
	find -name 'ui_*.h' | xargs rm -f
	find -name 'CMakeFiles' | xargs rm -rf
	rm -f stamp-h1

install: build install-stamp
install-stamp:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) install/fast DESTDIR=$(CURDIR)/debian/tmp/freecad
	# install the core system
	dh_install -pfreecad debian/tmp/freecad/usr/share/freecad/* usr/share/freecad/
	# Desktop icons
	dh_install -pfreecad debian/tmp/freecad/usr/share/freecad/freecad.xpm usr/share/pixmaps
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad-icon-16.png debian/freecad/usr/share/icons/hicolor/16x16/apps/freecad.png
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad-icon-32.png debian/freecad/usr/share/icons/hicolor/32x32/apps/freecad.png
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad-icon-32.png debian/freecad/usr/share/icons/hicolor/48x48/apps/freecad.png
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad-icon-64.png debian/freecad/usr/share/icons/hicolor/64x64/apps/freecad.png
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad.svg debian/freecad/usr/share/icons/hicolor/scalable/apps/freecad.svg
	install -m 644 debian/tmp/freecad/usr/share/freecad/freecad-doc.png debian/freecad/usr/share/icons/hicolor/64x64/mimetypes/application-x-extension-fcstd.png

	dh_install -pfreecad debian/tmp/freecad/usr/lib/freecad/bin usr/lib/freecad
	dh_install -pfreecad debian/tmp/freecad/usr/lib/freecad/lib usr/lib/freecad
	dh_install -pfreecad debian/tmp/freecad/usr/lib/freecad/Mod usr/lib/freecad
	dh_install debian/freecad.desktop usr/share/applications
	dh_installman debian/freecad.1 debian/mime/freecad-thumbnailer.1
	dh_installchangelogs ChangeLog.txt
	# install the headers
	#dh_install -pfreecad-dev debian/tmp/freecad/usr/include/* usr/include
	# install the help system
	dh_install -pfreecad-doc debian/tmp/freecad/usr/share/doc/* usr/share/doc/
	# install MIME stuff
	dh_install debian/mime/freecad-thumbnailer usr/bin
	dh_install debian/mime/freecad.thumbnailer usr/share/thumbnailers
	dh_install debian/mime/freecad.schemas etc/gconf/schemas
	dh_gconf -pfreecad
	dh_installmime
	touch install-stamp

override_dh_compress:
	dh_compress -X.qch -X.qhc

override_dh_makeshlibs:


binary-indep: build install
	dh binary-indep

binary-arch: build install
	dh binary-arch

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