#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp

build-stamp:
	dh_testdir
	scons
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp
	scons -c
	rm -f lib/mypaintlib_wrap.cpp options.cache .sconsign.dblite debian/*.debhelper debian/*.log
	find . -type f -name "*.pyc" -exec rm -vf {} \;
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	scons prefix=/usr --install-sandbox=$(CURDIR)/debian/mypaint
	mkdir -p $(CURDIR)/debian/mypaint-data/usr/share/mypaint/brushes/
	mkdir -p $(CURDIR)/debian/mypaint-data/usr/share/mypaint/backgrounds/
	mv $(CURDIR)/debian/mypaint/usr/share/mypaint/brushes/* $(CURDIR)/debian/mypaint-data/usr/share/mypaint/brushes/
	mv $(CURDIR)/debian/mypaint/usr/share/mypaint/backgrounds/* $(CURDIR)/debian/mypaint-data/usr/share/mypaint/backgrounds/
	find $(CURDIR)/debian/mypaint/usr/share/mypaint/ -type d -empty -delete
	chmod -x $(CURDIR)/debian/mypaint/usr/share/mypaint/gui/colorsamplerwindow.py
	# Dirty workaround for broken icons. Really, upstream should be patched
	# to make this unnecessary.
	#for s in 16x16 22x22 24x24 32x32 48x48 scalable ; do \
	#  mkdir -p $(CURDIR)/debian/mypaint/usr/share/icons/hicolor/$$s/apps; \
	#done
	#for s in 16x16 22x22 24x24 32x32 48x48 scalable ; do \
	#  cp $(CURDIR)/debian/mypaint/usr/share/mypaint/desktop/$$s/*.* \
	#     $(CURDIR)/debian/mypaint/usr/share/icons/hicolor/$$s/apps/ ; \
	#done
	#mkdir -p $(CURDIR)/debian/mypaint/usr/share/pixmaps
	#cp $(CURDIR)/debian/mypaint/usr/share/mypaint/desktop/mypaint_48.png \
	#   $(CURDIR)/debian/mypaint/usr/share/pixmaps/mypaint.png
	#cp $(CURDIR)/debian/mypaint/usr/share/mypaint/desktop/mypaint.ico \
	#   $(CURDIR)/debian/mypaint/usr/share/pixmaps/

# Build architecture-independent files here.
binary-indep: install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs changelog
	dh_installdocs
	dh_installmenu
	dh_pysupport
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_icons
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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