#!/usr/bin/make -f

%:
	dh $@

WP_INCLUDES=debian/wordpress/usr/share/wordpress/wp-includes

VERSION := $(shell dpkg-parsechangelog | awk '/^Version:/ {print $$2}'| sed -e 's/-[^-]\+$$//' -e 's/\+dfsg//')

# The following is a list of the non-free files that Wordpress
# ships in their archive that we will strip in get-orig-source.
UPSTREAM_FILE_BLACKLIST=wp-content/plugins/hello.php

override_dh_auto_build:
	for i in debian/languages/*.po; do \
		msgfmt $$i -o $${i%%.po}.mo; \
        done

override_dh_install:
	dh_install -Xlicense.txt -XMIT-LICENSE
	# Remove embedded libraries so that they can be replaced by symlinks
	# where appropriate
	debian/dh_linktree

get-orig-source:
	@test ! -e ../wordpress_$(VERSION)+dfsg.orig.tar.gz || (echo "You already have ../wordpress_$(VERSION)+dfsg.orig.tar.gz" >&2; exit 1)
	uscan --noconf --force-download --rename --download-version $(VERSION) --destdir=.
	tar --transform "s,^.[^/]*,wordpress-$(VERSION)/," -xzvf \
		./wordpress_$(VERSION).orig.tar.gz
	rm ./wordpress_$(VERSION).orig.tar.gz
	cd wordpress-$(VERSION) && rm $(UPSTREAM_FILE_BLACKLIST)
	tar -zcvf ../wordpress_$(VERSION)+dfsg.orig.tar.gz wordpress-$(VERSION)
	rm -rf wordpress-$(VERSION)
	@echo "Successfully created ../wordpress_$(VERSION)+dfsg.orig.tar.gz"
