#!/usr/bin/make -f

DEB_BUILD_PARALLEL = yes

# 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)
DEB_BUILD_ARCH  ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        OPTFLAGS = --disable-optimize
else
        OPTFLAGS = --enable-optimize
endif

ifneq (,$(filter ia64,$(DEB_BUILD_ARCH)))
        OPTFLAGS = --enable-optimize=-O2
endif

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	DEB_PARALLEL_JOBS ?= $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
	DEB_PARALLEL_JOBS += $(shell getconf _NPROCESSORS_ONLN)
endif
MAKEFLAGS += -j$(DEB_PARALLEL_JOBS)

BRANDING_DIR = calendar/sunbird/branding/nightly/

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

#export BUILD_OFFICIAL=1
#export MOZILLA_OFFICIAL=1

ifneq (,$(findstring s390,$(DEB_HOST_GNU_TYPE)))
        export FORCE_USE_HOST_OS=1
endif

DEB_MOZ_NAME=iceowl

DEB_CONFIGURE_USER_FLAGS= \
	--host=$(DEB_HOST_GNU_TYPE) \
	--enable-application=calendar \
	--enable-calendar \
	--disable-strip \
	--disable-strip-libs \
	--disable-install-strip \
	--disable-crashreporter \
	--disable-tests \
	--disable-mochitest \
	--enable-default-toolkit=cairo-gtk2-x11 \
	--with-default-mozilla-five-home=/usr/lib/iceowl \
	--with-system-mng=/usr \
	--with-system-jpeg=/usr \
	--with-system-zlib=/usr \
	--with-system-bz2 \
	--with-system-libevent \
	--with-system-libvpx \
	--with-system-nspr \
	--with-system-nss \
	--with-system-ply \
	--enable-system-cairo \
	--enable-system-sqlite \
	--enable-system-ffi \
	--enable-system-hunspell \
	$(OPTFLAGS) \
	--with-system-nspr \
	--with-system-nss \
	--enable-gio \
	--disable-gnomevfs \
	--enable-system-sqlite \
	--disable-necko-wifi \
	--enable-static \
	--enable-static-mail \
	--enable-chrome-format=jar \
	--disable-webm \
	--disable-ogg \
	--disable-shared \
	--disable-debug \
	--build=$(DEB_BUILD_GNU_TYPE) \
	--host=$(DEB_HOST_GNU_TYPE) \
	--with-distribution-id=org.debian

makebuilddir/iceowl::
	autoconf2.13 configure.in > configure
	cd mozilla && autoconf2.13 configure.in > configure

common-install-arch::
	make -C calendar/installer install DESTDIR=$(CURDIR)/debian/tmp
	find $(CURDIR)/debian/tmp -name .mkdir.done -exec rm -f '{}' \;

clean::
	rm -f debian/stamp-iceowl-branding debian/iceowl.js


post-patches:: debian/stamp-iceowl-branding
debian/stamp-iceowl-branding:
	cp -rLf debian/iceowl-branding/* $(BRANDING_DIR)
	sed -e "s/_UPSTREAM_VERSION_/$(DEB_UPSTREAM_VERSION)/" \
		debian/iceowl.js.in > debian/iceowl.js
	touch $@

CFLAGS=-g
CXXFLAGS=-g

export CFLAGS CXXFLAGS
