#!/usr/bin/make -f

PACKAGE=amide

# quilt
DEB_SOURCE_PACKAGE:=$(PACKAGE)
include /usr/share/quilt/quilt.make


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


# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


# FOR AUTOCONF 2.52 AND NEWER ONLY
CONFFLAGS =
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  CONFFLAGS += --build $(DEB_HOST_GNU_TYPE)
else
  CONFFLAGS += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

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

get-orig-source:
	uscan --verbose --force-download

configure: configure-stamp
configure-stamp: $(QUILT_STAMPFN)
	dh_testdir

	chmod +x debian/autogen.sh
	debian/autogen.sh

	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .
	rm -f config.cache

	./configure CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" \
		$(CONFFLAGS) \
		--disable-amide-debug \
		--config-cache \
		--disable-dependency-tracking \
		--enable-rpm-install \
		--prefix=/usr \
		--localstatedir=/var/lib/amide \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--localstatedir=/var/lib/amide \
		LDFLAGS="-Wl,-z,defs"

	touch $@


build: build-arch

build-arch: build-arch-stamp

build-arch-stamp: configure
	dh_testdir

	$(MAKE)

	touch $@


clean: clean-patched unpatch

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

	[ ! -f Makefile ] || $(MAKE) clean
	[ ! -f Makefile ] || $(MAKE) distclean


	find \( -name config.sub -o -name config.guess \) -print0 | xargs -0 -r rm -f \;
	find -name Makefile.in | xargs rm -f
	- rm configure ltmain.sh aclocal.m4 m4/intltool.m4 m4/libtool.m4 po/Makefile.in.in
	- rm config.log intltool-merge.in intltool-extract.in intltool-update.in

	# Fix permissions
	if [ -r debian/executable.files ] ; then \
		find -type d -print0 | xargs -0 -r chmod 755 ;\
		find -type f ! -name 'rules' -print0 | xargs -0 -r chmod 644 ;\
		xargs -t -r chmod +x < debian/executable.files ;\
	fi

	# Final static cleanups
	if [ -r debian/deletable.files ] ; then \
		xargs -t -r rm -f < debian/deletable.files ;\
	fi


	dh_clean 


install: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_prep
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/amide install
	install -d debian/amide/usr/share/pixmaps
	cp debian/amide_logo_small.xpm debian/amide/usr/share/pixmaps/amide_logo_small.xpm
	rm -rf debian/amide/var

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_installmenu
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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