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

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

UVERSION := $(shell dpkg-parsechangelog | sed -n -e's/^Version: \(.*\)-[^-]\+/\1/p' | cut -d ":" -f 2)
PACKAGE_NAME := $(shell dpkg-parsechangelog | sed -n -e's/^Source: \(.*\)\+/\1/p')
PYVERS :=  python2.7

%:
	dh $@ --with python2

override_dh_auto_build:

override_dh_auto_clean:
	dh_auto_clean -- --all
	rm -rf build
	rm -rf Nikola.egg-info

override_dh_auto_install:
	set -ex; \
	for py in $(PYVERS); do \
		$$py setup.py install --root debian/nikola \
				      --install-layout=deb; \
	done
	# Documentation
	rst2html docs/manual.txt debian/nikola/usr/share/doc/nikola/manual.html
	rst2html docs/theming.txt debian/nikola/usr/share/doc/nikola/theming.html
	rst2html docs/creating-a-theme.txt debian/nikola/usr/share/doc/nikola/creating-a-theme.html
	rst2html docs/extending.txt debian/nikola/usr/share/doc/nikola/extending.html
	# Drop wrong permission
	find debian/nikola/usr/lib -perm /a+x -type f -exec chmod -x {} +
	# Remove a copy of mit license
	find debian/nikola/usr/lib -name "MIT-LICENSE.txt" -type f -exec rm {} +

get-orig-source:
	@if [ ! -d "debian" ] ; then \
		echo 'Run this from the top directory of the Debian source' >&2; \
		exit 1; \
	fi
	mkdir -p ../tmp/nikola_$(UVERSION)
	wget https://github.com/getnikola/nikola/archive/v$(UVERSION).tar.gz \
		-O ../tmp/nikola_$(UVERSION).tar.gz;
	tar xf ../tmp/nikola_$(UVERSION).tar.gz \
		-C ../tmp/nikola_$(UVERSION) \
		'--exclude=*min.*' \
		'--exclude=*bootstrap3*' \
		'--exclude=*bootstrap.js' \
		'--exclude=*bootstrap.css' \
		'--exclude=*bootstrap-responsive.css' \
		'--exclude=*glyphicons-halflings*.png';
	tar -C ../tmp/nikola_$(UVERSION) nikola-$(UVERSION) -c --xz -f ../nikola_$(UVERSION).orig.tar.xz
