#!/usr/bin/make -f
# -*- mode: makefile; indent-tabs-mode: t -*- vim:noet:ts=4

#export DH_VERBOSE=1

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

DEB_SCONS_BUILD_OPTIONS := --prefix=/usr
DEB_SCONS_INSTALL_OPTIONS := $(DEB_SCONS_BUILD_OPTIONS) --install-sandbox=$(DEB_DESTDIR)

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CXXFLAGS += -g
endif

LITTLE_ENDIAN_ARCHS := "alpha amd64 arm hurd-i386 i386 ia64 mipsel sh3 sh4"
BIG_ENDIAN_ARCHS := "hppa m68k mips powerpc ppc64 sparc s390"

ifneq (,$(findstring $(DEB_BUILD_ARCH), $(LITTLE_ENDIAN_ARCHS)))
	BUILD_ENDIANNESS := le
endif

ifneq (,$(findstring $(DEB_BUILD_ARCH), $(BIG_ENDIAN_ARCHS)))
	BUILD_ENDIANNESS := be
endif

ifneq (,$(findstring $(DEB_HOST_ARCH), $(LITTLE_ENDIAN_ARCHS)))
	HOST_ENDIANNESS := le
endif

ifneq (,$(findstring $(DEB_HOST_ARCH), $(BIG_ENDIAN_ARCHS)))
	HOST_ENDIANNESS := be
endif

# ifneq ($(HOST_ENDIANNESS),$(BUILD_ENDIANNESS))
# 	$(error cross-compiling not supported so far\; cannot continue)
# endif

SUNPINYIN_DATA_DEPENDS=sunpinyin-data-$(HOST_ENDIANNESS)
DEB_DH_MAKESHLIBS_ARGS := -n
DEB_DH_GENCONTROL_ARGS := -u'-Vsunpinyin-data-depends=$(SUNPINYIN_DATA_DEPENDS)'

binary-fixup/sunpinyin-data-le::
	for f in pydict_sc.bin lm_sc.t3g ; do \
		cp -f $(CURDIR)/data/$$f.le \
		$(CURDIR)/debian/sunpinyin-data-le/usr/lib/sunpinyin/data/$$f; \
	done

binary-fixup/sunpinyin-data-be::
	for f in pydict_sc.bin lm_sc.t3g ; do \
		cp -f $(CURDIR)/data/$$f.be \
		$(CURDIR)/debian/sunpinyin-data-be/usr/lib/sunpinyin/data/$$f; \
	done

