#!/usr/bin/make -f

PACKAGE = makehuman
SRC_VERSION := $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')
SVN_DIR := $(shell echo $(SRC_VERSION) | sed -e 's/[.~]/_/g')
TARBALL = $(PACKAGE)_$(SRC_VERSION).orig.tar.gz

%:
	dh $@ --with python2

override_dh_auto_build:
	$(MAKE) -f Makefile.Linux EXE=makehuman.real
	sh debian/scripts/gendoc.sh

override_dh_install:
	dh_install
	if [ -d debian/makehuman-data ]; then \
	        find debian/makehuman-data -type d -empty -delete; \
	find $(CURDIR)/debian/makehuman-data/usr/share/makehuman/data/targets/ -type f | xargs chmod 0644; \
	chmod 644 $(CURDIR)/debian/makehuman-data/usr/share/makehuman/data/shaders/aqsis/hair.sl \
	    $(CURDIR)/debian/makehuman/usr/share/makehuman/plugins/3_libraries_hair_chooser.py \
	    $(CURDIR)/debian/makehuman/usr/share/makehuman/plugins/0_modeling_asymm.py \
	    $(CURDIR)/debian/makehuman/usr/share/makehuman/apps/uvinterpolator.py \
	    $(CURDIR)/debian/makehuman/usr/share/makehuman/plugins/pose.py; \
	fi

override_dh_auto_clean:
	touch utils
	$(MAKE) -f Makefile.Linux clean
	rm -f makehuman.real
	find $(CURDIR)/shared/ -name "*.pyc" -exec "rm" "-f" {} ";"
	find $(CURDIR)/plugins/ -name "*.pyc" -exec "rm" "-f" {} ";"
	rm -fr docs/mhproto_cdoc
	dh_auto_clean

get-orig-source:
	svn export \
		http://makehuman.googlecode.com/svn/releases/makehuman_$(SVN_DIR) \
			get-orig-source/$(PACKAGE)-$(SRC_VERSION)
	GZIP=--best tar czf $(TARBALL) --exclude=os-x --exclude=utils \
		-C get-orig-source $(PACKAGE)-$(SRC_VERSION)
	rm -rf get-orig-source
	echo "  "$(TARBALL)" created!"
