#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatability version to use.
#export DH_COMPAT=5
export destdir = $(CURDIR)/debian/openstreetmap-map-icons

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	rm -f CMakeCache.txt
	mkdir -p build
	cd build; cmake ..
#	cd build; cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DMAN_INSTALL_DIR=/usr/share/man -DINFO_INSTALL_DIR=/usr/share/info ..

	touch configure-stamp


clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	#-cd build; $(MAKE) distclean
	rm -f build/CMakeCache.txt
	rm -f build/Makefile
	rm -f build/cmake_install.cmake
	rm -f build/icons.xml
	rm -rf build/CMakeFiles
	rm -rf build/classic.big
	rm -rf build/classic.small
	rm -rf build/japan
	rm -rf build/svg_png
	rm -rf build/square.big
	rm -rf build/square.small
	rm -rf build/svg
	rm -rf build/japan_png
	rm -rf build/svg-twotone
	rm -rf build/svg-twotone_png
	rm -rf build/nickw
	dh_clean
	dh_clean -k

install:
	dh_testdir
	dh_testroot
	dh_installdirs

#       ../../utils/svn/svn_log2debian_changelog.pl --project_name="openstreetmap-map-icons"
	rm -f debian/files

	# Add here commands to compile the package.
	mkdir -p build
	cd build; cmake ..
	cd build; $(MAKE)

	touch build-stamp

	cp -u icons.xml build/
	cp -u icons.dtd build/
	# We do not want to change the ixons.xml automagically for now anymore
#	cd build; perl ../tools/update_icons.pl


	# Create geoinfo.*.db
	cd build; perl ../tools/create_geoinfo-db.pl --lang=en --source=icons.xml
	cd build; perl ../tools/create_geoinfo-db.pl --lang=de --source=icons.xml

	# Now split into differnet packages
	perl ./tools/copy_icons_to_debian_package_dirs.pl

	# Create Mini Icon Set
	mkdir -p debian/openstreetmap-map-icons-square.small-minimal/usr/share/icons/map-icons/square.small
	cp debian/openstreetmap-map-icons-square.small/usr/share/icons/map-icons/square.small/*.png debian/openstreetmap-map-icons-square.small-minimal/usr/share/icons/map-icons/square.small

	mkdir -p debian/openstreetmap-map-icons/usr/share/icons/map-icons/

	# Create a seperate Overview Package
	mkdir -p debian/openstreetmap-map-icons-info/usr/share/icons/map-icons/

	# This is not really FSH, but i didn't want to create a new directory
	cp build/icons.xml debian/openstreetmap-map-icons-info/usr/share/icons/map-icons/
	cp build/icons.dtd debian/openstreetmap-map-icons-info/usr/share/icons/map-icons/

	cp build/geoinfo.db debian/openstreetmap-map-icons/usr/share/icons/map-icons/
	cp build/geoinfo.de.db debian/openstreetmap-map-icons/usr/share/icons/map-icons/

	# icons.xml belongs to the main package
	perl ./tools/create_overview.pl -D debian/openstreetmap-map-icons-info/usr/share/icons/map-icons/ 
	perl ./tools/create_overview.pl -D debian/openstreetmap-map-icons-info/usr/share/icons/map-icons/ -l -n -b -P overview_lic


#	cd build; $(MAKE)
#	cd build; $(MAKE) DESTDIR=$(destdir) install

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdebconf
#	dh_installdocs
#	dh_installexamples
	dh_installmenu
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installman
#	dh_link
	dh_strip
	dh_compress 
	dh_fixperms
#	dh_perl
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

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