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

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


ifeq ($(shell lsb_release -c|cut -f 2),precise)
    SUBSTVARS = -Vdist:Depends="libtcmalloc-minimal0"
else
    SUBSTVARS = -Vdist:Depends="libtcmalloc-minimal4"
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	#docbook-to-man debian/cokemulator-config-imageparser.sgml > cokemulator-config-imageparser.1

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/cokemulator-config-imageparser.
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/etc/cron.d
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/etc/init.d
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/etc/logrotate.d
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/etc/nginx/sites-enabled/
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/var/log/cokemulator-imageparser
	mkdir -p $(CURDIR)/debian/cokemulator-config-imageparser/var/cache/nginx/cache/imageparser_cache
	echo 'set $$cokemulator_imageparser_version '$(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')';' > $(CURDIR)/debian/cokemulator-config-imageparser/etc/cokemulator-imageparser.version
	sed 's#[$$]{cache_path}#/var/cache/nginx/cache/imageparser_cache#g;s#[$$]{logformat}#defaultformat#g;s#[$$]{cache_opts}#proxy_cache_lock_age 5m;#g' $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser.conf-nginx > $(CURDIR)/debian/cokemulator-config-imageparser/etc/nginx/sites-enabled/cokemulator-imageparser.conf
	cp $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser $(CURDIR)/debian/cokemulator-config-imageparser/etc/init.d
	cp $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser.conf $(CURDIR)/debian/cokemulator-config-imageparser/etc/
	cp $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser.svc.conf $(CURDIR)/debian/cokemulator-config-imageparser/etc/
	cp $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser.logrotate $(CURDIR)/debian/cokemulator-config-imageparser/etc/logrotate.d
	cp $(CURDIR)/../../rpm/cokemulator-config/src/cokemulator-imageparser.logrotate-nginx $(CURDIR)/debian/cokemulator-config-imageparser/etc/logrotate.d


# 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
	dh_installdocs
	dh_installexamples
#	dh_install
#	dh_installmenu
#	dh_installdebconf
#	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_makeshlibs
	dh_installdeb
	#dh_shlibdeps
	dh_gencontrol -- $(SUBSTVARS)
	dh_md5sums
	dh_builddeb

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

