#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	# We can't use dh_auto_configure here; the cmake way is too complicated for it
	mkdir -p build_release
	# The -DCMAKE_INSTALL_LIBDIR=lib is to disable multiarch builds on debian/ubuntu; the official packages do so, so it avoids much confusion if we do too
	(cd build_release && cmake -Wno-dev -G "Unix Makefiles" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=debugfull -DAUTOGEN_REVISION=0 -DPREVENT_WX_ASSERTS=1  -DCOPY_WX_LIBS=1 ..)

	touch configure-stamp

build: build-stamp
build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	(cd build_release && $(MAKE) -j2  DEBUG=" -g3 -ggdb")

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
# Don't uncomment the next line, otherwise it breaks the initial debuild clean (as there's no makefile at that stage)
	#$(MAKE) clean
	#$(MAKE) distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep

	# Add here commands to install the package into debian/<packagename>
	(cd build_release && $(MAKE) DESTDIR=$(CURDIR)/debian/codelite install)

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_install
	
	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installcatalogs
#	dh_installpam
	dh_installmime
	dh_icons
#	dh_installinit
#	dh_installcron
#	dh_installinfo
#	dh_installwm
#	dh_installudev
#	dh_lintian
#	dh_bugfiles
#	dh_undocumented
	dh_installman debian/codelite.1
	dh_link
	dh_strip --dbg-package=codelite-dbg
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	
	# We don't want to depend on a particular xserver, and dh_shlibdeps fails (slowly!) to work in .so files e.g. the CL plugins
	dh_shlibdeps --exclude=nvidia-current  --exclude=nouveau --exclude=*.so
	# or on the unofficial wx3.0 libs (as we build them into the CodeLite package)
	# However --exclude would remove all the dependencies of wx too, so filter by hand
	# (Re)do nvidia etc too, as some versions of dh_shlibdeps fail to --exclude
	# and, for wx git builds, anything with the git version in: for CL13 substvars somehow
	# decided that there was a 'libstdc++6 (>= 6)63c2eaf524gtk2'
	if [ -f ./debian/codelite.substvars ]; then \
		sed -i 's|, libwx.*-unofficial||g' ./debian/codelite.substvars; \
		sed -i 's|, libwx.*-git||g' ./debian/codelite.substvars; \
		sed -i 's|63c2eaf524gtk[1-9]||g' ./debian/codelite.substvars; \
		sed -i 's|, nvidia.*||g' ./debian/codelite.substvars; \
	fi
	
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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