#!/usr/bin/make -f

destd=$(CURDIR)/debian/storebackup/
base_shared=usr/share/storebackup/
base_bin=usr/bin/
shared=$(destd)/$(base_shared)
bin=$(destd)/$(base_bin)

CMD=$(shell echo $@ | sed 's/^override_//')

%:
	dh $@

clean:
	dh $@
	rm -fr debian/man/

override_dh_install:
	$(CMD)
	for file in $(shared)/bin/*; \
	  do chmod 755 $$file; \
	  mv $$file $(shared)/bin/`basename $$file .pl`; \
	  dh_link $(base_shared)/bin/`basename $$file .pl` $(base_bin)/`basename $$file .pl`; \
	done

	rm -f $(bin)/multitail
	chmod 644 $(shared)/lib/*
	for file in $(shared)/lib/*; do \
	  if head -1 $$file | grep -q "#!"; then \
	    chmod +x $$file; \
	  fi \
	done

override_dh_installchangelogs:
	$(CMD) doc/ChangeLog

override_dh_installexamples:
	[ ! -f storeBackup_example ] || rm -f storeBackup_example
	/usr/bin/perl bin/storeBackup.pl -g storeBackup_example
	$(CMD)

override_dh_installcron:
	[ -f debian/storebackup.cron.daily ] || cp cron-storebackup debian/storebackup.cron.daily
	$(CMD)

override_dh_compres:
	$(CMD) -X storeBackup_example

override_dh_installman:
	rm -fr debian/man
	mkdir -p debian/man
	for file in $(bin)/*; do \
	  file=$$(basename $$file); \
	  pod2man $(bin)/$$file > debian/man/$$file.1; \
	done
	$(CMD)

