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

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

CFLAGS = -Wall -g
AUTOMAKE = automake-1.9

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp: 
	dh_testdir
	# Add here commands to configure the package.
	autoreconf -f # -i -s 
	AUTOMAKE=/bin/true ACLOCAL=/bin/true AUTOCONF=/bin/true ./configure  --enable-xarlib --enable-filters

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Unused file, conflicts with libjpeg-turbo
	rm -f wxOil/jconfig.h
	# Add here commands to compile the package.
	make
	#docbook-to-man debian/xaralx.sgml > xaralx.1

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	[ ! -f Makefile ] || $(MAKE) clean
	[ ! -f Makefile ] || $(MAKE) -C xarlib clean
	rm -rf xarlib/.deps/
	rm -f xarlib/Xar.pc
	find -name '*.Po' -delete
	find -name Makefile -delete
	rm -f config.log config.status libtool
	rm -f filters/SVGFilter/config.log filters/SVGFilter/config.status filters/SVGFilter/libtool
	rm -f po/POTFILES po/Makefile.in po/XaraLX.pot po/stamp-po
	find -name Makefile.in -delete
	find -name configure -delete
	find -name aclocal.m4 -delete

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs
	
	# Add here commands to install the package into debian/xaralx.
	install -m 775 XaraLX $(CURDIR)/debian/xaralx/usr/bin/xaralx
	install -m 664 xaralx.desktop $(CURDIR)/debian/xaralx/usr/share/applications/xaralx.desktop
	install -m 664 xaralx.xpm  $(CURDIR)/debian/xaralx/usr/share/pixmaps/xaralx.xpm
	install -m 664 xaralx.png  $(CURDIR)/debian/xaralx/usr/share/pixmaps/xaralx.png
	
	# libxar-dev files
	DESTDIR=$(CURDIR)/debian/libxar-dev make -C xarlib install
	
	# xaralx-svg files
	DESTDIR=$(CURDIR)/debian/xaralx-svg make -C filters/SVGFilter 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 ChangeLog
	dh_installdocs
	dh_installexamples
	# Fixing examples permissions
	chmod 644 $(CURDIR)/debian/xaralx-examples/usr/share/doc/xaralx-examples/examples/*.xar
#	dh_install
	dh_installmenu
#	dh_installmime
	dh_installman 
	dh_link
	dh_strip
	dh_compress -X.xar
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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