#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

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

ifneq (,$(findstring parallel,$(DEB_BUILD_OPTIONS)))
    PARALLEL_JOBS = $(shell echo $(DEB_BUILD_OPTIONS) | \
        sed -e 's/.*parallel=\([0-9]\+\).*/\1/')
    PARALLEL_OPTIONS = -j$(PARALLEL_JOBS)
endif
# DEB_BUILD_OPTIONS


# special issues on architectures
ifeq (hppa,$(DEB_BUILD_ARCH))
        CXXFLAGS += -ffunction-sections -mlong-calls
endif
# special issues on architectures


build: build-stamp

build-stamp:
	dh_testdir

	mkdir build && \
	cd build && \
	cmake   -D CMAKE_INSTALL_PREFIX:PATH=/usr \
		-D CMAKE_CXX_FLAGS=$(CXXFLAGS) \
		.. && \
	$(MAKE) $(PARALLEL_OPTIONS)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	rm -rf build

	dh_clean

install: install-stamp

install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs 

	cd build && $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

#	Strip plugins and libraries, dh_link doesn't work with all of them
	find debian/tmp/usr/lib -name \*.module -exec strip --strip-unneeded --remove-section=.comment {} \;

#	Remove files, we're not going to ship them because it would be only
#	useful for plugin developers and upstream discourages it
	rm -fr debian/tmp/usr/include
	rm -f debian/tmp/usr/lib/*so

#	Quell lintian warning "duplicate-font-file" by removing the files and
#	symlinking to the ones in the package tff-bitstream-vera.  Use dh_link,
#	since paths must be relative when elements in the path are common
#	(e.g. /usr/)
	rm -f debian/tmp/usr/share/k3d/fonts/Vera*ttf

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_install -i --list-missing
	dh_installdocs -i
	dh_installchangelogs -i
	dh_installmime -i
	dh_installman -i
	dh_lintian -i
	dh_icons -i
#	Symlinking fonts (file k3d-data.links)
	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 install
	dh_testdir
	dh_testroot
	dh_install -a --list-missing
	dh_installdocs -a
	dh_installchangelogs -a
	dh_installman -a
	dh_lintian -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_installdeb -a
	dh_shlibdeps -a
#	Python support
	dh_pysupport -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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