#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/langcore.mk

# 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)

# Define the build directory variable for each package,
# as required for multiple VPATH builds with CDBS.
$(foreach pkg,$(DEB_ARCH_PACKAGES),$(eval DEB_BUILDDIR_$(pkg) = build/$(pkg)))

CXXFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -O0 -fno-exceptions
else
	CXXFLAGS += -O2 -fno-exceptions
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

autogen:
	libtoolize --force --copy
	aclocal-1.10 -I scripts
	automake-1.10 --copy --add-missing
	autoconf2.50

DEB_CONFIGURE_EXTRA_FLAGS_glom-sqlite = --enable-sqlite --disable-postgresql

$(DEB_ARCH_PACKAGES:%=build/%/config.status):build/%/config.status:
	cd "build/$*" && "$(CURDIR)/configure" \
		--srcdir="$(CURDIR)" \
		--build="$(DEB_BUILD_GNU_TYPE)" $(subst \
		--host="$(DEB_BUILD_GNU_TYPE)",,--host="$(DEB_HOST_GNU_TYPE)") \
		--prefix=/usr --sysconfdir=/etc --localstatedir=/var \
		--libexecdir='$${libdir}/$(DEB_SOURCE_PACKAGE)' \
		--disable-dependency-tracking $(DEB_CONFIGURE_EXTRA_FLAGS_$*) \
		--enable-maemo --enable-doc-utils=no --enable-warnings=minimum $(conf_opt) \
		CC="$(CC)" CXX="$(CXX)" \
		CPPFLAGS="$(CPPFLAGS)" \
		CFLAGS="$(strip $(CFLAGS) $(CFLAGS_$*))" \
		CXXFLAGS="$(strip $(CXXFLAGS) $(CFLAGS_$*))" \
		LDFLAGS="$(LDFLAGS)" \
		PYTHON="/usr/bin/python2.5"

# Simply use the compiled executable as the rule target
# to avoid the need for a stamp file.
$(DEB_ARCH_PACKAGES:%=build/%/glom/glom):build/%/glom/glom:
	+$(MAKE) -C "build/$*"
 
# Append to the double-colon rule hooks provided by CDBS.
 
$(addprefix configure/,$(DEB_ARCH_PACKAGES))::configure/%: build/%/config.status
 
$(addprefix build/,$(DEB_ARCH_PACKAGES))::build/%: build/%/glom/glom
 
$(addprefix install/,$(DEB_ARCH_PACKAGES))::install/%:
	+$(MAKE) -C "build/$*" DESTDIR="$(CURDIR)/debian/$*" install
 
$(addprefix binary-install/,$(DEB_ARCH_PACKAGES))::binary-install/%:
	dh_desktop -p"$*" $(DEB_DH_DESKTOP_ARGS)
	#dh_icons -p"$*" $(DEB_DH_ICONS_ARGS)
 
# Cleanup is a no-brainer thanks to the VPATH setup.
cleanbuilddir::
	rm -rf buildbuild: build-stamp
	rm -rf build
