#
#	Makefile to create a KVIrc 3 Debian package. This is only used by the
#	package maintainer normally, not as part of a dpkg-buildpackage routine.
#
NAME=kvirc3
CVSROOT=:pserver:plugin@cvs.kvirc.net:/cvs
CVS_MODULE=kvirccvs
SRC_DIR=kvirc

DEBIAN_RELEASE=1

VER=3.0.0
export VER

all::

setup::
	mv "$(SRC_DIR)/debian"       "$(SRC_DIR)/debian.jw"
	mv "$(SRC_DIR)/debian.robin" "$(SRC_DIR)/debian"

tarball::
	mv "$(SRC_DIR)/debian"       "$(SRC_DIR)/debian.robin"
	mv "$(SRC_DIR)/debian.jw"    "$(SRC_DIR)/debian"

include Makefile.generic

# Reset this to make signing the packages possible
DPKG_OPTS=-sa
export DPKG_OPTS

OPTS=$(shell grep "^OPTS=" "$(DIR)/debian/rules" | sed "s,^OPTS=,,")

setup::
	#
	#	This shouldn't be distributed
	#
	rm -rf "$(DIR)/non-dist"

	#
	#	Remove .cvsignore files
	#
	find "$(DIR)" -name .cvsignore -print0 | xargs -r0 rm

	#
	#	Copy ChangeLog to changelog
	#
	[ ! -f "$(DIR)/changelog" ] && ln "$(DIR)/ChangeLog" "$(DIR)/changelog"

	#
	#	Rename lots of files to kvirc3 conventions
	#
	mv "$(DIR)/data/applnk/kvirc.desktop"             "$(DIR)/data/applnk/kvirc3.desktop"
	mv "$(DIR)/data/icons/32x32/kvirc.png"            "$(DIR)/data/icons/32x32/kvirc3.png"
	mv "$(DIR)/data/icons/48x48/kvirc.png"            "$(DIR)/data/icons/48x48/kvirc3.png"
	mv "$(DIR)/data/man/kvirc.1"                      "$(DIR)/data/man/kvirc3.1"
	mv "$(DIR)/scripts/config/kvirc-config.in"        "$(DIR)/scripts/config/kvirc3-config.in"
	mv "$(DIR)/scripts/browser/kvi_run_netscape.sh"   "$(DIR)/scripts/browser/kvi3_run_netscape.sh"
	mv "$(DIR)/scripts/helpsearch/kvi_search_help.sh" "$(DIR)/scripts/helpsearch/kvi3_search_help.sh"
	#
	#	Create .xpm icons to satisfy Debian menu requirements
	#
	for icon in "$(DIR)"/data/icons/*/kvirc3.png; do \
		convert $$icon `echo $$icon | sed "s,png,xpm,"`; \
	done

patch::
	# Make sure we caught all references to -lkvilib
	@if (cd "$(DIR)"; find -name Makefile.am -print0 | xargs -r0 grep lkvilib | grep -v kvilib3); \
	then \
		echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; \
		echo "Please fix the above files first!"; \
		echo; \
		exit 1; \
	fi
	#
	#	Automake work should be done here, outside the Debian package
	#
	(cd "$(DIR)" && ./autogen.sh $(OPTS))

#
#	Various tracers, memory leak detectors, etc.
#
KVIRC3=$(shell which kvirc3)

mpatrol: out
	SHELL=/bin/sh; \
	cd out; mpatrol \
		--check-all \
		--log-all \
		--show-all \
		--leak-table \
		--list \
		-prof \
		--dynamic \
		--threads \
	$(KVIRC3) 2>&1 | tee out/kvirc3.$$$$.log

valgrind: out
	SHELL=/bin/sh; \
	valgrind \
		--verbose \
		--error-limit=no \
		--num-callers=5 \
		--leak-check=yes \
		--leak-resolution=low \
		--show-reachable=yes \
		--logfile-fd=67 \
		67> out/valgrind.$$$$.log \
	$(KVIRC3) 2>&1 | tee out/kvirc3.$$$$.log; \
	$(EDITOR) out/{kvirc3,valgrind}.$$$$.log

out:
	mkdir -p out

.PHONY: mpatrol valgrind
