#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for openstreetmap-map-icons that uses debhelper.

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

SVNREPO := http://svn.openstreetmap.org/applications/share/map-icons
DATE := $(shell date +%Y%m%d)
VERSION := 0.0.svn${SVNREV}
DESTDIR := ../tarballs/openstreetmap-map-icons-${VERSION}
DESTTGZ := ../tarballs/openstreetmap-map-icons_${VERSION}.orig.tar.gz

build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: 
	touch $@

build-indep: build-indep-stamp
build-indep-stamp: 
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-arch-stamp build-indep-stamp
	dh_clean

install: install-indep install-arch
install-indep:
	dh_testdir
	dh_testroot
	dh_clean -k -i
	dh_installdirs -i
	dh_install -i
	for i in classic scalable square ; do \
		find $(CURDIR)/debian/openstreetmap-map-icons-$$i/usr/share/icons/openstreetmap/ -type d -empty -delete ; \
		find $(CURDIR)/debian/openstreetmap-map-icons-$$i/usr/share/icons/openstreetmap/ -type f | xargs chmod 644 ; \
	done

install-arch:

binary-common:
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	for i in classic.small classic.big square.small square.big scalable ; do \
		dh_link usr/share/icons/openstreetmap/$$i usr/share/doc/openstreetmap-map-icons-classic/examples/$$i ; \
	done
	dh_compress
	dh_fixperms 
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture independant packages using the common target.
binary-indep: build-indep install-indep
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build-arch install-arch

binary: binary-arch binary-indep

get-orig-source:
	dh_testdir
	test -d ../tarballs/. || mkdir -p ../tarballs
	@echo Downloading openstreetmap-map-icons from $(SVNREPO)
	svn -r $(SVNREV) export $(SVNREPO) $(DESTDIR)
	@echo Removing directories: debian nickw japan
	rm -rf $(DESTDIR)/debian
	rm -rf $(DESTDIR)/nickw
	rm -rf $(DESTDIR)/japan
	@echo Building snapshot tarball
	tar czf $(DESTTGZ) -C `dirname $(DESTDIR)` `basename $(DESTDIR)`
	@echo Cleaning up
	rm -rf $(DESTDIR)
	@echo .
	@echo To update debian/changelog type
	@echo dch -v $(VERSION)-1
	@echo .

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