#!/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

AQSIS_CHANGELOG = release-notes/1.6/summary-1.6.0.txt

# 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


build: build-stamp

build-stamp:
	dh_testdir

	mkdir build && \
	cd build && \
	cmake   -D CMAKE_INSTALL_PREFIX:PATH=/usr \
		-D SYSCONFDIR=/etc/aqsis \
		-D CMAKE_CXX_FLAGS=$(CXXFLAGS) \
		-D AQSIS_USE_EXTERNAL_TINYXML:BOOL=ON \
		-D AQSIS_USE_PDIFF:BOOL=OFF \
		-D AQSIS_USE_RPATH:BOOL=OFF \
		.. && \
	$(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

#	Remove houdini script, not interesting for Debian (it's intended as
#	plugin for 3rd party proprietary software, to use Aqsis as renderer),
#	and also has poor licensing terms (not well explained, not for all
#	files, etc).
	rm -fr debian/tmp/usr/share/aqsis/plugins/houdini

#	Add exec permissions to several example scripts
	find debian/tmp/usr/ \( -name \*.sh -o -name \*.py \) -exec chmod a+x {} \;

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs -i
	dh_installchangelogs -i $(AQSIS_CHANGELOG)
	dh_install -i --sourcedir=debian/tmp
	dh_lintian -i
	dh_icons -i
	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_installmime -a
	dh_installman -a
	dh_installchangelogs -a $(AQSIS_CHANGELOG)
	dh_lintian -a
	dh_icons -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -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 
