#!/usr/bin/make -f
################################################################################
# LibreOffice source package rules file
#
# Please see debian/README for detailed documentation about the build system, and
# how to build LibreOffice.
################################################################################
# Authors:
# Chris Halls <halls@debian.org>
# Rene Engelhard <rene@debian.org>
# Copyright 2002-2013 Software in the Public Interest, Inc.
# Portions Copyright 2010 Canonical Ltd. Author: Matthias Klose
# Portions Copyright 2011-2013 Canonical Ltd. Author: Bjoern Michaelsen
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
################################################################################

vafilt = $(subst $(2)=,,$(filter $(2)=%,$(1)))

include /usr/share/dpkg/pkg-info.mk
CURDIR ?= $(realpath $(dir $(firstword $(MAKEFILE_LIST)))/..)
BASE_VERSION:=$(shell echo $(DEB_VERSION) | cut -d: -f1):$(DEB_VERSION_UPSTREAM)
BINARY_VERSION=$(DEB_VERSION)
#HELP_L10N_VIRTUAL_VERSION:=$(shell echo $(DEB_VERSION_UPSTREAM) | cut -d: -f2 | tr [~] [\\-])
HELP_L10N_VIRTUAL_VERSION:=4.3
OOVER:=4.3
NEXT_OOVER:=$(shell echo "$(OOVER) + 0.1" | bc)

ARCH_INDEP_PACKAGES := $(shell dh_listpackages -i)
ARCH_DEP_PACKAGES := $(shell dh_listpackages -s)
PACKAGES := $(ARCH_INDEP_PACKAGES) $(ARCH_DEP_PACKAGES)

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/vendor.mk
SHELL:=/bin/bash
export gb_SHELL:=$(SHELL)

SYSTEM_GCC_VERSION = $(shell gcc --version | sed -n '/^gcc/s/.*\(.\..\)\..$$/\1/p')
SYSTEM_GCJ_VERSION = $(shell basename `readlink /usr/lib/jvm/java-gcj/bin/gcj` | sed -e s/gcj-//)

PKGDIR:=debian/libreoffice
OODIRNAME=libreoffice
OODIR:=usr/lib/$(OODIRNAME)
OOUREDIR:=usr/lib/ure
OOSDKDIR:=$(OODIR)/sdk

# Figure out who's building this package.
OOO_VENDOR:=The Document Foundation/Debian
ifeq "$(DEB_VENDOR)" "Ubuntu"
OOO_VENDOR=The Document Foundation, Debian and Ubuntu
endif
export OOO_VENDOR

# debhelper
export DH_OPTIONS
export DH_ALWAYS_EXCLUDE=CVS:.svn:.bzr:.git
#export DH_VERBOSE=1
# quilt
export QUILT_PATCHES=debian/patches
export QUILT_OPTIONS="-p1 -F0"

SOURCE_TREE=.
STAMP_DIR=debian/stampdir
TARFILE_LOCATION=$(CURDIR)/external/tarballs
export TARFILE_LOCATION
USE_SOURCE_TARBALLS=n
USE_GIT_TARBALLS=n
ifeq "$(USE_GIT_TARBALLS)" "y"
GIT_BASEURL:=git://anongit.freedesktop.org/libreoffice
lo_sources_ver=$(shell grep AC_INIT $(SOURCE_TREE)/configure.ac | grep documentfoundation | cut -d, -f2 | sed -e 's,\[,,' -e 's,\],,')
# NOT in proper libreoffice-3-6 branch
# use ./g checkout -b tag-libreoffice-3.6.2.1 libreoffice-3.6.2.1
GIT_TAG=libreoffice-$(lo_sources_ver)
GIT_BRANCH=libreoffice-4-3-3
endif
ifeq "$(USE_SOURCE_TARBALLS)" "y"
lo_sources_ver=$(shell cat $(CURDIR)/sources.ver | cut -d= -f2)
endif

#########
# Default package configuration
#
OOO_ARCHS = alpha amd64 armel armhf hppa i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc powerpcspe ppc64 s390 s390x sparc
PATCHSET=$(DEB_VENDOR)
BUILD_DEPS=\
    autoconf,\
    automake,\
    bc,\
    bison,\
    bzip2,\
    dpkg-dev (>= 1.16.1),\
    fastjar,\
    flex (>= 2.3.35), \
    gperf,\
    libarchive-zip-perl,\
    libc0.1 (>= 2.10.2-7) [kfreebsd-i386 kfreebsd-amd64],\
    libcups2-dev,\
    libfontconfig1-dev,\
    libfreetype6-dev (>= 2.2.0),\
    libice-dev,\
    libsm-dev,\
    libx11-dev,\
    libxaw7-dev,\
    libxext-dev,\
    libxinerama-dev,\
    libxkbfile-dev,\
    libxrender-dev,\
    libxt-dev,\
    libxtst-dev,\
    pkg-config,\
    unzip,\
    x11proto-render-dev,\
    xsltproc,\
    zip,\
    zlib1g-dev\


CHECKTARGET:=check
# These are components which can be built from internal copies, or used from the
# distribution. See configure --help for valid values (--with-system-<value>).
SYSTEM_STUFF = dicts

ENABLE_PYTHON=y
ENABLE_PYTHON2=y
ifeq "$(ENABLE_PYTHON)" "y"
  ENABLE_SCRIPT_PROVIDER_PYTHON=y
  PACKAGE_LIBRELOGO=y
endif
# THIS IS ONLY FOR TESTING. When building against a specified pythonX.Y
# this will work inside OOo but *not* from outside OOo unless the user
# uses pythonX.Y directly (and the dh_pycentral-created dependencies allow
# also the non-working default python then) - see e.g. #587402. Also
# note we are NOT working with python < 2.6 anymore!
PYTHON_VERSION=current
ifeq "$(PYTHON_VERSION)" "current"
  PYTHON=python3
export PYTHON=python3
else
  PYTHON=python$(PYTHON_VERSION)
export PYTHON=python$(PYTHON_VERSION)
endif
ifeq "$(ENABLE_PYTHON2)" "y"
	PYTHON2_VERSION=current
  ifeq "$(PYTHON2_VERSION)" "current"
	PYTHON2=python
  else
	PYTHON2=python$(PYTHON2_VERSION)
  endif
endif
PACKAGE_TTF_OPENSYMBOL=y
BUILD_ONLY_EN_US=n
ENABLE_JAVA=y
ifeq "$(ENABLE_JAVA)" "y"
  ifneq "$(WHEEZY_BACKPORT)" "y"
    JDK=default
    include /usr/share/java/java_defaults.mk
  else
    JDK=openjdk
  endif
  ifneq "$(JDK)" "default"
    JAVA_MAINVER=7
    ifeq "$(WHEEZY_BACKPORT)" "y"
      ifneq (,$(filter hppa kfreebsd%, $(DEB_HOST_ARCH)))
      JDK=gcj-jdk
      endif
    else
      ifneq (,$(filter hppa, $(DEB_HOST_ARCH)))
      JDK=gcj-jdk
      endif
    endif
  endif
endif
JAVAHELPER_MIN_VERSION= (>= 0.37~)
SYSTEM_STUFF += hunspell
HUNSPELL_MIN_VER= (>= 1.1.5-2)
SYSTEM_STUFF += altlinuxhyph
USE_LIBHYPHEN=y
LIBALTLINUXHYPH_MINVER= (>= 0.1.1-11)
LIBHYPHEN_MINVER= (>= 2.4)
SYSTEM_STUFF += boost
BOOST_VERSION=default
ifeq "$(BOOST_VERSION)" "default"
  ifeq "$(shell dpkg --compare-versions $(SYSTEM_GCC_VERSION) ge 4.8 && echo true)" "true"
    BOOST_MINVER= (>= 1.53)
  else
    ifneq "$(WHEEZY_BACKPORT)" "y"
    BOOST_MINVER= (>= 1.49.0-4)
    else
    BOOST_MINVER= (>= 1.47)
    endif
  endif
endif
SYSTEM_STUFF += mdds
SYSTEM_STUFF += vigra
USE_EXTERNAL_CXXLIBS=y
SYSTEM_STUFF += mythes
SYSTEM_STUFF += icu
ICU_MINVER= (>= 4.6)
SYSTEM_STUFF += librevenge
SYSTEM_STUFF += libwpd libwpg libwps
SYSTEM_STUFF += libvisio
SYSTEM_STUFF += libcdr
SYSTEM_STUFF += libmspub
SYSTEM_STUFF += libmwaw
SYSTEM_STUFF += libodfgen
SYSTEM_STUFF += libetonyek
SYSTEM_STUFF += libfreehand
# this is libe-book, NOT evolutions libebook (which is
# dlopen()'ed anyway and whose headers we need from the
# system anyways if enabled
SYSTEM_STUFF += libebook
SYSTEM_STUFF += libabw
BUILD_CAIROCANVAS=y
SYSTEM_STUFF += cairo
CAIRO_FONTS_PATCH=y
BUILD_KDE=y
# not ported to KDE 4
ENABLE_KDEAB=n
ifeq "$(shell dpkg --compare-versions $(SYSTEM_GCC_VERSION) ge 4.7 && echo true)" "true"
# < 4.8 fails with gcc 4.7, see #667911
QT_MINVER= (>= 4:4.8)
else
QT_MINVER= (>= 4:4.5)
endif
KDELIBS_MINVER= (>= 4:4.3.4)
BUILD_DBG_PACKAGE=y
ifneq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  BUILD_TEST_PACKAGE=y
endif
ifeq "$(BUILD_TEST_PACKAGE)" "y"
  BUILD_DBG_PACKAGE=y
endif
ifeq "$(BUILD_DBG_PACKAGE)" "y"
  ENABLE_SYMBOLS=y
  SMALL_SYMBOLS=y
endif
ifeq "$(ENABLE_JAVA)" "y"
  # NOTE: If you change this while gcj/ant multiarch combo is still broken
  # you need to disable bsh scripting engine completely (see disable-rhino.diff)
  # See http://lists.debian.org/debian-java/2011/06/msg00108.html and replies
  SYSTEM_STUFF += beanshell
  SYSTEM_STUFF += hsqldb
  HSQLDB_MINVER= (>> 1.8.0.10)
  HSQLDB_TOONEWVER=1.8.1
  ifeq "$(WHEEZY_BACKPORT)" "y"
    HSQLDB_JAR=/usr/share/java/hsqldb.jar
  else
    HSQLDB_JAR=/usr/share/java/hsqldb1.8.0.jar
  endif
endif
SYSTEM_STUFF += lpsolve
USE_SHARED_LPSOLVE=y
LPSOLVE_MIN_VERSION= (>= 5.5.0.13-5+b1)
ENABLE_COINMP=y
SYSTEM_STUFF += coinmp
USE_DBUS=y
ifeq "$(USE_DBUS)" "y"
  ifneq (,$(findstring kfreebsd,$(DEB_HOST_ARCH)))
    ENABLE_BLUETOOTH=n
  else
    ENABLE_BLUETOOTH=y
    SYSTEM_STUFF += bluez
  endif
endif
#22:47 < siqi_> I think the best thing to do now is to disable avahi completely since it doesn't work anyway..
#[...]
#22:56 <@_rene_> I don't care much about the dependency..
#22:57 <@_rene_> but those two bugs are bad.
#22:57 < siqi_> I know but I'm actually not sure about wether avahi was working proprely for now
#22:57 <@_rene_> ok
#[...]
#22:58 <@_rene_> so I disable it in all branches I have for now
#22:58 < siqi_> I think it's safe to disable it for now
ENABLE_AVAHI=n
USE_GSTREAMER=y
ifneq "$(WHEEZY_BACKPORT)" "y"
  GSTREAMER_VERSION=1.0
else
   GSTREAMER_VERSION=0.10
endif
USE_VLC=y
ENABLE_WEBDAV=y
ifeq "$(ENABLE_WEBDAV)" "y"
WEBDAV_LIB=neon
  ifeq "$(WEBDAV_LIB)" "neon"
    SYSTEM_STUFF += neon
    NEON_SECTYPE=gnutls
    NEONSONR=27
  else
   SYSTEM_STUFF += apr
   SYSTEM_STUFF += serf
  endif
endif
SYSTEM_STUFF += redland
PACKAGE_SDK=y
PACKAGE_SDK_DOCS=y
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(JDK)" "default"
    ifeq "$(shell LANG=C /usr/lib/jvm/default-java/bin/java -version 2>&1 | tail -n 1 | awk '{ print $$1 }')" "OpenJDK"
      RUN_MAKE_CHECK=y
      RUN_PYTESTS=y
      ifeq "$(DEB_HOST_ARCH)" "i386"
	ENABLE_JUNIT4=y
      endif
      ifeq "$(DEB_HOST_ARCH)" "amd64"
	ENABLE_JUNIT4=y
      endif
    endif
  else
    ifeq "$(JDK)" "openjdk"
      RUN_MAKE_CHECK=y
      RUN_PYTESTS=y
      ifeq "$(DEB_HOST_ARCH)" "i386"
	ENABLE_JUNIT4=y
      endif
      ifeq "$(DEB_HOST_ARCH)" "amd64"
	ENABLE_JUNIT4=y
      endif
    else
      RUN_MAKE_CHECK=n
      ENABLE_JUNIT4=n
      RUN_PYTESTS=n
      BUILD_TEST_PACKAGE=n
    endif
  endif
  ifneq (,$(findstring arm,$(DEB_HOST_ARCH)))
    export DISABLE_CVE_TESTS=TRUE
  endif
  ifneq (,$(findstring powerpc,$(DEB_HOST_ARCH)))
    export DISABLE_CVE_TESTS=TRUE
  endif
  ifneq (,$(findstring ppc,$(DEB_HOST_ARCH)))
    export DISABLE_CVE_TESTS=TRUE
  endif
  ifneq (,$(findstring s390,$(DEB_HOST_ARCH)))
    export DISABLE_CVE_TESTS=TRUE
  endif
else
  RUN_MAKE_CHECK=n
  ENABLE_JUNIT4=n
  BUILD_TEST_PACKAGE=n
endif
ifeq "$(ENABLE_JUNIT4)" "y"
  JUNIT_MIN_VER= (>= 4.8.2-2)
endif
USE_LIBCURL4=y
CURL_SECTYPE=gnutls
USE_LIBSUITESPARSE=y
SUITESPARSE_MIN_VERSION= (>= 1:3.4.0)
PARALLEL_BUILD=y
ENABLE_LDAP=y
USE_OPENLDAP=y
# --enable/-disable-opengl just affects OGLTrans...
ENABLE_OPENGL=y
SYSTEM_STUFF += glew
# this is also not affected by --enable/-disable-opengl but at least has an
# own --enable/--disable...
ENABLE_GLTF=y
SYSTEM_STUFF += libgltf
ifeq "$(ENABLE_GLTF)" "y"
  ENABLE_COLLADA=n
endif
SYSTEM_STUFF += openssl
ifeq "$(ENABLE_JAVA)" "y"
  ENABLE_REPORTDESIGN=y
  SYSTEM_STUFF += jfreereport
  ENABLE_MEDIAWIKI=y
  SYSTEM_STUFF += apache-commons
  ENABLE_SCRIPT_PROVIDER_BSH=y
  ENABLE_SCRIPT_PROVIDER_JS=y
else
  ENABLE_REPORTDESIGN=n
  ENABLE_MEDIAWIKI=n
  ENABLE_SCRIPT_PROVIDER_BSH=n
  ENABLE_SCRIPT_PROVIDER_JS=n
endif
ENABLE_SDBC_POSTGRESQL=y
BUILD_GTK=y
#ifeq "$(DEB_DISTRIBUTION)" "experimental"
BUILD_GTK3=y
#endif
ENABLE_EVO2=y
ENABLE_GVFS=n
ENABLE_GCONF=y
ENABLE_GIO=y
ENABLE_RANDR=y
ifeq "$(BUILD_GTK)" "y"
  PACKAGE_NSPLUGIN=y
endif
SYSTEM_STUFF += npapi-headers
PACKAGE_BASE=y
ENABLE_GRAPHITE=y
SYSTEM_STUFF += graphite
SYSTEM_STUFF += harfbuzz
ALLOC=system
SYSTEM_STUFF += libexttextcat
SYSTEM_STUFF += cppunit
DEFAULT_IMAGE=galaxy
IMAGES:=crystal default $(DEFAULT_IMAGE) hicontrast oxygen tango sifr
ENABLE_MYSQLNATIVE=y
USE_MARIADB=n
# set this also to y for system-mysql..
SYSTEM_STUFF += mariadb
SYSTEM_STUFF += mysql-cppconn
MYSQLCPPCONN_MINVER= (>= 1.1.0~r791)
SYSTEM_STUFF += postgresql
DICT_DIR=/usr/share/hunspell
HYPH_DIR=/usr/share/hyphen
THES_DIR=/usr/share/mythes
SYSTEM_STUFF += libcmis
SYSTEM_STUFF += jpeg
SYSTEM_STUFF += libxml
SYSTEM_STUFF += expat
SYSTEM_STUFF += odbc
SYSTEM_STUFF += curl
SYSTEM_STUFF += sane
SYSTEM_STUFF += mesa-headers
SYSTEM_STUFF += poppler
SYSTEM_STUFF += libpng
SYSTEM_STUFF += nss
SYSTEM_STUFF += clucene
ENABLE_HELP=y
SYSTEM_STUFF += lcms2
SYSTEM_STUFF += openldap
PACKAGE_UNOWINREG_DLL=y
ifeq "$(DEB_VENDOR)" "Debian"
BUILD_UNOWINREG_DLL=y
endif
FAKEROOT_LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/libfakeroot
# upstream says: "it's 'highly experimental'", I wouldn't enable it for
# distros"
ENABLE_TELEPATHY=n
ENABLE_LIBLANGTAG=y
SYSTEM_STUFF += liblangtag
ENABLE_ORCUS=y
SYSTEM_STUFF += orcus
USE_UCPP=y
ifeq "$(USE_UCPP)" "y"
  SYSTEM_STUFF += ucpp
endif
ENABLE_MERGELIBS=n
USE_OPENCL=y
#10:15 <@_rene_> ahunt: I remember you wanted to do some endian things? did it 
#                ever get done?
#10:15 -!- xrmx [~rm@2-228-255-178.ip194.fastwebnet.it] has joined 
#          #libreoffice-dev
#10:15 <@_rene_> ahunt: for firebird sdbc that is
#10:15 -!- xrmx [~rm@2-228-255-178.ip194.fastwebnet.it] has quit [Changing host]
#10:15 -!- xrmx [~rm@unaffiliated/xrmx] has joined #libreoffice-dev
#10:15 <@_rene_> because I just remember I still have 
#https://buildd.debian.org/status/fetch.php?pkg=libreoffice&arch=powerpc&ver=1%3
#
#10:16 < ahunt> _rene_: Not yet -- I still need to get round to actually 
#               debugging within firebird itself to make it work.
#10:16 < ahunt> _rene_: Yup, basically we're not endian portable yet.
#10:16 <@_rene_> An uncaught exception of type com.sun.star.sdbc.SQLException
#10:16 <@_rene_> - firebird_sdbc error:
#10:16 <@_rene_> *unsupported on-disk structure for file 
#                /tmp/lu4va82l.tmp/firebird.fdb; found 2
#10:16 <@_rene_> 944.512, support 11.2
#10:16 < xrmx> morning
#10:16 <@_rene_> aha, so disable firebird on be?
#10:16 <@_rene_> (for now)
#10:16 < Safa_[A_boy]> Hello. About converting dialogs to .ui files, What about 
#                      wizards?
#10:17 < ahunt> _rene_: yes, unfortunately.
ENABLE_FIREBIRD=y
ifeq "$(DEB_HOST_ARCH_ENDIAN)" "big"
  ENABLE_FIREBIRD=n
endif
ifeq "$(ENABLE_FIREBIRD)" "y"
  SYSTEM_STUFF += firebird
  ifeq (,$(filter firebird, $(SYSTEM_STUFF)))
  SYSTEM_STUFF += libatomic-ops
  endif
endif
ENABLE_EOT=y
ifeq "$(ENABLE_EOT)" "y"
SYSTEM_STUFF += libeot
endif
SYSTEM_STUFF += glm
BUILD_PPC64EL=y
BUILD_ARM64=y

# Default flags to pass to configure
CONFIGURE_FLAGS= \
		--with-vendor='$(OOO_VENDOR)' \
                --prefix=/usr --mandir=/usr/share/man \
                --docdir=/usr/share/doc/libreoffice \
                --enable-lockdown \
		--libdir=/usr/lib \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--disable-online-update \
		--disable-fetch-external \
		--without-fonts \
		--without-myspell-dicts \
		--disable-dependency-tracking \
		--enable-hardlink-deliver \
		--with-branding=$(CURDIR)/debian/branding

ifeq "$(shell echo $(DEB_VERSION_UPSTREAM) | grep -E '(alpha|beta)'; echo $$?)" "1"
CONFIGURE_FLAGS += --enable-release-build
endif

CONFIGURE_FLAGS += --enable-verbose

CONFIGURE_FLAGS += --with-alloc=$(ALLOC)

#############
# Architecture-specific changes

# helper to generate no_archs macros (pass name of source macro)
define gen_no_archs
  _no_arch_macro = $(subst OOO_,OOO_NO_,$1)
  _no_arch_tmp_$1 = $$(foreach _a,$$(filter-out $$(call $1),$(OOO_ARCHS)),!$$(_a))
  $$(_no_arch_macro) = $$(if $$(_no_arch_tmp_$1),$$(_empty) [$$(_no_arch_tmp_$1)])
endef

PLATFORMID := $(shell grep PLATFORMID debian/vars.$(DEB_HOST_ARCH) | cut -d"=" -f2)

ifeq "$(BUILD_PPC64EL)" "y"
OOO_ARCHS += ppc64el
endif
ifeq "$(BUILD_ARM64)" "y"
OOO_ARCHS += arm64
endif

ifeq "$(ENABLE_OPENGL)" "y"
  # doesn't make that much sense on armel and mips(el), does it? :)
  OOO_OGLTRANS_ARCHS = $(filter-out armel mips%, $(OOO_ARCHS))
  ifeq (,$(filter $(DEB_HOST_ARCH),$(OOO_OGLTRANS_ARCHS)))
       ENABLE_OPENGL=n
  endif
  $(eval $(call gen_no_archs,OOO_OGLTRANS_ARCHS))
endif
ifeq "$(ENABLE_GLTF)" "y"
  # doesn't make that much sense on armel and mips(el), does it? :)
  OOO_GLTF_ARCHS = $(filter-out armel mips%, $(OOO_ARCHS))
  ifeq (,$(filter $(DEB_HOST_ARCH),$(OOO_GLTF_ARCHS)))
       ENABLE_GLTF=n
  endif
  $(eval $(call gen_no_archs,OOO_GLTF_ARCHS))
endif

IGNORE_MAKE_CHECK_FAILURES=-
ifneq "$(JDK)" "gcj-jdk"
# disabled due to the Linux/Java Stack Clash fix regression...
#  ifeq (i386,$(DEB_HOST_ARCH))
#IGNORE_MAKE_CHECK_FAILURES:=
#  endif
  ifeq (amd64,$(DEB_HOST_ARCH))
IGNORE_MAKE_CHECK_FAILURES:=
  endif
endif
# sw_python would fail anyways as it doesn't work with python2..
ifeq "$(WHEEZY_BACKPORT)" "y"
IGNORE_MAKE_CHECK_FAILURES=-
endif

OOO_64BIT_ARCHS = $(filter alpha amd64 arm64 ia64 kfreebsd-amd64 ppc64 ppc64el s390x, $(OOO_ARCHS))
$(eval $(call gen_no_archs,OOO_64BIT_ARCHS))
OOO_BE_ARCHS = $(filter hppa m68k mips powerpc powerpcspe ppc64 s390 s390x sparc,$(OOO_ARCHS))
OOO_LE_ARCHS = $(filter-out $(OOO_BE_ARCHS),$(OOO_ARCHS))
$(eval $(call gen_no_archs,OOO_LE_ARCHS))

# Java...
ifeq "$(JDK)" "default"
OOO_JAVA_ARCHS = $(filter $(OOO_ARCHS),$(java_architectures))
else
OOO_JAVA_ARCHS = $(OOO_ARCHS)
endif
$(eval $(call gen_no_archs,OOO_JAVA_ARCHS))

ifeq "$(JDK)" "default"
OOO_GCJ_JDK_ARCHS := $(filter $(OOO_ARCHS),$(filter-out $(java7_architectures),$(filter-out $(java6_architectures),$(java5_architectures))))
else
OOO_GCJ_JDK_ARCHS := hppa
ifeq "$(WHEEZY_BACKPORT)" "y"
OOO_GCJ_JDK_ARCHS += kfreebsd-i386 kfreebsd-amd64
endif
endif
OOO_OPENJDK_ARCHS := $(filter-out $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))
$(eval $(call gen_no_archs,OOO_OPENJDK_ARCHS))

OOO_GCJ_ARCHS = $(filter-out $(OOO_OPENJDK_ARCHS), $(OOO_JAVA_ARCHS))
$(eval $(call gen_no_archs,OOO_GCJ_ARCHS))

OOO_UNOWINREG_DLL_ARCHS := i386 amd64
ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_UNOWINREG_DLL_ARCHS)))
	PACKAGE_UNOWINREG_DLL=n
endif

OOO_ARCH_DEP_EXTENSIONS_ARCHS := $(OOO_ARCHS)
OOO_EXTENSIONS_ARCHS := $(OOO_ARCH_DEP_EXTENSIONS_ARCHS)

OOO_BASE_ARCHS := $(OOO_JAVA_ARCHS)
$(eval $(call gen_no_archs,OOO_BASE_ARCHS))
OOO_REPORTDESIGN_ARCHS := $(filter-out $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))
$(eval $(call gen_no_archs,OOO_REPORTDESIGN_ARCHS))

ifneq (,$(findstring $(DEB_HOST_ARCH),$(OOO_NO_BASE_ARCHS)))
  ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_BASE_ARCHS)))
	PACKAGE_BASE=n
	ENABLE_SDBC_POSTGRESQL=n
	ENABLE_MYSQLNATIVE=n
	ENABLE_EVO2=n
	ENABLE_KDEAB=n
	ENABLE_REPORTDESIGN=n
	DEBHELPER_OPTIONS += -Nlibreoffice-base libreoffice-base-core -Nlibreoffice-base-drivers
	DEBHELPER_OPTIONS += -Nlibreoffice-evolution -Nlibreoffice-kab
	DEBHELPER_OPTIONS += -Nlibreoffice-sdbc-postgresql -Nlibreoffice-mysql-connector
	DEBHELPER_OPTIONS += -Nlibreoffice-sdbc-hsqldb -Nlibreoffice-sdbc-firebird 
	DEBHELPER_OPTIONS += -Nlibreoffice-report-builder-bin -Nlibreoffice-report-builder
	CONFIGURE_FLAGS += --disable-database-connectivity
  endif
endif

ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_BE_ARCHS)))
	ENABLE_FIREBIRD=n
	DEBHELPER_OPTIONS += -Nlibreoffice-sdbc-firebird
endif
ifeq (,$(findstring $(DEB_HOST_ARCH),$(OOO_ARCH_DEP_EXTENSIONS_ARCHS)))
	ENABLE_MYSQLNATIVE=n
	DEBHELPER_OPTIONS += -Nlibreoffice-mysql-connector
	DEBHELPER_OPTIONS += -Nlibreoffice-presentation-minimizer
endif
ifeq (,$(findstring $(DEB_HOST_ARCH),$(OOO_EXTENSIONS_ARCHS)))
	ENABLE_MEDIAWIKI=n
	ENABLE_REPORTDESIGN=n
	DEBHELPER_OPTIONS += -Nlibreoffice-wiki-publisher -Nlibreoffice-script-provider-python
	CONFIGURE_FLAGS += --disable-extension-integration --disable-extensions
else
	CONFIGURE_FLAGS += --enable-extension-integration
endif

ifeq (,$(filter $(DEB_HOST_ARCH),$(OOO_JAVA_ARCHS)))
	ENABLE_JAVA=n
	ENABLE_REPORTDESIGN=n
	ENABLE_MEDIAWIKI=n
	DEBHELPER_OPTIONS += -Nlibreoffice-wiki-publisher
	DEBHELPER_OPTIONS += -Nlibreoffice-report-builder-bin -Nlibreoffice-report-builder
endif

ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_GCJ_JDK_ARCHS)))
  ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_OPENJDK_ARCHS)))
	ENABLE_REPORTDESIGN=n
	SYSTEM_STUFF := $(filter-out jfreereport, $(SYSTEM_STUFF))
	DEBHELPER_OPTIONS += -Nlibreoffice-report-builder-bin -Nlibreoffice-report-builder
  endif
endif
# disable SRB on ia64 when building with internal jfreereport.
# fails to build. ("The system is out of resources."). FIXME.
ifeq (ia64,$(findstring ia64,$(OOO_OPENJDK_ARCHS)))
  ifeq (,$(findstring jfreereport,$(SYSTEM_STUFF))) 
    OOO_REPORTDESIGN_ARCHS := $(filter-out ia64,$(OOO_REPORTDESIGN_ARCHS))
    ifeq "$(DEB_HOST_ARCH)" "ia64"
	ENABLE_REPORTDESIGN=n
    endif
  endif
endif
ifneq (,$(filter $(DEB_HOST_ARCH),$(OOO_GCJ_ARCHS)))
	BUILD_JARS_NATIVE=n
endif

ifeq "$(BUILD_TEST_PACKAGE)" "n"
	DEBHELPER_OPTIONS += -Nlibreoffice-subsequentcheckbase
endif

ifeq "$(PACKAGE_NSPLUGIN)" "y"
OOO_NSPLUGIN_ARCHS = $(OOO_ARCHS)
else
OOO_NSPLUGIN_ARCHS=
endif
$(eval $(call gen_no_archs,OOO_NSPLUGIN_ARCHS))

ifneq "$(WHEEZY_BACKPORT)" "y"
  ifneq (,$(findstring mips, $(OOO_ARCHS)))
BUILD_DEPS += , binutils (>= 2.23) [mips mipsel], libc6 (>= 2.17-6) [mips mipsel]
  endif
endif

#############
# Distro-specific overrides

# Debian WHeezy
ifeq "$(shell dpkg-parsechangelog | grep Distribution | awk '{ print $$2 }')" "wheezy-backports"
  BUGS=mailto:debian-backports@lists.debian.org
  SYSTEM_STUFF := $(filter-out libcmis libcdr clucene libmspub libmwaw libodfgen mdds liblangtag orcus harfbuzz libatomic-ops libwpd redland libetonyek libfreehand libebook libvisio libeot libabw glew glm librevenge libwpg libwps boost coinmp libgltf ucpp,$(SYSTEM_STUFF))
  PACKAGE_SDK_DOCS=n
  WHEEZY_BACKPORT=y
endif
ifeq "$(shell dpkg-parsechangelog | grep Distribution | awk '{ print $$2 }')" "UNRELEASED"
  BUGS=mailto:debian-openoffice@lists.debian.org
endif

CONFIGURE_FLAGS += $(foreach i, $(SYSTEM_STUFF),--with-system-$(i))

CC_PREFIX:=$(shell gcc -dumpmachine)-

	BUILD_DEPS += , gcc-$(SYSTEM_GCJ_VERSION) [$(OOO_GCJ_JDK_ARCHS)] ,g++-$(SYSTEM_GCJ_VERSION) [$(OOO_GCJ_JDK_ARCHS)]
#ifeq (,$(findstring i386,$(DEB_HOST_ARCH)))
#  ifeq (,$(findstring amd64,$(DEB_HOST_ARCH)))
#    ifneq "$(SYSTEM_GCC_VERSION)" "4.6"
#	GCC_VERSION := 4.6
#    endif
#  endif
#endif
ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_GCJ_JDK_ARCHS)))
  ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_OPENJDK_ARCHS)))
GCC_VERSION := $(SYSTEM_GCJ_VERSION)
  endif
endif
ifneq "$(GCC_VERSION)" ""
  ifneq "$(SYSTEM_GCC_VERSION)" "$(GCC_VERSION)"
    BUILD_DEPS += , gcc-$(GCC_VERSION), g++-$(GCC_VERSION)
    CONFIGURE_FLAGS+= \
      CC=$(CC_PREFIX)gcc-$(GCC_VERSION) \
      CXX=$(CC_PREFIX)g++-$(GCC_VERSION)
  endif
endif

BUILDDEB_OPTIONS ?= -- -Zxz

ifneq (,$(findstring mesa-headers,$(SYSTEM_STUFF)))
	BUILD_DEPS += , libgl1-mesa-dev, libglu1-mesa-dev
endif
ifneq "$(ENABLE_OPENGL)" "y"
	CONFIGURE_FLAGS += --disable-opengl
endif
ifneq "$(ENABLE_GLTF)" "y"
	CONFIGURE_FLAGS += --disable-gltf
else
  ifneq (,$(findstring libgltf,$(SYSTEM_STUFF)))
	BUILD_DEPS += , libgltf-dev (>= 0.0.1)$(OOO_NO_GLTF_ARCHS)
  endif
  ifneq "$(ENABLE_COLLADA)" "y"
	CONFIGURE_FLAGS += --disable-collada
  endif
endif

ifneq "$(PACKAGE_SDK)" "y"
	CONFIGURE_FLAGS += --disable-odk
 ifneq "$(PACKAGE_SDK_DOCS)" "y"
	CONFIGURE_FLAGS += --without-doxygen --without-javadoc
 endif
else
  ifeq "$(PACKAGE_SDK_DOCS)" "y"
	BUILD_DEPS_INDEP += , doxygen (>= 1.8.4)
  else
	CONFIGURE_FLAGS += --without-doxygen --without-javadoc
  endif
endif

	BUILD_DEPS += , libpoppler-dev (>= 0.8.0), libpoppler-private-dev, libpoppler-cpp-dev

ifeq "$(WHEEZY_BACKPORTS)" "y"
# fails their tests
  ifeq "$(DEB_HOST_ARCH)" "armel"
ENABLE_GRAPHITE=n
SYSTEM_STUFF := $(filter-out graphite, $(SYSTEM_STUFF))
  endif
  ifeq "$(DEB_HOST_ARCH)" "sparc"
ENABLE_GRAPHITE=n
SYSTEM_STUFF := $(filter-out graphite, $(SYSTEM_STUFF))
  endif
endif

ifeq "$(ENABLE_GRAPHITE)" "y"
  ifneq (,$(filter graphite, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libgraphite2-dev (>= 0.9.3)
    ifeq "$(WHEEZY_BACKPORTS)" "y"
	BUILD_DEPS += [!armel !sparc]
    endif
  endif
else
	CONFIGURE_FLAGS += --disable-graphite
endif

ifneq (,$(filter harfbuzz, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libharfbuzz-dev (>= 0.9.18)
endif

ifneq (,$(filter libexttextcat, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libexttextcat-dev (>= 3.1.1)
	TEXTCAT_DATA_RECOMMENDS := libexttextcat-data
endif

ifneq (,$(filter jpeg, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libjpeg-dev
endif
ifneq (,$(filter libxml, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libxml2-dev, libxml2-utils
       BUILD_DEPS += , libxslt1-dev
       DBG_DBG_SUGGESTS+= , libxslt1-dbg
endif
ifneq (,$(filter expat, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libexpat1-dev
endif
ifneq (,$(filter odbc, $(SYSTEM_STUFF)))
       BUILD_DEPS += , unixodbc-dev (>= 2.2.11)
endif
ifneq (,$(filter sane, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libsane-dev
endif
ifneq (,$(filter libpng, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libpng12-dev
endif

ifneq (,$(filter curl, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libcurl4-$(CURL_SECTYPE)-dev
endif

ifneq ($(ENABLE_COINMP),y)
	CONFIGURE_FLAGS += --disable-coinmp
else
	BUILD_DEPS += , coinor-libcoinmp-dev
endif

ifneq (,$(filter openssl, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libssl-dev (>= 0.9.8)
	DBG_DBG_SUGGESTS += , libssl$(shell readlink /usr/lib/$(DEB_HOST_MULTIARCH)/libssl.so | cut -d"." -f3,4,5)-dbg
endif
ifeq "$(USE_OPENCL)" "y"
	OPENCL_SUGGESTS := ocl-icd-libopencl1
else
	CONFIGURE_FLAGS += --disable-opencl
endif

ifeq "$(BUILD_DBG_PACKAGE)" "y"
  ifneq (,$(findstring i386,$(DEB_HOST_ARCH)))
	SMALL_SYMBOLS = n
  else
    ifneq (,$(findstring amd64,$(DEB_HOST_ARCH)))
	SMALL_SYMBOLS = n
    endif
  endif
	DBG_DBG_SUGGESTS+= , libc6.1-dbg [alpha ia64], libc0.1-dbg [kfreebsd-i386 kfreebsd-amd64], libc0.3-dbg [hurd-i386], libc6-dbg [!alpha !ia64 !kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libatk1.0-dbg, libglib2.0-0-dbg, libgnomevfs2-0-dbg, libstdc++6-$(SYSTEM_GCC_VERSION)-dbg, libx11-6-dbg, libxext6-dbg, libxaw7-dbg, libxml2-dbg, libgtk2.0-0-dbg, libxau6-dbg, libice6-dbg, libsm6-dbg, libxinerama1-dbg, libfontconfig1-dbg, libhunspell-$(shell pkg-config --modversion hunspell | cut -d. -f1,2)-0-dbg, libcurl4-dbg
endif

export DPKG_EXPORT_BUILDFLAGS=y 
include /usr/share/dpkg/buildflags.mk
ifeq "$(ENABLE_SYMBOLS)" "y"
  # Small symbols?
  ifeq "$(SMALL_SYMBOLS)" "y"
	CONFIGURE_FLAGS += --enable-symbols=SMALL
	CFLAGS := $(shell echo $(CFLAGS) | sed -e "s/-g/-g1/")
	CXXFLAGS := $(shell echo $(CXXFLAGS) | sed -e "s/-g/-g1/")
export CFLAGS CXXFLAGS
  else
	CONFIGURE_FLAGS += --enable-symbols
  endif
endif
ifeq (debug,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CONFIGURE_FLAGS += --enable-debug
endif


ifneq "$(WHEEZY_BACKPORT)" "y"
PYMAJOR:=$(shell $(PYTHON) -c "import sys; print (sys.version_info[0])")
PYMINOR:=$(shell $(PYTHON) -c "import sys; print (sys.version_info[1])")
PYMINORPLUS1:=$(shell $(PYTHON) -c "import sys; print (sys.version_info[1]+1)")
PYTHON_SITE:=debian/python3-uno/$(shell $(PYTHON) -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
ifeq "$(ENABLE_PYTHON2)" "y"
PY2MAJOR:=$(shell $(PYTHON2) -c "import sys; print sys.version_info[0]")
PY2MINOR:=$(shell $(PYTHON2) -c "import sys; print sys.version_info[1]")
PY2MINORPLUS1:=$(shell $(PYTHON2) -c "import sys; print sys.version_info[1]+1")
PYTHON2_SITE:=debian/python-uno/$(shell $(PYTHON2) -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
endif
else
PYMAJOR:=$(shell $(PYTHON2) -c "import sys; print (sys.version_info[0])")
PYMINOR:=$(shell $(PYTHON2) -c "import sys; print (sys.version_info[1])")
PYMINORPLUS1:=$(shell $(PYTHON2) -c "import sys; print (sys.version_info[1]+1)")
# YES, really! python3-uno. see "OMG!" below :-)
PYTHON_SITE:=debian/python3-uno/$(shell $(PYTHON2) -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')
PYTHON:=$(PYTHON2)
endif

ifeq "$(PYTHON_VERSION)" "current"
	PYTHON_VERSION_CONTROL := $(PYMAJOR).$(PYMINOR)
else
	PYTHON_VERSION_CONTROL := $(PYTHON_VERSION)
endif

ifeq "$(ENABLE_PYTHON)" "y"
	BUILD_DEPS += , $(PYTHON)
  ifeq "$(ENABLE_PYTHON2)" "y"
	BUILD_DEPS += , $(PYTHON2) (>= 2.6.6-3+squeeze4)
  endif
	DBG_DBG_SUGGESTS+= , $(PYTHON)-dbg
  ifneq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS += , $(PYTHON)-dev (>= 3.3)
    ifeq "$(ENABLE_PYTHON2)" "y"
	BUILD_DEPS += , $(PYTHON2)-dev (>= 2.6)
    endif
  else
	BUILD_DEPS += , $(PYTHON2)-dev (>= 2.7)
  endif
else
	BUILD_DEPS += , python
endif
ifeq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS += , dh-python
endif

	BUILD_DEPS += , debhelper (>= 7.2.3~)

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
	STAMP_NATIVE_JARS = $(STAMP_DIR)/native-jars
	JAVA_GCJ_DEPENDS = libgcj-common (>= 1:4.1.1-14)
  endif
endif

ifeq "$(RUN_TESTTOOL)" "y"
	CONFIGURE_FLAGS += --enable-hids
endif
ifneq (,$(filter cppunit, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libcppunit-dev (>= 1.12)
endif
ifeq "$(RUN_MAKE_CHECK)" "y"
	BUILD_DEPS += , gdb
	BUILD_DEPS += , fontconfig
  ifeq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS += , ttf-liberation
  else
	BUILD_DEPS += , fonts-liberation
  endif
  	BUILD_DEPS += , fonts-crosextra-carlito
  ifeq "$(ENABLE_JUNIT4)" "y"
	BUILD_DEPS += , junit4 $(JUNIT_MIN_VER)
  else
	CONFIGURE_FLAGS += --without-junit
  endif
else
	CONFIGURE_FLAGS += --without-junit
endif

ifneq "$(BUILD_ONLY_EN_US)" "y"
  ifeq (lang=,$(findstring lang=,$(DEB_BUILD_OPTIONS)))
	ISOS=$(shell echo "$(DEB_BUILD_OPTIONS) " | sed -n 's/^.*lang=\([^\s].*\)\s.*/\1/p' | awk '{ print $$1 }' | sed -e 's/,/ /g')
    ifeq "$(ENABLE_HELP)" "n"
	HELPISOS=
    else
	HELPISOS=$(shell echo "$(DEB_BUILD_OPTIONS) " | sed -n 's/^.*lang=\([^\s].*\)\s.*/\1/p' | awk '{ print $$1 }' | sed -e 's/,/ /g')
    endif
	LANGPACKISOS=$(shell echo "$(DEB_BUILD_OPTIONS) " | sed -n 's/^.*lang=\([^\s].*\)\s.*/\1/p' | awk '{ print $$1 }' | sed -e 's/,/ /g')
  else
	# Note that the first one here *has to be* en-US. the first one gets
	# gid_Module_Root as filelist later and the rest gid_Module_Root.$iso
	# but we can't/shouldn't do dynamic switching, so let en-US be the first
	# one to that gid_Module_Root always is english and the other langpacks
	# have gid_Module_Root.$iso
	#ISOS=$(shell $(SOURCE_TREE)/bin/lo-xlate-lang -i all')
	ISOS:=en-US af ar as ast be bg bn br bs ca ca-valencia cs cy da de dz el \
	  en-GB en-ZA eo es et eu fa fi fr ga gd gl gu he hi hr hu id is it ja \
	  ka kk km ko kmr-Latn lt lv mk mn ml mr nb ne nl nn nr nso oc om or \
	  pa-IN pl pt pt-BR ro ru rw si sk sl sr ss st sv \
	  ta te tg th tn tr ts ug uk uz ve vi xh zh-CN zh-TW zu
    ifeq "$(ENABLE_HELP)" "n"
	HELPISOS:=
    else
	#HELPISOS:=$(shell $(SOURCE_TREE)/bin/lo-xlate-lang -i all') 
	HELPISOS:=en-US ca ca-valencia cs da de dz el en-GB es et eu fi fr gl hi hu it \
	  ja km ko nl om pl pt pt-BR ru sk sl sv tr vi zh-CN zh-TW
    endif
	#LANGPACKISOS:=$(shell $(SOURCE_TREE)/bin/lo-xlate-lang -i all')
	LANGPACKISOS:=en-US af ar as ast be bg bn br bs ca ca-valencia cs cy da de dz el \
	  en-GB en-ZA eo es et eu fa fi fr ga gd gl gu he hi hr hu id is it ja \
	  ka kk km ko kmr-Latn lt lv mk mn ml mr nb ne nl nn nr nso oc om or \
	  pa-IN pl pt pt-BR ro ru rw si sk sl sr ss st sv \
	  ta te tg th tn tr ts ug uk uz ve vi xh zh-CN zh-TW zu
  endif
else
	ISOS=en-US
    ifeq "$(ENABLE_HELP)" "n"
    	HELPISOS=
    else
	HELPISOS=en-US
    endif
	LANGPACKISOS=en-US
endif
BUILD_ISOS = $(ISOS)

ifneq "$(BUILD_ONLY_EN_US)" "y"
  ifneq "$(BUILD_ISOS)" "en-US"
	CONFIGURE_FLAGS_LANG += --with-lang="$(BUILD_ISOS)"
  endif
endif

ifeq "$(ENABLE_JAVA)" "y"
  BUILD_DEPS += , maven-repo-helper
  ifeq "$(JDK)" "default"
	BUILD_DEPS += , java-common (>= 0.49)
	JAVA_HOME=/usr/lib/jvm/default-java
	BUILD_DEPS += , default-jdk$(filter-out !ia64,$(OOO_NO_JAVA_ARCHS))
    ifneq (,$(findstring ia64,$(OOO_JAVA_ARCHS)))
	BUILD_DEPS += , default-jdk (>= 1:1.7-48) [ia64]
    endif
    ifeq ($(java_default_version),5)
	JDK=gcj-jdk
    endif
  endif
  ifeq "$(JDK)" "gcj-jdk"
	JAVA_HOME=/usr/lib/jvm/java-gcj
	BUILD_DEPS += , gcj-jdk$(OOO_NO_JAVA_ARCHS)
	DEBHELPER_OPTIONS += -Nlibreoffice-dev-doc
	PACKAGE_SDK_DOCS = n
  endif
  ifeq "$(JDK)" "openjdk"
    ifeq "$(JAVA_MAINVER)" "6"
	BUILD_DEPS += , openjdk-$(JAVA_MAINVER)-jdk (>= 6b23~pre8-2) [$(filter-out ia64 $((OOO_GCJ_JDK_ARCHS),$(filter-out $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))])
    else
	BUILD_DEPS += , openjdk-$(JAVA_MAINVER)-jdk [$(filter-out mips mipsel $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))]
      # no 7 on mips(el)
      ifneq (,$(findstring mips,$(OOO_JAVA_ARCHS)))
	BUILD_DEPS += , openjdk-6-jdk (>= 6b23~pre8-2) [mips mipsel]
        ifneq (,$(findstring mips,$(DEB_HOST_ARCH)))
          JAVA_MAINVER=6
        endif
      endif
    endif
	JAVA_HOME=/usr/lib/jvm/java-$(JAVA_MAINVER)-openjdk-$(DEB_HOST_ARCH)
  endif
        TEST_JAVA_HOME=$(JAVA_HOME)
  ifneq "$(OOO_GCJ_JDK_ARCHS)" ""
	BUILD_DEPS += , gcj-jdk [$(OOO_GCJ_JDK_ARCHS)]
	BUILD_DEPS += , gcj-native-helper [$(OOO_GCJ_ARCHS)], libgcj-common (>= 1:4.4.1) [$(OOO_GCJ_ARCHS)]
  endif
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	BUILD_DEPS += , ant (>= 1.7.0)$(OOO_NO_JAVA_ARCHS), ant-optional (>= 1.7.0)$(OOO_NO_JAVA_ARCHS)
  else
	BUILD_DEPS += , ant (>= 1.6.5)$(OOO_NO_JAVA_ARCHS)
  endif
	GCJ_JAWT_DEPENDS= $(shell dpkg -S /usr/lib/$(DEB_HOST_MULTIARCH)/gcj-$(GCJ_VERSION)-*/libgcj_bc.so.1 | cut -d: -f1 | sed -e s/$$/-awt/)
	DBG_DBG_SUGGESTS+= , $(shell echo $(GCJ_AWT_DEPENDS) | sed -e s/awt/dbg/)
	JAVA_RUNTIME_DEPENDS = default-jre | gcj-jre
#  ifneq (,$(GCJ_JAWT_DEPENDS))
#	JAVA_RUNTIME_DEPENDS += | $(GCJ_JAWT_DEPENDS)
#  endif
  ifneq (,$(filter $(DEB_HOST_ARCH), $(OOO_OPENJDK_ARCHS)))
    ifneq "$(DEB_HOST_ARCH)" "ia64"
	JAVA_RUNTIME_DEPENDS += | openjdk-7-jre | openjdk-6-jre
    else
	JAVA_RUNTIME_DEPENDS += | openjdk-7-jre
    endif
  endif
  ifneq (,$(filter $(DEB_HOST_ARCH), amd64 i386))
	JAVA_RUNTIME_DEPENDS += | sun-java5-jre | sun-java6-jre
  endif
	JAVA_RUNTIME_DEPENDS += | java5-runtime
	# Suns Java "packages"
	JAVA_RUNTIME_DEPENDS += | jre
	GCJ_JAWT_DIR=$(shell dirname `dpkg -L $(GCJ_JAWT_DEPENDS) | grep libjawt.so | head -n 1`)
export JAVA_HOME
	CONFIGURE_FLAGS += --with-jdk-home=$(JAVA_HOME)
	JAVA_COMMON_DEPENDS= , libreoffice-java-common
	JAVA_COMMON_DEPENDS_VERSION:= (>= $(BASE_VERSION)~)
  ifeq "$(PACKAGE_SDK)" "y"
    ifeq "$(PACKAGE_UNOWINREG_DLL)" "y"
      ifeq "$(BUILD_UNOWINREG_DLL)" "y"
	CONFIGURE_FLAGS += --enable-build-unowinreg
	BUILD_DEPS += , g++-mingw-w64-i686 [$(OOO_UNOWINREG_DLL_ARCHS)]
	CONFIGURE_FLAGS += --with-mingw-cross-compiler=i686-w64-mingw32-g++
      endif
    endif
  endif
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	CONFIGURE_FLAGS += --enable-ext-wiki-publisher
    ifneq (,$(filter apache-commons, $(SYSTEM_STUFF)))
	MEDIAWIKI_BUILD_DEPS += , libcommons-codec-java$(OOO_NO_JAVA_ARCHS), libcommons-httpclient-java$(OOO_NO_JAVA_ARCHS), libcommons-lang-java$(OOO_NO_JAVA_ARCHS), libcommons-logging-java$(OOO_NO_JAVA_ARCHS)
	MEDIAWIKI_JAR_DEPENDS := , libcommons-codec-java, libcommons-httpclient-java, libcommons-lang-java, libcommons-logging-java
	BUILD_DEPS_INDEP += $(MEDIAWIKI_BUILD_DEPS)
	CONFIGURE_FLAGS += --with-commons-codec-jar=/usr/share/java/commons-codec.jar --with-commons-lang-jar=/usr/share/java/commons-lang.jar --with-commons-httpclient-jar=/usr/share/java/commons-httpclient.jar --with-commons-logging-jar=/usr/share/java/commons-logging.jar
    endif
  endif
  ifeq "$(ENABLE_REPORTDESIGN)" "y"
	# report-builder
    ifneq (,$(filter jfreereport, $(SYSTEM_STUFF)))
	REPORT_BUILDER_BUILD_DEPS += , libbase-java$(OOO_NO_REPORTDESIGN_ARCHS), libsac-java$(OOO_NO_REPORTDESIGN_ARCHS), libxml-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS), libflute-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS), libpentaho-reporting-flow-engine-java (>= 0.9.4)$(OOO_NO_REPORTDESIGN_ARCHS), liblayout-java (>= 0.2.10)$(OOO_NO_REPORTDESIGN_ARCHS), libloader-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS), libformula-java (>= 1.1.7)$(OOO_NO_REPORTDESIGN_ARCHS), librepository-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS), libfonts-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS), libserializer-java (>= 1.1.6)$(OOO_NO_REPORTDESIGN_ARCHS)
	REPORT_BUILDER_JAR_DEPENDS := , libbase-java, libsac-java, libxml-java (>= 1.1.6), libflute-java (>= 1.1.6), libpentaho-reporting-flow-engine-java (>= 0.9.4), liblayout-java (>= 0.2.10), libloader-java (>= 1.1.6), libformula-java (>= 1.1.7), librepository-java (>= 1.1.6), libfonts-java (>= 1.1.6), libserializer-java (>= 1.1.6)
	BUILD_DEPS_INDEP += $(REPORT_BUILDER_BUILD_DEPS)
	CONFIGURE_FLAGS += --with-libbase-jar=/usr/share/java/libbase.jar --with-libxml-jar=/usr/share/java/libxml.jar --with-flute-jar=/usr/share/java/flute.jar --with-jfreereport-jar=/usr/share/java/flow-engine.jar --with-liblayout-jar=/usr/share/java/liblayout.jar --with-libloader-jar=/usr/share/java/libloader.jar --with-libformula-jar=/usr/share/java/libformula.jar --with-librepository-jar=/usr/share/java/librepository.jar --with-libfonts-jar=/usr/share/java/libfonts.jar --with-libserializer-jar=/usr/share/java/libserializer.jar
    endif
    ifneq (,$(filter apache-commons, $(SYSTEM_STUFF)))
	REPORT_BUILDER_BUILD_DEPS += , libcommons-logging-java$(OOO_NO_JAVA_ARCHS)
	REPORT_BUILDER_JAR_DEPENDS += , libcommons-logging-java
	CONFIGURE_FLAGS += --with-commons-logging-jar=/usr/share/java/commons-logging.jar
    endif
  else
	CONFIGURE_FLAGS += --disable-report-builder
  endif
	OOO_OFFICEBEAN_DEP = libreoffice-officebean
	BUILD_DEPS += , javahelper $(JAVAHELPER_MIN_VERSION)
else
	CONFIGURE_FLAGS += --without-java
	DEBHELPER_OPTIONS += -Nlibreoffice-officebean -Nlibreoffice-java-common -Nlibreoffice-gcj -Nlibreoffice-script-provider-bsh -Nlibreoffice-script-provider-js
endif

ifneq (,$(filter nss, $(SYSTEM_STUFF)))
	BUILD_DEPS+= , libnss3-dev (>= 3.12.3)
	DBG_DBG_SUGGESTS+= , libnss3-dbg
endif
ifneq (,$(filter npapi-headers, $(SYSTEM_STUFF)))
  ifneq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS+= , npapi-sdk-dev$(OOO_NO_NSPLUGIN_ARCHS)
  else
	BUILD_DEPS+= , xulrunner-dev$(OOO_NO_NSPLUGIN_ARCHS)
  endif
endif
ifeq (,$(findstring $(DEB_HOST_ARCH),$(OOO_NSPLUGIN_ARCHS)))
	PACKAGE_NSPLUGIN=n
	CONFIGURE_FLAGS += --disable-nsplugin
endif

ifeq "$(USE_UCPP)" "y"
  ifneq (,$(filter ucpp, $(SYSTEM_STUFF)))
	IDLC_CPP_DEPENDS := ucpp
  endif
else
# hardcode 4.7 as 4.8 fails:
# 14:17 <@caolan> ah, "build fails with cpp 4.8.0, this is fixable by passing 
#                -P, but then idlc produces empty urd files"
	IDLC_CPP_DEPENDS := cpp-4.7
	CONFIGURE_FLAGS += --with-idlc-cpp=cpp-4.7
endif
	BUILD_DEPS += , $(IDLC_CPP_DEPENDS)

ifneq (,$(filter hunspell, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libhunspell-dev $(HUNSPELL_MIN_VER)
endif
	CONFIGURE_FLAGS += --with-external-dict-dir=$(DICT_DIR)

ifneq (,$(filter altlinuxhyph, $(SYSTEM_STUFF)))
  ifeq "$(USE_LIBHYPHEN)" "y"
	BUILD_DEPS += , libhyphen-dev $(LIBHYPHEN_MINVER)
  else
	BUILD_DEPS += , libaltlinuxhyph-dev $(LIBALTLINUXHYPH_MINVER)
  endif
endif
	CONFIGURE_FLAGS += --with-external-hyph-dir=$(HYPH_DIR)

ifneq (,$(filter boost, $(SYSTEM_STUFF)))
  ifneq "$(BOOST_VERSION)" "default"
	BUILD_DEPS += , libboost$(BOOST_VERSION)-dev $(BOOST_MINVER), libboost-date-time$(BOOST_VERSION)-dev $(BOOST_MINVER), libboost-iostreams$(BOOST_VERSION)-dev
	#BUILD_DEPS += , libboost-thread$(BOOST_VERSION)-dev, libboost-program-options$(BOOST_VERSION)-dev
    ifeq "$(ENABLE_ORCUS)" "y"
      ifeq (,$(filter orcus, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libboost-system$(BOOST_VERSION)-dev $(BOOST_MINVER), libboost-iostreams$(BOOST_VERSION)-dev $(BOOST_MINVER), libboost-program-options$(BOOST_VERSION)-dev $(BOOST_MINVER),
      endif
    endif
    ifeq ($(USE_VLC),y)
	BUILD_DEPS += , libboost-system$(BOOST_VERSION)-dev $(BOOST_MINVER)
    endif
  else
	BUILD_DEPS += , libboost-dev $(BOOST_MINVER), libboost-date-time-dev $(BOOST_MINVER), libboost-iostreams-dev $(BOOST_MINVER)
	#BUILD_DEPS += , libboost-thread-dev, libboost-program-options-dev
    ifeq (,$(filter orcus, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libboost-system-dev $(BOOST_MINVER), libboost-iostreams-dev $(BOOST_MINVER), libboost-program-options-dev $(BOOST_MINVER)
    endif
    ifeq ($(USE_VLC),y)
	BUILD_DEPS += , libboost-system-dev $(BOOST_MINVER)
    endif
  endif
  ifeq "$(shell if [ -e /usr/lib/$(DEB_HOST_MULTIARCH)/libboost_date_time.so ]; then echo true; fi)" "true"
  	CONFIGURE_FLAGS += --with-boost-libdir=/usr/lib/$(DEB_HOST_MULTIARCH)
  endif
endif

ifneq (,$(filter mdds, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmdds-dev (>= 0.10.3)
endif

ifeq "$(ENABLE_ORCUS)" "y"
  ifneq (,$(filter orcus, $(SYSTEM_STUFF)))
	BUILD_DEPS += , liborcus-dev (>= 0.7.0)
  endif
else
	CONFIGURE_FLAGS += --disable-orcus
endif

ifneq (,$(filter vigra, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libvigraimpex-dev
endif

ifneq (,$(filter clucene, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libclucene-dev (>= 2.3.3.4-2)
endif

ifeq "$(USE_EXTERNAL_CXXLIBS)" "y"
  ifneq (,$(filter librevenge, $(SYSTEM_STUFF)))
	BUILD_DEPS += , librevenge-dev
  endif
  ifneq (,$(filter libwpd, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libwpd-dev (>= 0.10)
  endif
  ifneq (,$(filter mythes, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmythes-dev (>= 2:1.2)
  endif
  ifneq (,$(filter libwps, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libwps-dev (>= 0.3)
  endif
  ifneq (,$(filter libwpg, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libwpg-dev (>= 0.3)
  endif
  ifneq (,$(filter libvisio, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libvisio-dev (>= 0.1)
  endif
  ifneq (,$(filter libcdr, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libcdr-dev (>= 0.1)
  endif
  ifneq (,$(filter libmspub, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmspub-dev (>= 0.1)
  endif
  ifneq (,$(filter libmwaw, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmwaw-dev (>= 0.3.1)
  endif
  ifneq (,$(filter libodfgen, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libodfgen-dev (>= 0.1)
  endif
  ifneq (,$(filter libetonyek, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libetonyek-dev (>= 0.1.1)
  endif
  ifneq (,$(filter libfreehand, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libfreehand-dev (>= 0.1)
  endif
  ifneq (,$(filter libabw, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libabw-dev (>= 0.1)
  endif
  ifneq (,$(filter libebook, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libe-book-dev (>= 0.1.1)
  endif
  ifneq (,$(filter libcmis, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libcmis-dev (>= 0.4.0)
  endif
endif
	CONFIGURE_FLAGS += --with-external-thes-dir=$(THES_DIR)

ifeq "$(ENABLE_EOT)" "y"
 	CONFIGURE_FLAGS += --enable-eot
 ifneq (,$(filter libeot, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libeot-dev
 endif
endif

ifneq (,$(filter lcms2, $(SYSTEM_STUFF)))
	BUILD_DEPS += , liblcms2-dev
endif

ifneq (,$(filter openldap, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libldap2-dev
endif

ifeq ($(ENABLE_TELEPATHY),y)
	BUILD_DEPS += , libtelepathy-glib-dev (>= 0.18)
	CONFIGURE_FLAGS += --enable-telepathy
endif

ifeq ($(ENABLE_LIBLANGTAG),y)
  ifneq (,$(filter liblangtag, $(SYSTEM_STUFF)))
	BUILD_DEPS += , liblangtag-dev (>= 0.4)
  endif
else
	CONFIGURE_FLAGS += --disable-liblangtag
endif

ifneq (,$(filter icu, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libicu-dev $(ICU_MINVER)
endif


ifeq "$(BUILD_CAIROCANVAS)" "y"
  ifneq (,$(filter cairo, $(SYSTEM_STUFF)))
	BUILD_DEPS+= , libcairo2-dev
  endif
else
	CONFIGURE_FLAGS+= --disable-cairo
endif

ifeq "$(BUILD_KDE)" "n"
	CONFIGURE_FLAGS+= --disable-kde
	CONFIGURE_FLAGS-= --disable-kde4
else
	CONFIGURE_FLAGS += --disable-kde
	CONFIGURE_FLAGS += --enable-kde4
	KDE_ICONSET_DEP=libreoffice-style-oxygen
	BUILD_DEPS += , kdelibs5-dev $(KDELIBS_MINVER)
	BUILD_DEPS += , libqt4-dev $(QT_MINVER)
	DBG_DBG_SUGGESTS+= , kdelibs5-dbg, libqt4-dbg
  ifeq "$(ENABLE_KDEAB)" "y"
	ADDITIONAL_SECTIONS += KDE4Experimental
	BUILD_DEPS += , kdepimlibs5-dev$(OOO_NO_BASE_ARCHS)
  else
	CONFIGURE_FLAGS+= --disable-kdeab
  endif
endif

ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	CONFIGURE_FLAGS += --enable-ext-mariadb-connector
  ifneq "$(USE_MARIADB)" "y"
    ifneq (,$(filter mysql-cppconn, $(SYSTEM_STUFF)))
        BUILD_DEPS += , libmysqlclient-dev
    endif
     MARIADBCONFIG=/usr/bin/mysql_config
  else
    ifneq (,$(filter mariadb, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmariadbclient-dev (>= 1.1.0~)
    endif
     MARIADBCONFIG=/usr/bin/mariadb_config
  endif
  ifneq (,$(filter mysql-cppconn, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libmysqlcppconn-dev $(MYSQLCPPCONN_MINVER)
  endif
endif

ifeq "$(ENABLE_FIREBIRD)" "y"
  ifneq (,$(filter libatomic-ops, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libatomic-ops-dev (>= 7.3~alpha1+git20110913-1)$(OOO_NO_BE_ARCHS)
  endif
  ifneq (,$(filter firebird, $(SYSTEM_STUFF)))
    ifneq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS += , firebird-dev (>= 2.5.2.26540.ds4-2)$(OOO_NO_LE_ARCHS)
	# no FIREBIRD_CFLAGS here. Have no effect as fb_config is there
	# and configure prefers that over our values...
    else
	BUILD_DEPS += , firebird-dev$(OOO_NO_LE_ARCHS)
	# firebird-dev only _Suggests_ libfbembed2.5...
	BUILD_DEPS += , libfbembed2.5$(OOO_NO_LE_ARCHS)
	FIREBIRD_CFLAGS := " "
	FIREBIRD_LIBS := "-L/usr/lib/$(DEB_HOST_MULTIARCH) -lfbembed"
    endif
  endif
else
	CONFIGURE_FLAGS += --disable-firebird-sdbc
endif

ifeq "$(BUILD_GTK)" "n"
	CONFIGURE_FLAGS+= --disable-gtk
	DEBHELPER_OPTIONS+= -Nlibreoffice-gtk -Nlibreoffice-gnome
else
	BUILD_DEPS += , libgtk2.0-dev (>= 2.10)
endif
ifeq "$(BUILD_GTK3)" "y"
       BUILD_DEPS += , libgtk-3-dev (>= 3.2~)
       CONFIGURE_FLAGS+= --enable-gtk3
  ifneq (cairo,$(findstring cairo,$(SYSTEM_STUFF)))
  $(error GTK3 build fails without system-cairo!!)
  endif
else
       DEBHELPER_OPTIONS+= -Nlibreoffice-gtk3
endif

ifeq "$(ENABLE_EVO2)" "n"
	CONFIGURE_FLAGS += --disable-evolution2
	DEBHELPER_OPTIONS += -Nlibreoffice-evolution
else
	CONFIGURE_FLAGS += --enable-evolution2
	BUILD_DEPS += , libebook1.2-dev
endif

ifeq "$(ENABLE_SDBC_POSTGRESQL)" "y"
  ifneq (,$(filter postgresql, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libpq-dev (>= 9.0~)
  else
	BUILD_DEPS += , libkrb5-dev
  endif
else
	CONFIGURE_FLAGS += --disable-postgresql-sdbc
endif

ifeq "$(ENABLE_RANDR)" "y"
	BUILD_DEPS += , libxrandr-dev
else
	CONFIGURE_FLAGS += --disable-randr
endif

ifneq "$(ENABLE_PYTHON)" "y"
	DEBHELPER_OPTIONS+= -Npython-uno -Npython3-uno -Nlibreoffice-script-provider-python
  ifeq "$(BUILD_ISOS)" "en-US"
	CONFIGURE_FLAGS += --disable-python
  else
	$(error you can not disable python when building with translations)
  endif
else
  ifeq "$(WHEEZY_BACKPORT)" "y"
	DEBHELPER_OPTIONS+= -Npython3-uno
	PYUNO_DEPENDS = python-uno
  else
    ifeq "$(ENABLE_PYTHON2)" "y"
	PYUNO_DEPENDS = python3-uno (>= 4.0~) | python-uno
    else
	PYUNO_DEPENDS = python3-uno (>= 4.0~)
	DEBHELPER_OPTIONS+= -Npython-uno
    endif
  endif
  CONFIGURE_FLAGS += --enable-python=system
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifneq (,$(filter hsqldb, $(SYSTEM_STUFF)))
    ifeq "$(WHEEZY_BACKPORT)" "y"
	BUILD_DEPS += , libhsqldb-java $(HSQLDB_MINVER)$(OOO_NO_JAVA_ARCHS)
	BASE_HSQLDB_DEPENDS = libhsqldb-java $(HSQLDB_MINVER), libhsqldb-java (<< $(HSQLDB_TOONEWVER)~)
	JAVA_GCJ_DEPENDS += , libhsqldb-java-gcj [$(OOO_GCJ_ARCHS)]
    else
	BUILD_DEPS += , libhsqldb1.8.0-java $(HSQLDB_MINVER)$(OOO_NO_JAVA_ARCHS)
	BASE_HSQLDB_DEPENDS = libhsqldb1.8.0-java $(HSQLDB_MINVER)
	JAVA_GCJ_DEPENDS += , libhsqldb1.8.0-java-gcj [$(OOO_GCJ_ARCHS)]
	CONFIGURE_FLAGS += --with-hsqldb-jar=$(HSQLDB_JAR)
    endif
  else
    ifeq "$(JDK)" "gcj-jdk"
	# hsqldb with jdk7 buildfix from jdk7.diff fails with gcj
	$(error hsqldb with jdk7 buildfix from jdk7.diff fails with gcj)
    endif
  endif
  ifeq "$(ENABLE_SCRIPT_PROVIDER_BSH)" "y"
    ifneq (,$(filter beanshell, $(SYSTEM_STUFF)))
      ifneq "$(WHEEZY_BACKPORT)" "y"
	# -gcj is gone
	BUILD_DEPS_INDEP += , libbsh-java
	BSH_DEPENDS = libbsh-java
      else
	BUILD_DEPS_INDEP += , bsh (>= 2.0b4)$(OOO_NO_JAVA_ARCHS)
	BSH_DEPENDS = bsh (>= 2.0b4)
	JAVA_GCJ_DEPENDS += , bsh-gcj [$(OOO_GCJ_ARCHS)]
      endif
    endif
	CONFIGURE_FLAGS += --enable-scripting-beanshell
  else
 	DEBHELPER_OPTIONS += -Nlibreoffice-script-provider-bsh
  endif
  ifeq "$(ENABLE_SCRIPT_PROVIDER_JS)" "y"
	CONFIGURE_FLAGS += --enable-scripting-javascript	
  else
	DEBHELPER_OPTIONS += -Nlibreoffice-script-provider-js
  endif
endif

ifneq (,$(filter lpsolve, $(SYSTEM_STUFF)))
  ifeq "$(USE_SHARED_LPSOLVE)" "y"
	BUILD_DEPS += , liblpsolve55-dev $(LPSOLVE_MIN_VERSION), lp-solve $(LPSOLVE_MIN_VERSION)
	LPSOLVE_DEP = lp-solve $(LPSOLVE_MIN_VERSION)
  else
	BUILD_DEPS += , liblpsolve55-dev $(LPSOLVE_MIN_VERSION)
  endif
  ifeq "$(USE_LIBSUITESPARSE)" "y"
	DBG_DBG_SUGGESTS+= , libsuitesparse-dbg
	BUILD_DEPS += , libsuitesparse-dev $(SUITESPARSE_MIN_VERSION)
  else
	DBG_DBG_SUGGESTS+= , libufsparse-dbg
	BUILD_DEPS += , libufsparse-dev
  endif
endif

ifeq "$(USE_DBUS)" "y"
	BUILD_DEPS += , libdbus-glib-1-dev (>= 0.70)
	CONFIGURE_FLAGS += --enable-dbus
  ifeq "$(ENABLE_BLUETOOTH)" "y"
    ifneq (,$(filter bluez, $(SYSTEM_STUFF)))
       BUILD_DEPS += , libbluetooth-dev [!kfreebsd-amd64 !kfreebsd-i386]
    endif
  else
	CONFIGURE_FLAGS += --disable-sdremote-bluetooth
  endif
endif

ifeq "$(ENABLE_AVAHI)" "y"
	BUILD_DEPS += , libavahi-client-dev
	CONFIGURE_FLAGS += --enable-avahi
endif

ifeq "$(USE_GSTREAMER)" "y"
  ifeq "$(GSTREAMER_VERSION)" "1.0"
	BUILD_DEPS += , libgstreamer$(GSTREAMER_VERSION)-dev
	CONFIGURE_FLAGS += --enable-gstreamer --disable-gstreamer-0-10
  endif
	BUILD_DEPS += , libgstreamer-plugins-base$(GSTREAMER_VERSION)-dev
	GSTREAMER_PLUGINS_SUGGESTS += , gstreamer$(GSTREAMER_VERSION)-plugins-base, gstreamer$(GSTREAMER_VERSION)-plugins-good, gstreamer$(GSTREAMER_VERSION)-plugins-ugly, gstreamer$(GSTREAMER_VERSION)-plugins-bad, gstreamer$(GSTREAMER_VERSION)-ffmpeg
	DBG_DBG_SUGGESTS+= , libgstreamer$(GSTREAMER_VERSION)-0-dbg
	AVMEDIA_BE_DEPENDS += , libreoffice-avmedia-backend-gstreamer
else
	CONFIGURE_FLAGS += --disable-gstreamer-0-10
	DEBHELPER_OPTIONS += -Nlibreoffice-avmedia-backend-gstreamer
endif

ifeq "$(USE_VLC)" "y"
	CONFIGURE_FLAGS += --enable-vlc
	BUILD_DEPS += , $(shell debian/scripts/get_libvlc_dep.sh)
  ifeq "$(AVMEDIA_BE_DEPENDS)" ""
	AVMEDIA_BE_DEPENDS += , libreoffice-avmedia-backend-vlc
  else
	AVMEDIA_BE_DEPENDS += | libreoffice-avmedia-backend-vlc
  endif
else
	DEBHELPER_OPTIONS += -Nlibreoffice-avmedia-backend-vlc
endif

ifeq "$(ENABLE_WEBDAV)" "y"
  ifeq "$(WEBDAV_LIB)" "neon"
    ifneq (,$(filter neon, $(SYSTEM_STUFF)))
      ifneq "$(NEON_SECTYPE)" "openssl"
	BUILD_DEPS += , libneon$(NEONSONR)-$(NEON_SECTYPE)-dev
	DBG_DBG_SUGGESTS+= , libneon$(NEONSONR)-$(NEON_SECTYPE)-dbg
      else
	BUILD_DEPS += , libneon$(NEONSONR)-dev
	DBG_DBG_SUGGESTS+= , libneon$(NEONSONR)-dbg
      endif
    endif
  else
    ifneq (,$(filter apr, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libaprutil1-dev
    endif
    ifneq (,$(filter serf, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libserf-dev
    endif
  endif
  CONFIGURE_FLAGS += --with-webdav=$(WEBDAV_LIB)
else
  CONFIGURE_FLAGS += --with-webdav=no
endif

ifeq "$(ENABLE_HELP)" "n"
	CONFIGURE_FLAGS += --without-helppack-integration --without-help
endif

ifneq (,$(filter redland, $(SYSTEM_STUFF)))
	BUILD_DEPS += , librdf0-dev (>= 1.0.16-2)
	SHLIBS_OVERRIDE += -Xunordf
endif

ifneq (,$(filter glew, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libglew-dev
endif
ifneq (,$(filter glm, $(SYSTEM_STUFF)))
	BUILD_DEPS += , libglm-dev
endif

ifeq "$(ENABLE_GIO)" "y"
	BUILD_DEPS += , libglib2.0-dev (>= 2.15.0)
else
	CONFIGURE_FLAGS += --disable-gio
endif

ifeq "$(ENABLE_GVFS)" "y"
	BUILD_DEPS += , libgnomevfs2-dev
	CONFIGURE_FLAGS += --enable-gnome-vfs
endif

ifeq "$(ENABLE_GCONF)" "y"
	BUILD_DEPS += , libgconf2-dev
else
	CONFIGURE_FLAGS += --disable-gconf
endif
	BUILD_DEPS += , gettext

ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	BUILD_DEPS_INDEP += , fontforge
endif

ifeq ($(ENABLE_MERGELIBS),y)
	CONFIGURE_FLAGS += --enable-mergelibs
endif

ifneq "$(WHEEZY_BACKPORT)" "y"
  DEJAVU_DEPENDS=fonts-dejavu
else
  DEJAVU_DEPENDS=ttf-dejavu
endif

# Use compiler cache?  Include ccache in DEB_BUILD_OPTIONS for much faster rebuild times
# A complete build uses about 9G of compiler cache.
ifneq (ccache,$(findstring ccache,$(DEB_BUILD_OPTIONS)))
	CONFIGURE_FLAGS += --disable-ccache
endif

## Build n projects in parallel?
## DEB_BUILD_OPTIONS=parallel=<n>
## if not specified LibreOffices configure tries to find it out itself
NUM_CPUS=$(shell echo "$(DEB_BUILD_OPTIONS) " | sed -n 's/^\(.* \)\?parallel=\([0-9]\+\).*$$/\2/p')
AVAIL_CPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
ifeq "$(PARALLEL_BUILD)" "y"
	# http://bugs.debian.org/622644
	BUILD_DEPS += , make (>= 3.81-8.2)
  # we need to specify it only if it differs, otherwise configure autodetects
  # it.
  ifneq "$(NUM_CPUS)" "$(AVAIL_CPUS)"
	CONFIGURE_FLAGS += --with-parallelism=$(NUM_CPUS)
  endif
else
	CONFIGURE_FLAGS += --without-parallelism
endif

ifeq ($(GCC_VERSION),)
	BUILD_PATH = /usr/lib/jvm/java-gcj/bin:$$PATH
else
  ifeq ($(GCC_VERSION),snapshot)
	BUILD_PATH = /usr/lib/jvm/java-gcj/bin:/usr/lib/gcc-snapshot/bin:$$PATH
	BUILD_LD_LIBRARY_PATH = /usr/lib/gcc-snapshot/lib:$$LD_LIBRARY_PATH
	BUILD_DEPS += , gcc-snapshot
  else
	BUILD_PATH = /usr/lib/jvm/java-gcj/bin:$(CURDIR)/debian/usr/bin:$$PATH
  endif
endif
BUILD_PATH := $(CURDIR)/debian/usr/bin:$(BUILD_PATH)
BUILD_LD_LIBRARY_PATH := $(BUILD_LD_LIBRARY_PATH):$(GCJ_JAWT_DIR)

# Because of the stampdir magic, when you actually want to run a rule
# over, you would have to remove the stamp manually.  Now, just do
# 'debian/rules <target> <target> ... FORCE=1', and the stamp files
# that match the given targets will be removed automagically.
stampdir_targets+=prepare
stampdir_targets+=build build-arch build-indep maintscripts
stampdir_targets+=install-common install-arch install-indep langpacks
stampdir_targets+=binary-arch binary-indep
ifdef FORCE
 DUMMY:=$(shell rm -f $(patsubst %,$(STAMP_DIR)/%,$(filter $(stampdir_targets),$(MAKECMDGOALS))))
endif

# If this is defined, then none of the 'long' commands will be run.  Useful
# for testing.
# test_rules=1

# Since the final stages use up a large amount of diskspace, provide targets to
# remove them without needing a full rebuild

# Clean up the package directories (about 830M) 
clean-debdir:
	dh_testdir
	# remove generated symlinks / java wrappers
	rm -rf debian/usr

	find debian -name "*.links" ! -name "libreoffice-dev-doc.links" \
		! -name "libreoffice-java-common.links" -exec rm {} \;
	if [ -d "$(STAMP_DIR)" ]; then rm -rf "$(STAMP_DIR)"; fi
	rm -f debian/*.bug-script
	rm -f debian/scripts/aotcompile.py*

	rm -f l10n.fdupes
	rm -f debian/shlibs.local
	rm -f debian/*.templates

	rm -f debian/libreoffice-dev-doc.doc-base.*
	rm -f debian/*.install debian/*.dirs debian/*.changelog
	rm -f debian/catalog.xml
	rm -f debian/openoffice.org-dtd-officedocument1.0.xmlcatalogs
	rm -f debian/*.postinst debian/*.postrm debian/*.preinst debian/*.prerm debian/*.triggers
	rm -f debian/pom*.xml

	mh_clean
	dh_clean

clean:
	dh_testroot
	dh_testdir

	if [ -f config.status ]; then \
		$(MAKE) distclean; \
		rm -f config.status; \
	fi
	find $(SOURCE_TREE) -name "*.pyc" -exec rm {} \;
	rm -rf */*.pro.obsolete

	rm -rf $(SOURCE_TREE)/file-lists
	rm -rf $(SOURCE_TREE)/pyuno-for*
	rm -f autogen.lastrun
	rm -f build_error.log
	rm -f config/config_version.h

ifeq "$(HELPISOS)" ""
	rm -rf images*
endif

	rm -f download.list

	# Files created in debian directory
	$(MAKE) -f debian/rules clean-debdir

	$(MAKE) -f debian/rules control


# Generate control file, because we have so many different languages
# Based on script by Martin Quinson <Martin.Quinson@tuxfamily.org>
control: debian/control
debian/control: $(wildcard debian/control*in) $(SOURCE_TREE)/bin/lo-xlate-lang  debian/rules
	chmod 755 $(SOURCE_TREE)/bin/lo-xlate-lang
	sed -e "s#%$(DEB_VENDOR)=\([^%]*\)%#, \1#g#" \
	    -e "s#%[A-Za-z]*=[^%]*%##g#" \
	    -e "s#%BUILD_DEPS_INDEP%#$(strip $(BUILD_DEPS_INDEP))#g" \
	    -e "s#@PYTHON_VERSION_CONTROL@#$(PYTHON_VERSION_CONTROL)#g" \
	    -e "s#@PYTHON2_VERSION@#$(PYTHON2_VERSION)#g" \
	    -e "s#@BUGS@#$(BUGS)#g" \
	    < debian/control.in > debian/control

	for LNUM in $(filter-out en-US,$(LANGPACKISOS)) ; do \
	    LNAME=`$(SOURCE_TREE)/bin/lo-xlate-lang -l $$LNUM | perl -e 'print ucfirst(<STDIN>);'`; \
	    LCODE=`$(SOURCE_TREE)/bin/lo-xlate-lang -i $$LNUM | tr A-Z a-z`; \
	    [ "$$LNUM" = ca-valencia ] && continue; \
	    [ "$$LCODE" = kmr-latn ] && LCODE=kmr; \
	    CCODE=`echo $$LCODE | sed 's/-.*//'`; \
	    case "$$LCODE" in \
		bn) \
			FONT_SUGGESTS=", fonts-beng"; \
			;; \
		gu) \
			FONT_SUGGESTS=", fonts-gujr"; \
			;; \
		pa-in) \
			FONT_SUGGESTS=", fonts-guru"; \
			;; \
		ml) \
			FONT_SUGGESTS=", fonts-mlym"; \
			;; \
		or) \
			FONT_SUGGESTS=", fonts-orya"; \
			;; \
		te) \
			FONT_SUGGESTS=", fonts-telu"; \
			;; \
		ta) \
			FONT_SUGGESTS=", fonts-taml"; \
			;; \
		hi-in|ne|mr) \
			FONT_SUGGESTS=", fonts-deva"; \
			;; \
		he) \
			FONT_SUGGESTS=", culmus"; \
			;; \
		km) \
			FONT_SUGGESTS=", fonts-khmeros"; \
			;; \
		ar) \
			FONT_SUGGESTS=", fonts-arabeyes"; \
			;; \
		fa) \
			FONT_SUGGESTS=", fonts-farsiweb"; \
			;; \
		dz) \
			FONT_SUGGESTS=", fonts-dzongkha"; \
			;; \
		th) \
			FONT_SUGGESTS=", fonts-thai-tlwg"; \
			;; \
		*) \
			FONT_SUGGESTS= ;; \
	    esac; \
	    case "$$LCODE" in \
		rw) \
			LOCALES_DEPENDS="locales (>= 2.3.6) | locales-all (>= 2.3.6)" \
			;; \
		ss|ts|km|ns|tn) \
			LOCALES_DEPENDS="locales (>= 2.3.5-12) | locales-all" \
			;; \
		sr) \
			LOCALES_DEPENDS="locales (>= 2.3.6.ds1-5) | locales-all" \
			;; \
		as|or|nr) \
			LOCALES_DEPENDS="locales (>= 2.3.6.ds1-1) | locales-all (>= 2.3.6.ds1-1)" \
			;; \
		sw) \
			LOCALES_DEPENDS="locales (>= 2.13-5) | locales-all (>= 2.13-5)" \
			;; \
		*) \
			LOCALES_DEPENDS="locales | locales-all" \
			;; \
	    esac; \
	    sed -e "s|@LNAME@|$$LNAME|g" -e "s|@LCODE@|$$LCODE|g" \
		-e "s|@CCODE@|$$CCODE|g" \
	        -e "s|@FONT_SUGGESTS@|$$FONT_SUGGESTS|g" \
	        -e "s:@LOCALES_DEPENDS@:$$LOCALES_DEPENDS:g" \
		-e "s|@LDAP_LIB@|$(LDAP_LIB)|g" \
	        >> debian/control < debian/control.lang.in; \
	done
	cat debian/control.transitionals.in >> debian/control

ifneq "$(ENABLE_HELP)" "n"
	for LNUM in $(HELPISOS) ; do \
	    LNAME=`$(SOURCE_TREE)/bin/lo-xlate-lang -l $$LNUM | perl -e 'print ucfirst(<STDIN>);'`; \
	    LCODE=`$(SOURCE_TREE)/bin/lo-xlate-lang -i $$LNUM | tr A-Z a-z`; \
	    [ "$$LNUM" = ca-valencia ] && continue; \
	    CCODE=`echo $$LCODE | sed 's/-.*//'`; \
	    sed -e "s|@LNAME@|$$LNAME|g" -e "s|@LCODE@|$$LCODE|g" \
		-e "s|@CCODE@|$$CCODE|g" \
	        >> debian/control < debian/control.help.in; \
	done
	# en_US is in -common
	perl -pi -e 's|(Depends: libreoffice-writer \| language-support-translations-en), libreoffice-l10n-en-us|\1|' \
		debian/control
	perl -pi -e 's|(Depends: libreoffice-writer, libreoffice-l10n-en-us)|\1, fonts-deva|' \
		debian/control
endif
	cat debian/control.ure.in >> debian/control
ifeq "$(ENABLE_JAVA)" "y"
  ifneq "$(OOO_GCJ_JDK_ARCHS)" ""
    ifeq "$(BUILD_JARS_NATIVE)" "y"
	cat debian/control.gcj.in >> debian/control
    endif
  endif
endif
ifneq "$(OOO_NSPLUGIN_ARCHS)" ""
	cat debian/control.mozilla.in >> debian/control
endif
ifneq "$(OOO_OGLTRANS_ARCHS)" ""
	cat debian/control.ogltrans.in >> debian/control
endif
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	cat debian/control.mediawiki.in >> debian/control
  endif
  ifeq "$(ENABLE_REPORTDESIGN)" "y"
	cat debian/control.reportdesign.in >> debian/control
  endif
endif
ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	cat debian/control.fonts.in >> debian/control
endif
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	cat debian/control.debug.in >> debian/control
endif
ifeq "$(PACKAGE_SDK)" "y"
	cat debian/control.sdk.in >> debian/control
endif
ifeq "$(BUILD_KDE)" "y"
	cat debian/control.kde.in >> debian/control
endif
ifeq "$(ENABLE_SDBC_POSTGRESQL)" "y"
	cat debian/control.postgresql.in >> debian/control
endif
ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	cat debian/control.mysql.in >> debian/control
endif
ifeq "$(ENABLE_EVO2)" "y"
	cat debian/control.evolution.in >> debian/control
endif
ifeq "$(ENABLE_KDEAB)" "y"
	cat debian/control.kab.in >> debian/control
endif
ifeq "$(BUILD_TEST_PACKAGE)" "y"
  ifneq "$(OOO_JAVA_ARCHS)" ""
	cat debian/control.subsequentcheckbase.in >> debian/control
  endif
endif
ifeq "$(PACKAGE_LIBRELOGO)" "y"
	cat debian/control.librelogo.in >> debian/control
endif

	perl -pi -e "s,%OOO_ARCHS%,$(OOO_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_BE_ARCHS%,$(OOO_BE_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_LE_ARCHS%,$(OOO_LE_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_BASE_ARCHS%,$(OOO_BASE_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_NO_BASE_ARCHS%,$(OOO_NO_BASE_ARCHS),"g debian/control
	perl -pi -e "s,%OOO_JAVA_ARCHS%,$(OOO_JAVA_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_GCJ_ARCHS%,$(OOO_GCJ_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_NSPLUGIN_ARCHS%,$(OOO_NSPLUGIN_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_OGLTRANS_ARCHS%,$(OOO_OGLTRANS_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_GCJ_JDK_ARCHS%,$(OOO_GCJ_JDK_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_ARCH_DEP_EXTENSIONS_ARCHS%,$(OOO_ARCH_DEP_EXTENSIONS_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_REPORTDESIGN_ARCHS%,$(OOO_REPORTDESIGN_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_NO_REPORTDESIGN_ARCHS%,$(OOO_NO_REPORTDESIGN_ARCHS),g" debian/control
	perl -pi -e "s#%BUILD_DEPS%#$(strip $(BUILD_DEPS))#g" debian/control
ifeq "$(BUILD_TEST_PACKAGE)" "y"
	# we want the build deps as dep on subsequentcheckbase, but strip the arch
	# specifics as we are arch-all
	# for now we filter out the arch-specific libc* and ia64, which is ugly,
	# but better than manual bookkeeping. Also filter out the mips(el)-only
	# binutils build-dep...
	perl -pi -e "s#%BUILD_DEPS_ARCH_ALL%#$(strip $(shell echo '$(BUILD_DEPS), $(BUILD_DEPS_INDEP)'|sed -e 's/,/,\n /g'|grep -v libc0.1| grep -v libc6| grep -v ia64|grep -v binutils|grep -v gcj-jdk|grep -v gcj-native-helper|grep -v libgcj-common|grep -v openjdk-6-jdk|sed -e 's/\[[^]]*\]//g'))#g" debian/control
endif
ifeq "$(BUILD_KDE)" "y"
	perl -pi -e 's/%LO-DESKTOP-INTEGRATION%/libreoffice-gnome | libreoffice-kde/' debian/control
else
	perl -pi -e 's/%LO-DESKTOP-INTEGRATION%/libreoffice-gnome/' debian/control
endif

ifeq (sk,$(findstring sk,$(HELPISOS)))
	perl -pi -e 's/(Depends:.*)libreoffice-l10n-sk(.*)$$/\1libreoffice-l10n-sk, libreoffice-help-cs\2/' debian/control
endif
ifeq (pt-BR,$(findstring pt-BR,$(LANGPACKISOS)))
	perl -pi -e 's/libreoffice2-l10n-pt-br$$/libreoffice2-l10n-pt-br, broffice/' debian/control
	perl -pi -e 's/libreoffice2-l10n-pt-br$$/libreoffice2-l10n-pt-br, broffice/' debian/control
	perl -pi -e 's/libreoffice2-l10n-pt-br$$/libreoffice2-l10n-pt-br, broffice/' debian/control
endif
	perl -pi -e 's/Package: libreoffice-help-en-us/Package: libreoffice-help-en-us\nReplaces: libreoffice-common (<< 1:3.0.0~dev300m28)/' debian/control

ifeq "$(ENABLE_GIO)" "y"
	perl -pi -e 's/VFS/GIO/' debian/control
	# fix up "GNOME GIO"
	perl -pi -e 's/GNOME GIO/GIO/' debian/control
endif

ifeq "$(WHEEZY_BACKPORT)" "y"
  ifneq (,$(filter hsqldb, $(SYSTEM_STUFF)))
	perl -pi -e "s/(Build-Conflicts: .*)/\1,libhsqldb-java (>= $(HSQLDB_TOONEWVER)~),/" debian/control
  endif
endif

ifneq "$(USE_MARIADB)" "y"
	perl -pi -e "s/(Build-Conflicts: .*)/\1,libmariadbclient-dev,/" debian/control
endif

ifeq (4.4,$(SYSTEM_GCC_VERSION))
	perl -pi -e 's/flex \|/flex (>= 2.5.25-7) |/' debian/control
endif

ifeq "$(BUILD_TEST_PACKAGE)" "y"
	perl -pi -e 's/Vcs-Git:/XS-Testsuite: autopkgtest\nVcs-Git:/' debian/control
endif

	python debian/scripts/joinctrl.py < debian/control > debian/control.tmp
	mv debian/control.tmp debian/control

	# no conflict with "universal Linux packages" as they have the version in their
	# names thankfully now
	perl -pi -e 's/libreoffice-unbundled, //' debian/control

	# make -l10n-fi suggest libreoffice-spellcheck-fi to
	# match myspell-fi and libreoffice-soikko/-voikko
	perl -pi -e 's/myspell-dictionary-fi/myspell-dictionary-fi | libreoffice-spellcheck-fi/' debian/control
	# similar for tr (libreoffice-zemberek)
	perl -pi -e 's/myspell-dictionary-tr/myspell-dictionary-tr | libreoffice-spellcheck-tr/' debian/control

ifeq "$(BUILD_KDE)" "y"
	perl -pi -e 's/GConf backend$$/GConf backend\n  * libreoffice-kde: KDE UI Plugin and KDE File Picker support/' debian/control
endif

ifeq "$(USE_DBUS)" "y"
	perl -pi -e 's/paperconf$$/paperconf\n  * bluez: Bluetooth support for Impress (slideshow remote control/' debian/control
	perl -pi -e 's/Description: office productivity suite -- presentation/Suggests: bluez\nDescription: office productivity suite -- presentation/' debian/control
endif

ifneq "$(DICT_DIR)" "/usr/share/hunspell"
	perl -pi -e 's/^Breaks:.*myspell.*\n//' debian/control
endif

.DELETE_ON_ERROR: debian/control

# All 'important' targets have 2 lines.  The one that is run by
# dpkg-buildpackage or the user, and the one that does the actual work.  This
# indirection is needed so that the 'stamp' files that signify when a rule is
# done can be located in a separate 'stampdir'.  Recall that make has no way to
# know when a goal has been met for a phony target (like "build" or "install").
#
# At the end of each stampdir target, be sure to run the command 'touch $@'
# so that the target will not be run again.  Removing the file will make
# make run the target over.

prepare: $(STAMP_DIR)/prepare
$(STAMP_DIR)/prepare:
	dh_testdir

	# Make sure needed scripts are executable
	set -e;\
	for FILE in debian/scripts/move-if-change \
		    debian/scripts/cleandupes \
		    debian/scripts/get_libebook_dep.sh \
		    debian/scripts/get_libvlc_dep.sh \
		    autogen.sh; \
	do \
	  chmod 755 $$FILE ;\
	done

	mkdir -p $(STAMP_DIR)

	# Make sure we have /proc mounted - otherwise idlc will fail later.
	test -r /proc/version

ifneq "$(PACKAGE_UNOWINREG_DLL)" "y"
  ifneq "$(BUILD_UNOWINREG_DLL)" "y"
	# create fake file if file not there; we don't use it anyways.
	if [ ! -f $(TARFILE_LOCATION)/185d60944ea767075d27247c3162b3bc-unowinreg.dll ]; then \
		touch $(TARFILE_LOCATION)/185d60944ea767075d27247c3162b3bc-unowinreg.dll; \
	fi
  endif
endif

	touch $@

.PHONY: config_host.mk
config_host.mk:
	rm -f config.status autogen.lastrun
	PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) ./autogen.sh $(CONFIGURE_FLAGS) $(CONFIGURE_FLAGS_LANG)

build:
	$(CURDIR)/debian/rules build-arch
	$(CURDIR)/debian/rules build-indep
	touch $(STAMP_DIR)/$@

build-arch: $(STAMP_DIR)/prepare $(STAMP_DIR)/build-arch
$(STAMP_DIR)/build-arch:
#build-arch: ENABLE_HELP = n PACKAGE_SDK_DOCS = n ENABLE_MEDIAWIKI = n ENABLE_REPORTDESIGN = n ENABLE_SCRIPT_PROVIDER_BSH = n ENABLE_SCRIPT_PROVIDER_JS = n
	dh_testdir

	# FIXME: Theoretically this should call ./configure instead of
	# it exists but that causes the configure flags NOT to be hnoured
	# somehow...
	PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) \
	PYTHON=$(PYTHON) PYTHON_CFLAGS="$(shell pkg-config --cflags python-$(PYMAJOR).$(PYMINOR))" PYTHON_LIBS="$(shell pkg-config --libs python-$(PYMAJOR).$(PYMINOR))" \
	MARIADBCONFIG=$(MARIADBCONFIG) \
	FIREBIRD_CFLAGS=$(FIREBIRD_CFLAGS) FIREBIRD_LIBS=$(FIREBIRD_LIBS) \
	./autogen.sh $(CONFIGURE_FLAGS) \
		--without-doxygen --without-javadoc --disable-ext-wiki-publisher \
		--disable-report-builder --disable-scripting-javascript \
		--disable-scripting-beanshell \
		--with-galleries=no

ifneq "$(WHEEZY_BACKPORT)" "y"
	# setting PYTHON_FOR_BUILD above does NOT work and otherwise it
	# might pick up /usr/bin/python (python 2!) due to wheezy-backports-python.diff
	# which will not work.
	perl -pi -e 's/export PYTHON_FOR_BUILD=.*/export PYTHON_FOR_BUILD=$(PYTHON)/' config_host.mk
endif

	PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) ARCH_FLAGS=$(ARCH_FLAGS) TMP=`mktemp -q -d` $(MAKE) build-non-l10n-only

ifneq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	$(CURDIR)/debian/rules check
endif

ifneq "$(WHEEZY_BACKPORT)" "y"
  ifeq "$(ENABLE_PYTHON)" "y"
    ifeq "$(ENABLE_PYTHON2)" "y"
	# remove python3 pyUNO...
	$(MAKE) pyuno.clean
	# ... so that we can build it for python2...
	make cmd cmd='cd pyuno; export PYTHON=$(PYTHON2); export PYTHON_CFLAGS="$(shell pkg-config --cflags python-$(PY2MAJOR).$(PY2MINOR))"; export PYTHON_LIBS="$(shell pkg-config --libs python-$(PY2MAJOR).$(PY2MINOR))"; $(MAKE)'
	# copy the libs away
	rm -rf debian/pyuno-for-$(PY2MAJOR).$(PY2MINOR)
	mkdir -p debian/pyuno-for-$(PY2MAJOR).$(PY2MINOR)
	for i in pyuno.so libpyuno.so libpythonloaderlo.so; do \
		cp $(SOURCE_TREE)/instdir/program/$$i \
			debian/pyuno-for-$(PY2MAJOR).$(PY2MINOR); \
	done
	# and build the correct one again
	$(MAKE) pyuno.clean
	make pyuno
    endif
  endif
endif

ifneq "$(BUILD_ISOS)" "en-US"
	# build sysui and some extensions again with all languages; as it contains language-specific help
	# and/or descriptions...
	$(MAKE) sysui.clean
	$(MAKE) mysqlc.clean
	make cmd cmd="cd sysui; export WITH_LANG='$(LANGPACKISOS)'; export WITH_LANG_LIST='$(LANGPACKISOS)'; $(MAKE)"
	make cmd cmd="cd mysqlc; export WITH_LANG='$(LANGPACKISOS)'; export WITH_LANG_LIST='$(LANGPACKISOS)'; $(MAKE)"
endif

	touch $@

build-indep: $(STAMP_DIR)/prepare $(STAMP_DIR)/build-arch $(STAMP_DIR)/build-indep
$(STAMP_DIR)/build-indep:
	dh_testdir

	$(MAKE) odk.clean
	$(MAKE) scp2.clean
	# FIXME: those are arch-indep but somehow fail in the second run
 	# with all languages - handle it like the ones in binary-arch. The
	# rebuild automatically will be done, though.
	$(MAKE) swext.clean
	$(MAKE) reportbuilder.clean
	rm -f config.status autogen.lastrun

	PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) \
	PYTHON=$(PYTHON) PYTHON_CFLAGS="$(shell pkg-config --cflags python-$(PYMAJOR).$(PYMINOR))" PYTHON_LIBS="$(shell pkg-config --libs python-$(PYMAJOR).$(PYMINOR))" \
	MARIADBCONFIG=$(MARIADBCONFIG) \
	FIREBIRD_CFLAGS=$(FIREBIRD_CFLAGS) FIREBIRD_LIBS=$(FIREBIRD_LIBS) \
	./autogen.sh $(CONFIGURE_FLAGS) --with-help $(CONFIGURE_FLAGS_LANG)

ifneq "$(WHEEZY_BACKPORT)" "y"
	# setting PYTHON_FOR_BUILD above does NOT work and otherwise it
	# might pick up /usr/bin/python (python 2!) due to wheezy-backports-python.diff
	# which will not work.
	perl -pi -e 's/export PYTHON_FOR_BUILD=.*/export PYTHON_FOR_BUILD=$(PYTHON)/' config_host.mk
endif

	PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) ARCH_FLAGS=$(ARCH_FLAGS) TMP=`mktemp -q -d` $(MAKE) build-nocheck

	touch $@

check: 
ifeq "$(RUN_MAKE_CHECK)" "y"
ifneq (,$(findstring $(DEB_HOST_ARCH),$(OOO_NO_BASE_ARCHS)))
	patch -p1 < $(CURDIR)/debian/patches/disable-db-tests.diff
endif
ifeq (,$(findstring $(DEB_HOST_ARCH),$(OOO_EXTENSIONS_ARCHS)))
	cd $(SOURCE_TREE)/smoketest && \
		patch -p1 < $(CURDIR)/debian/patches/smoketest-disable-extension-tests.diff
endif

	$(IGNORE_MAKE_CHECK_FAILURES)t=`mktemp -q -d`; \
	cd $(SOURCE_TREE) && \
		export PATH=$(BUILD_PATH); \
		export TMPDIR=$$t; \
		export HOME=$$t; \
		export SAL_USE_VCLPLUGIN="svp"; \
		if [ -x /usr/bin/gdb ]; then ulimit -c unlimited; fi && \
		PARALLELISM=1 $(MAKE) -k $(CHECKTARGET) || PARALLELISM=1 $(MAKE) $(CHECKTARGET) && \
	rm -rf $$t

ifneq (,$(findstring $(DEB_HOST_ARCH),$(OOO_NO_BASE_ARCHS)))
	patch -p1 -R < $(CURDIR)/debian/patches/disable-db-tests.diff
endif
ifeq (,$(findstring $(DEB_HOST_ARCH),$(OOO_EXTENSIONS_ARCHS)))
	cd $(SOURCE_TREE)/smoketest && \
		patch -p1 -R < $(CURDIR)/debian/patches/smoketest-disable-extension-tests.diff
endif
endif

ifeq "$(RUN_PYTESTS)" "y"
	cd $(SOURCE_TREE)/pyuno && $(MAKE) PythonTest_pytests
endif

install: $(STAMP_DIR)/install-common $(STAMP_DIR)/install-arch $(STAMP_DIR)/install-indep

install-common: $(STAMP_DIR)/install-common
$(STAMP_DIR)/install-common:
	dh_testdir
	dh_testroot

	if [ -x /usr/bin/dh_prep ]; then dh_prep; else dh_clean -k; fi
	rm -f debian/*.install debian/*.dirs

	# remove those for safety in case the languages might change on
	# testbuilds. then the /*/ in dh_installdocs in binary-* won't work
	# anymore (different dirs)
	rm -rf $(SOURCE_TREE)/instsetoo_native/util/LibreOffice

	rm -rf $(SOURCE_TREE)/file-lists

	# install LibreOffice.
	cd $(SOURCE_TREE)/; \
		 PATH=$(BUILD_PATH) \
		 DESTDIR=$(CURDIR)/debian/tmp \
		 $(MAKE) distro-pack-install
	export DESTDIR=$(CURDIR)/debian/tmp ;\
	export VERSION=$(OOVER); \
	export OOINSTBASE=$(OODIR); \
	export OOO_LANGS_LIST="$(ISOS)"; \
	$(CURDIR)/debian/scripts/gid2pkgdirs.sh
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	make cmd cmd="export DESTDIR=$(CURDIR)/debian/tmp; install-gdb-printers -a /usr/share/gdb/auto-load/$(OODIR) -c -i /$(OODIR) -p /usr/share/libreoffice/gdb"
endif

	# FIXME
	cd $(CURDIR)/debian/tmp/pkg && rm -rf \*
	
	# prepare install/dir files for dh
	for i in `cd $(CURDIR)/debian/tmp/pkg; ls -1 | xargs`; do \
		echo "$${i}/usr/* usr" > debian/$$i.install; \
		if [ "$$i" = "libreoffice-common" ]; then \
			echo "$${i}/etc/* etc" >> debian/$$i.install; \
		fi; \
		(cd debian/tmp/pkg/$$i; find . -type d | sed -e "s,\./,,") \
			> debian/$$i.dirs; \
	done

	# the english resources should be in -common
	cat debian/libreoffice-l10n-en-US.dirs >> debian/libreoffice-common.dirs
	cat debian/libreoffice-l10n-en-US.install >> debian/libreoffice-common.install
	rm -f debian/libreoffice-l10n-en-US.dirs debian/libreoffice-l10n-en-US.install

	# and ca-valencia in -ca...
ifeq (ca-valencia,$(findstring ca-valencia,$(LANGPACKISOS)))
	if [ -f debian/libreoffice-l10n-ca-valencia.dirs -a -f debian/libreoffice-l10n-ca-valencia.install ]; then \
		cat debian/libreoffice-l10n-ca-valencia.dirs >> debian/libreoffice-l10n-ca.dirs; \
		cat debian/libreoffice-l10n-ca-valencia.install >> debian/libreoffice-l10n-ca.install; \
		rm -f debian/libreoffice-l10n-ca-valencia.dirs debian/libreoffice-l10n-ca-valencia.install; \
	fi
endif
ifeq (ca-valencia,$(findstring ca-valencia,$(HELPISOS)))
	if [ -f debian/libreoffice-help-ca-valencia.dirs -a -f debian/libreoffice-help-ca-valencia.install ]; then \
		cat debian/libreoffice-help-ca-valencia.dirs >> debian/libreoffice-help-ca.dirs; \
		cat debian/libreoffice-help-ca-valencia.install >> debian/libreoffice-help-ca.install; \
		rm -f debian/libreoffice-help-ca-valencia.dirs debian/libreoffice-help-ca-valencia.install; \
	fi
endif

	# should be in -kmr...
ifeq (kmr-Latn,$(findstring kmr-Latn,$(LANGPACKISOS)))
	if [ -f debian/libreoffice-l10n-kmr-Latn.dirs -a -f debian/libreoffice-l10n-kmr-Latn.install ]; then \
		cat debian/libreoffice-l10n-kmr-Latn.dirs >> debian/libreoffice-l10n-kmr.dirs; \
		cat debian/libreoffice-l10n-kmr-Latn.install >> debian/libreoffice-l10n-kmr.install; \
		rm -f debian/libreoffice-l10n-kmr-Latn.dirs debian/libreoffice-l10n-kmr-Latn.install; \
	fi
endif

	# fixup case (-l10n-pt-BR -> l10n-pt-br etc.)
	for iso in $(ISOS); do \
		pkgiso=`echo $$iso | tr A-Z a-z`; \
		if [ "$$iso" != "$$pkgiso" ]; then \
			if [ "$$iso" != "en-US" -a \
			  -e debian/libreoffice-l10n-$$iso.dirs -a \
			  -e debian/libreoffice-l10n-$$iso.install ]; then \
				mv debian/libreoffice-l10n-$$iso.dirs \
					debian/libreoffice-l10n-$$pkgiso.dirs; \
				mv debian/libreoffice-l10n-$$iso.install \
					debian/libreoffice-l10n-$$pkgiso.install; \
			fi; \
			if [ -e debian/libreoffice-help-$$iso.dirs -a \
			  -e debian/libreoffice-help-$$iso.install ]; then \
				mv debian/libreoffice-help-$$iso.dirs \
					debian/libreoffice-help-$$pkgiso.dirs; \
				mv debian/libreoffice-help-$$iso.install \
					debian/libreoffice-help-$$pkgiso.install; \
			fi; \
		fi; \
	done

	# fix up still sneaking in ./. They break dh_install (it installs
	# but wrongly complains about it as not-installed files)
	perl -pi -e 's,\./,,' debian/libreoffice-common.install
	perl -pi -e 's,\./,,' debian/ure.install

ifneq "$(ENABLE_HELP)" "n"
	# remove non-packaged localized help. This a) saves space 
	# and b) we need this for the following dh_install as there will be
	# no .install files created and dh_install will warn/fail due
	# to non-installed files.
	for iso in $(filter-out en-US,$(LANGPACKISOS)); do \
		if ! `echo $(HELPISOS) | grep -q $$iso` || [ "$$iso" = "sk" ] ; then \
			pkgiso=`echo $$iso | tr A-Z a-z`; \
			rm -rf debian/tmp/pkg/libreoffice-help-$$iso; \
			rm -f debian/libreoffice-help-$$pkgiso.dirs; \
			rm -f debian/libreoffice-help-$$pkgiso.install; \
		fi; \
	done
endif

ifneq "$(PACKAGE_LIBRELOGO)" "y"
	rm -rf debian/tmp/pkg/libreoffice-librelogo
endif

	dh_installdirs -A
	dh_install -A --sourcedir=debian/tmp/pkg --fail-missing

	rm -rf debian/tmp/pkg

	# move desktop files to their correct packages
	for i in base calc draw impress math writer; do \
		mkdir -p $(PKGDIR)-$$i/$(OODIR)/share/xdg; \
		mv $(PKGDIR)-common/$(OODIR)/share/xdg/$$i.desktop \
			$(PKGDIR)-$$i/$(OODIR)/share/xdg; \
	done

	# move help to /usr/share
	for iso in $(HELPISOS); do \
		pkgiso=`echo $$iso | tr A-Z a-z`; \
		if [ -e $(PKGDIR)-help-$$pkgiso/usr ]; then \
			mv $(PKGDIR)-help-$$pkgiso/usr/lib \
				$(PKGDIR)-help-$$pkgiso/usr/share; \
		fi; \
	done

ifeq (sk,$(findstring sk,$(HELPISOS)))
	# add fake sk help
	mkdir -p $(PKGDIR)-help-sk/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	ln -s cs \
		$(PKGDIR)-help-sk/$(shell echo $(OODIR) | sed -e s/lib/share/)/help/sk
endif

ifeq "$(ENABLE_JAVA)" "y"
	# move officebean.jar into -officebean (They will be moved out of -core
	# in the install-arch target). Do the /usr/share move here already
	mkdir -p $(PKGDIR)-core/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes; \
	mv $(PKGDIR)-common/$(OODIR)/program/classes/officebean.jar \
		$(PKGDIR)-core/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes
	# fix the classpath
	jh_classpath --classpath="ridl.jar unoil.jar jurt.jar juh.jar" \
		$(PKGDIR)-core/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes/officebean.jar
	
  ifeq "$(PACKAGE_BASE)" "y"
	# move sdbc_hsqldb.jar into -base (do the move
	# to /usr/share/java here directly, we do it for the "rest"
	# later
	mkdir -p $(PKGDIR)-base/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes; \
	mkdir -p $(PKGDIR)-base/$(OODIR)/program/classes; \
	mv $(PKGDIR)-common/$(OODIR)/program/classes/sdbc_hsqldb.jar \
		$(PKGDIR)-base/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes; \
	ln -s $(shell echo /$(OODIR) | sed -e s/lib/share/)/program/classes/sdbc_hsqldb.jar \
		$(PKGDIR)-base/$(OODIR)/program/classes/sdbc_hsqldb.jar
    ifneq (,$(filter hsqldb, $(SYSTEM_STUFF)))
	# fix the classpath (file:// breaks javahelper)
	jh_classpath --classpath="$(HSQLDB_JAR) .." \
		$(PKGDIR)-base/$(shell echo /$(OODIR) | sed -e s/lib/share/)/program/classes/sdbc_hsqldb.jar
    endif
    ifeq (,$(filter hsqldb, $(SYSTEM_STUFF)))
	# we need this in -base. Otherwise we get unwanted package differences
	# in the unstable version and backports which might use internal hsqldb
	mkdir -p $(PKGDIR)-base/$(OODIR)/program/classes
	mv $(PKGDIR)-common/$(OODIR)/program/classes/hsqldb.jar \
		$(PKGDIR)-base/$(OODIR)/program/classes
    endif
  else
	# remove sdbc_hsqldb.jar. otherwise ends up in -java-common
	rm -f $(PKGDIR)-common/$(OODIR)/program/classes/sdbc_hsqldb.jar
  endif
endif

ifeq "$(BUILD_GTK)" "y"
	# Gtk quickstarter, so to -gtk (via -gnome)
	mkdir -p -m755 $(PKGDIR)-gnome/$(OODIR)/share/xdg
	mv $(PKGDIR)-common/$(OODIR)/share/xdg/qstart.desktop \
		$(PKGDIR)-gnome/$(OODIR)/share/xdg
endif

ifeq "$(BUILD_KDE)" "y"
	mkdir -p $(PKGDIR)-kde/$(OODIR)/program
	mv $(PKGDIR)-common/$(OODIR)/program/kde-open-url \
		$(PKGDIR)-kde/$(OODIR)/program
else
	rm -f $(PKGDIR)-common/$(OODIR)/kde-open-url
endif

ifeq "$(PACKAGE_SDK)" "y"
	# move SDK documentation into own package
	rm -rf $(PKGDIR)-dev-doc
	mkdir -p $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev/docs
	mv $(PKGDIR)-dev/usr/share/doc/libreoffice/sdk/docs/* \
		$(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev/docs
	rmdir $(PKGDIR)-dev/usr/share/doc/libreoffice/sdk/docs
	mkdir -p $(PKGDIR)-dev-doc/$(OOSDKDIR)
	ln -sf /usr/share/doc/libreoffice-dev/docs \
		$(PKGDIR)-dev/$(OOSDKDIR)/docs
	mv $(PKGDIR)-dev/$(OOSDKDIR)/examples \
		$(PKGDIR)-dev-doc/$(OOSDKDIR)
endif

ifeq "$(ENABLE_EVO2)" "y"
	mkdir -p $(PKGDIR)-evolution/$(OODIR)/presets/database
	mkdir -p $(PKGDIR)-evolution/$(OODIR)/share/registry
	mv $(PKGDIR)-common/$(OODIR)/presets/database/evolocal.odb \
		$(PKGDIR)-evolution/$(OODIR)/presets/database
endif

ifeq "$(PACKAGE_SDK)" "y"
	mkdir -p $(PKGDIR)-dev/$(OODIR)/share/glade
	mv $(PKGDIR)-common/$(OODIR)/share/glade/libreoffice-catalog.xml \
		$(PKGDIR)-dev/$(OODIR)/share/glade
else
	rm -rf $(PKGDIR)-common/$(OODIR)/share/glade
endif

	# Access2Base IMHO clearly is -base specific :-)
ifeq "$(PACKAGE_BASE)" "y"
	mkdir -p $(PKGDIR)-base/$(OODIR)/share/basic
	mv $(PKGDIR)-common/$(OODIR)/share/basic/Access2Base \
		$(PKGDIR)-base/$(OODIR)/share/basic
	cp $(PKGDIR)-common/$(OODIR)/share/basic/dialog.xlc \
		$(PKGDIR)-base/$(OODIR)/share/basic
	cp $(PKGDIR)-common/$(OODIR)/share/basic/script.xlc \
		$(PKGDIR)-base/$(OODIR)/share/basic
	# FIXME. Does not scale. This has to be a diversion...
	t=`mktemp -q`; grep -v Access2Base $(PKGDIR)-common/$(OODIR)/share/basic/dialog.xlc > \
		$$t && mv $$t $(PKGDIR)-common/$(OODIR)/share/basic/dialog.xlc && rm -f $$t
	t=`mktemp -q`; grep -v Access2Base $(PKGDIR)-common/$(OODIR)/share/basic/script.xlc > \
		$$t && mv $$t $(PKGDIR)-common/$(OODIR)/share/basic/script.xlc && rm -f $$t
else
	rm -rf $(PKGDIR)-common/$(OODIR)/share/basic/Access2Base
	t=`mktemp -q`; grep -v Access2Base $(PKGDIR)-common/$(OODIR)/share/basic/dialog.xlc > \
		$$t && mv $$t $(PKGDIR)-common/$(OODIR)/share/basic/dialog.xlc && rm -f $$t
	t=`mktemp -q`; grep -v Access2Base $(PKGDIR)-common/$(OODIR)/share/basic/script.xlc > \
		$$t && mv $$t $(PKGDIR)-common/$(OODIR)/share/basic/script.xlc && rm -f $$t
endif

ifeq "$(PACKAGE_SDK)" "y"
	# move gengal stuff into -dev
	mkdir -p $(PKGDIR)-dev/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/gengal.bin \
		$(PKGDIR)-dev/$(OODIR)/program
	mv $(PKGDIR)-common/$(OODIR)/program/gengal \
		$(PKGDIR)-dev/$(OODIR)/program
else
	rm -f $(PKGDIR)-core/$(OODIR)/program/gengal.bin
	rm -f $(PKGDIR)-common/$(OODIR)/program/gengal
endif

ifneq "$(ENABLE_REPORTDESIGN)" "y"
	# unneeded. a no-Java arch, so the report-builder can't work anyway.
	# (and we need to remove it here anyway as it otherwise would end up
	# in -base/-core)
	rm -rf $(PKGDIR)-report-builder
	rm -f $(PKGDIR)-core/$(OODIR)/program/librpt*
else
  ifeq "$(PACKAGE_BASE)" "y"
	# move rpt stuff into -report-builder-bin
	rm -rf $(PKGDIR)-report-builder-bin
	mkdir -p $(PKGDIR)-report-builder-bin/$(OODIR)/program
	# FIXME: it seems that --enable/--disable-reportbuiler affects the install
	# location. sigh.
	if [ -e $(PKGDIR)-core/$(OODIR)/program/librptlo.so ]; then \
		i=core; else i=report-builder; fi; \
	mv $(PKGDIR)-$$i/$(OODIR)/program/librpt* \
		$(PKGDIR)-report-builder-bin/$(OODIR)/program
  endif
endif

	find debian/tmp ! -perm -200 | xargs -r chmod u+w

	touch $@

#
# Generate maintainer scripts
maintscripts: $(STAMP_DIR)/maintscripts
$(STAMP_DIR)/maintscripts: $(wildcard debian/shell-lib*.sh) $(wildcard debian/*.preinst.in) $(wildcard debian/*.postinst.in) $(wildcard debian/*.prerm.in) $(wildcard debian/*.postrm.in) debian/control
	dh_testdir

	rm -f debian/*.{pre,post}{inst,rm}

	# generate maintainer scripts from *.in
	for PKG in $(PACKAGES); do \
	  for FILE in postinst postrm preinst prerm triggers; do \
	    MAINTSCRIPT=debian/$$PKG.$$FILE ; \
	    if [ -e $$MAINTSCRIPT.in ]; then \
	      sed -n '1,/^#INCLUDE_SHELL_LIB#$$/p' < $$MAINTSCRIPT.in | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' > $$MAINTSCRIPT; \
	      if egrep -q "(validate_extension|sync_extension)" $$MAINTSCRIPT.in; then \
		 cat debian/shell-lib-extensions.sh >> $$MAINTSCRIPT; \
	      fi; \
	      sed -n '/^#INCLUDE_SHELL_LIB#$$/,$$p' < $$MAINTSCRIPT.in | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' >> $$MAINTSCRIPT; \
	      perl -pi -e "s/\@LANGPACKISOS\@/$(LANGPACKISOS)/" $$MAINTSCRIPT; \
	      perl -pi -e "s,\@OODIR\@,$(OODIR),g" $$MAINTSCRIPT; \
	    fi; \
	  done; \
	done

	touch $@

# Install files generated by setup into package directories
langpacks: $(STAMP_DIR)/langpacks
$(STAMP_DIR)/langpacks: $(STAMP_DIR)/build-indep $(STAMP_DIR)/install-indep $(SOURCE_TREE)/bin/lo-xlate-lang

	# remove empty uno_packages dirs somehow in the langpacks(?)
	for iso in `echo $(LANGPACKISOS) | tr A-Z a-z`; do \
		rm -rf $(PKGDIR)-l10n-$$iso/$(OODIR)/share/uno_packages; \
	done

	# remove ooo dirs somehow in the langpacks(?)
	for iso in `echo $(LANGPACKISOS) | tr A-Z a-z`; do \
		rm -rf $(PKGDIR)-l10n-$$iso/$(OODIR)/share/dict/ooo; \
	done

	# remove extra license files
	for iso in `echo $(LANGPACKISOS) | tr A-Z a-z`; do \
		rm -rf $(PKGDIR)-l10n-$$iso/$(OODIR)/licenses; \
		rm -f $(PKGDIR)-l10n-$$iso/$(OODIR)/share/readme/LICENSE*; \
	done

	# remove extra readme files
	for iso in `echo $(LANGPACKISOS) | tr A-Z a-z`; do \
		rm -rf $(PKGDIR)-l10n-$$iso/$(OODIR)/readmes; \
		rm -f $(PKGDIR)-l10n-$$iso/$(OODIR)/share/readme/README*; \
	done

	# remove empty help directories
	for iso in `echo $(LANGPACKISOS) | tr A-Z a-z`; do \
		rm -rf $(PKGDIR)-l10n-$$iso/$(shell echo $(OODIR) | sed -e s/lib/share/)/help; \
		rm -rf $(PKGDIR)-l10n-$$iso/$(OODIR)/help; \
	done

	# install technical.dic
	for iso in $(LANGPACKISOS); do \
		if [ "$$iso" = "en-US" ]; then pkg=common; \
		elif [ "$$iso" = "ca-valencia" ]; then pkg=l10n-ca; \
		elif [ "$$iso" = "kmr-Latn" ]; then pkg=l10n-kmr; \
		else pkg=l10n-`echo $$iso | tr A-Z a-z`; \
		fi; \
		mkdir -p $(PKGDIR)-$$pkg/$(OODIR)/share/wordbook/$$iso; \
		install -m644 $(SOURCE_TREE)/extras/source/wordbook/technical.dic \
			$(PKGDIR)-$$pkg/$(OODIR)/share/wordbook/$$iso/technical.dic; \
	done

	# FIXME!
#	# replace duplicate files in the langpacks with symlinks
#	TMP=`mktemp -q`; \
#		fdupes --quiet --recurse --sameline --size \
#		debian/libreoffice-common/$(OODIR) \
#		$(foreach d,$(shell echo $(filter-out en-US ca-valencia,$(LANGPACKISOS)) | tr A-Z a-z),debian/libreoffice-l10n-$(d)/$(OODIR)) \
#		> $$TMP && \
#	debian/scripts/cleandupes --base=libreoffice --prefix=debian < $$TMP && rm -f $$TMP

ifeq "$(DEB_VENDOR)" "Debian"
	# install Debian presentation template
	otps=`cd debian/templates; echo *.otp`; \
	for iso in $(LANGPACKISOS); do \
	  [ "$$iso" = "en-US" ] && continue; \
	  pkgiso=`echo $$iso | tr \[:upper:\] \[:lower:\]`; \
	  [ "$$pkgiso" = "ca-valencia" ] && pkgiso=ca; \
	  [ "$$pkgiso" = "kmr-latn" ] && pkgiso=kmr; \
	  mkdir -p $(PKGDIR)-l10n-$$pkgiso/$(OODIR)/share/template/$$iso/presnt; \
	  for otp in $$otps; do \
	    ln -sf ../../en-US/presnt/$$otp \
	    $(PKGDIR)-l10n-$$pkgiso/$(OODIR)/share/template/$$iso/presnt/$$odt; \
	  done; \
	done
endif

ifeq (he,$(findstring he,$(LANGPACKISOS)))
	perl -pi -e 's#<prop oor:name="CTLSequenceChecking"><value>true</value></prop>#<prop oor:name="CTLSequenceChecking"><value>false</value></prop>#' $(PKGDIR)-l10n-he/$(OODIR)/share/registry/ctl_he.xcd
endif

	touch $@

native-jars: $(STAMP_NATIVE_JARS)
$(STAMP_NATIVE_JARS): $(STAMP_DIR)/install-common
ifeq "$(BUILD_JARS_NATIVE)" "y"
	rm -rf debian/tmp/native-jars
	mkdir -p debian/tmp/native-jars/gcj
	cp -a \
	    $(PKGDIR)-common/$(OODIR)/program/classes/*.jar \
		debian/tmp/native-jars/
	cp -a \
	    $(PKGDIR)-core/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes/*.jar \
	        debian/tmp/native-jars/
ifeq "$(PACKAGE_BASE)" "y"
	cp -a \
	    $(PKGDIR)-base/$(OODIR)/program/classes/*.jar \
	        debian/tmp/native-jars/
endif
	: # remove problematic ones
	rm -f debian/tmp/native-jars/ridl.jar
	: # compile the others
	# the Debian i386 buildd, although having much ram still OOMs without
	# this (at unoil.jar).
	# Also the native jar build is MUCH faster with this. But it
	# won't be accepted into the official libgcj-common package so this
	# hack here is needed.
	cp /usr/lib/gcc/aotcompile.py debian/scripts
	cd debian/scripts && \
		patch -p0 < $(CURDIR)/debian/patches/aotcompile-256M-default.diff
	PYTHONPATH="debian/scripts:$(shell echo $(PYTHON_SITE) | sed -e s,debian/python-uno,,)" \
	AOT_MAKEFLAGS=-j$(NUM_CPUS) aot-compile -L /usr/lib/gcj/$(OODIRNAME) \
	    debian/tmp/native-jars debian/tmp/native-jars/gcj
	gcj-dbtool -n debian/tmp/native-jars/tmp.db 64
	find debian/tmp/native-jars/gcj -name '*.db' -print0 \
	    | xargs -r -0 \
		gcj-dbtool -m debian/tmp/native-jars/tmp.db debian/tmp/native-jars/tmp.db || exit 1
	rm -f debian/tmp/native-jars/gcj/*.db
endif
	touch $@

# Install files generated by setup into arch-dependent package directories
install-arch: $(STAMP_DIR)/install-arch
$(STAMP_DIR)/install-arch: $(STAMP_DIR)/install-common $(STAMP_NATIVE_JARS)
	dh_testdir
	dh_testroot
	umask 022

	# move the URE to /usr/lib/ure
	mv debian/ure/$(OODIR)/ure debian/ure/usr/lib
	chmod 644 debian/ure/$(OOUREDIR)/lib/unorc
	# move URE Java stuff to /usr/share/java
	mkdir -p debian/ure/usr/share/java
ifeq "$(ENABLE_JAVA)" "y"
	mv debian/ure/$(OOUREDIR)/share/java/* \
		debian/ure/usr/share/java
	cd debian/ure/$(OOUREDIR)/share/java && \
		for i in $(CURDIR)/debian/ure/usr/share/java/*.jar; do \
			ln -sf `echo $$i | sed -e 's,$(CURDIR)/debian/ure,,'` `basename $$i`; \
		done
	# fix up Class-Path of jurt.jar to be able to find libjpipe.so.
	# See See http://www.openoffice.org/servlets/ReadMsg?list=dev&msgNo=27765
	jh_classpath --classpath="ridl.jar unoloader.jar ../../lib /$(OOUREDIR)/lib/ ../bin/" \
		$(CURDIR)/debian/ure/usr/share/java/jurt.jar
endif
	# and the public libs to uno-libs3
	mkdir -p debian/uno-libs3/$(OOUREDIR)/lib
	for i in debian/ure/$(OOUREDIR)/lib/libuno_*so.3; do \
		mv $$i debian/uno-libs3/$(OOUREDIR)/lib; \
		ln -sf /$(OOUREDIR)/lib/`basename $$i` debian/uno-libs3/usr/lib/`basename $$i`; \
	done
	# we also need libxmlreaderlo.so and libreglo.so (libuno_cppuhelpergcc3.so.3 needs it)
	# and libstorelo.so (libreglo.so needs it)
	for i in libxmlreaderlo.so libreglo.so libstorelo.so; do \
		mv debian/ure/$(OOUREDIR)/lib/$$i \
			debian/uno-libs3/$(OOUREDIR)/lib; \
	done
	cd debian/ure/$(OODIR) && \
		rm ure-link && ln -sf /$(OOUREDIR) ure-link


ifeq "$(BUILD_KDE)" "y"
	# install files for KDEs "create new" ...
	mkdir -p $(PKGDIR)-kde/usr/share/templates/.source
	for i in $(SOURCE_TREE)/extras/source/shellnew/*; do \
		cp $$i $(PKGDIR)-kde/usr/share/templates/.source/`basename $$i`; \
	done
	cat debian/templates/soffice-template.desktop.in \
		| sed -e "s/@APP@/Writer/" \
		| sed -e "s/@EXT@/odt/" \
		| sed -e "s/@TYPE@/text/" \
		> $(PKGDIR)-kde/usr/share/templates/soffice.odt.desktop
	cat debian/templates/soffice-template.desktop.in \
		| sed -e "s/@APP@/Calc/" \
		| sed -e "s/@EXT@/ods/" \
		| sed -e "s/@TYPE@/spreadsheet/" \
		> $(PKGDIR)-kde/usr/share/templates/soffice.ods.desktop
	cat debian/templates/soffice-template.desktop.in \
		| sed -e "s/@APP@/Impress/" \
		| sed -e "s/@EXT@/odp/" \
		| sed -e "s/@TYPE@/presentation/" \
		> $(PKGDIR)-kde/usr/share/templates/soffice.odp.desktop
	cat debian/templates/soffice-template.desktop.in \
		| sed -e "s/@APP@/Draw/" \
		| sed -e "s/@EXT@/odg/" \
		| sed -e "s/@TYPE@/drawing/" \
		> $(PKGDIR)-kde/usr/share/templates/soffice.odg.desktop
endif

	# split out gtk stuff
	rm -rf $(PKGDIR)-gtk
	mkdir -p -m755 $(PKGDIR)-gtk/$(OODIR)/program
ifeq "$(BUILD_GTK3)" "y"
	rm -rf $(PKGDIR)-gtk3
	mkdir -p -m755 $(PKGDIR)-gtk3/$(OODIR)/program
	mv $(PKGDIR)-gnome/$(OODIR)/program/libvclplug_gtk3lo.so $(PKGDIR)-gtk3/$(OODIR)/program/
endif
	mv $(PKGDIR)-gnome/$(OODIR)/program/* $(PKGDIR)-gtk/$(OODIR)/program/
ifeq "$(BUILD_GTK)" "y"
	mkdir -p -m755 $(PKGDIR)-gtk/$(OODIR)/share
	mv $(PKGDIR)-gnome/$(OODIR)/share/xdg $(PKGDIR)-gtk/$(OODIR)/share
  ifeq "$(ENABLE_GIO)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/libucpgio1lo.so \
		$(PKGDIR)-gnome/$(OODIR)/program/
  endif
  ifeq "$(ENABLE_GVFS)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/libucpgvfs1lo.so \
		$(PKGDIR)-gnome/$(OODIR)/program/
  endif
  ifeq "$(ENABLE_GCONF)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/libgconfbe1lo.so \
		$(PKGDIR)-gnome/$(OODIR)/program
  endif
endif

ifeq "$(ENABLE_EVO2)" "y"
	mkdir -p -m755 $(PKGDIR)-evolution/$(OODIR)/program
	mv $(PKGDIR)-gtk/$(OODIR)/program/libevoab*.so $(PKGDIR)-evolution/$(OODIR)/program
	mv $(PKGDIR)-gnome/$(OODIR)/share/registry/evoab.xcd \
		$(PKGDIR)-evolution/$(OODIR)/share/registry
	# FIXME: When the rdb is correctly generated, move here, too.
endif

ifeq "$(PACKAGE_NSPLUGIN)" "y"
	mkdir -p -m755 debian/browser-plugin-libreoffice/$(OODIR)/program
	for f in libnpsoplugin.so nsplugin; do \
		mv $(PKGDIR)-core/$(OODIR)/program/$$f debian/browser-plugin-libreoffice/$(OODIR)/program; \
	done
	cd debian/browser-plugin-libreoffice && \
		mkdir -p usr/lib/mozilla/plugins && \
			ln -sf /$(OODIR)/program/libnpsoplugin.so \
			   usr/lib/mozilla/plugins/libnpsoplugin.so
endif

ifeq "$(PACKAGE_BASE)" "y"
	mkdir -p $(PKGDIR)-base-core/$(OODIR)/program
	mv $(PKGDIR)-base/$(OODIR)/program/libdbalo.so \
		$(PKGDIR)-base-core/$(OODIR)/program
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifneq (,$(filter hsqldb, $(SYSTEM_STUFF)))
	# link to system hsqldb
	mkdir -p $(PKGDIR)-base/$(OODIR)/program/classes
	ln -sf $(HSQLDB_JAR) \
	        $(PKGDIR)-base/$(OODIR)/program/classes/hsqldb.jar
  endif
endif

ifeq "$(ENABLE_JAVA)" "y"
	rm -rf $(PKGDIR)-officebean
	mkdir -p -m755 $(PKGDIR)-officebean/$(OODIR)/program/classes
	mkdir -p -m755 $(PKGDIR)-officebean/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes
	mv $(PKGDIR)-core/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes/officebean.jar \
		$(PKGDIR)-officebean/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes
	ln -s $(shell echo /$(OODIR) | sed -e s/lib/share/)/program/classes/officebean.jar \
		 $(PKGDIR)-officebean/$(OODIR)/program/classes/officebean.jar
	mv $(PKGDIR)-core/$(OODIR)/program/libofficebean.so \
		$(PKGDIR)-officebean/$(OODIR)/program
endif

	mkdir -p -m755 $(PKGDIR)-base/usr/share/applications \
	               $(PKGDIR)-core/usr/share/applications

	sed -i -e 's/Office;/Office;Graphics;/' $(PKGDIR)-draw/$(OODIR)/share/xdg/draw.desktop
	# invalid, according to lintian. make it shut up.
	for i in writer calc impress draw math base; do \
		perl -pi -e 's/Application;//; s/X-Red-Hat-Base;//; s/X-SuSE-Core-Office;//; s/X-MandrivaLinux-.*;//;' $(PKGDIR)-$$i/$(OODIR)/share/xdg/$$i.desktop; \
	done
	perl -pi -e 's/Application;//' $(PKGDIR)-gtk/$(OODIR)/share/xdg/qstart.desktop

ifeq "$(ENABLE_PYTHON)" "y"
	# PyUNO packaging
	install -d $(PYTHON_SITE)
	# prepend stuff so that it works when the module is not in LOs
	# directories but in $(PYTHON_SITE). Can't be a patch (anymore)
	# as otherwise the python-based unittests fail miserably.
	echo "import sys, os" > $(PYTHON_SITE)/uno.py
	echo "sys.path.append('/$(OODIR)/program')" >> $(PYTHON_SITE)/uno.py
	echo "os.putenv('URE_BOOTSTRAP', 'vnd.sun.star.pathname:/$(OODIR)/program/fundamentalrc')" >> $(PYTHON_SITE)/uno.py
	cat debian/python3-uno/$(OODIR)/program/uno.py >> $(PYTHON_SITE)/uno.py
	rm -f debian/python3-uno/$(OODIR)/program/uno.py
	mv debian/python3-uno/$(OODIR)/program/unohelper.py $(PYTHON_SITE)
	touch debian/python3-uno/$(OODIR)/program/pythonloader.unorc
	chmod u+w debian/python3-uno/$(OODIR)/program/pythonloader.unorc
	( echo 'PYTHONHOME=file:///usr/lib/python$(PYMAJOR).$(PYMINOR)' ;\
	  echo 'PYTHONPATH=$$PYTHONHOME $$PYTHONHOME/site-packages $$PYTHONHOME/lib-dynload $$PYTHONHOME/lib-tk $$ORIGIN' \
	) >> debian/python3-uno/$(OODIR)/program/pythonloader.unorc
	chmod u-w debian/python3-uno/$(OODIR)/program/pythonloader.unorc
  ifneq "$(WHEEZY_BACKPORT)" "y"
    ifeq "$(ENABLE_PYTHON2)" "y"
	install -d $(PYTHON2_SITE)
	cp $(PYTHON_SITE)/uno.py \
		$(PYTHON2_SITE)
	cp $(PYTHON_SITE)/unohelper.py \
		$(PYTHON2_SITE)
	mkdir -p debian/python-uno/$(OODIR)/program/services
	mkdir -p debian/python-uno/$(OODIR)/share/registry
	mkdir -p debian/python-uno/$(OODIR)/share/Scripts
	cat debian/python3-uno/$(OODIR)/program/pythonloader.unorc \
		| sed -e "s/$(PYMAJOR).$(PYMINOR)/$(PY2MAJOR).$(PY2MINOR)/" \
		> debian/python-uno/$(OODIR)/program/pythonloader.unorc
	for i in pyuno.so libpyuno.so libpythonloaderlo.so; do \
		install -m644 debian/pyuno-for-$(PY2MAJOR).$(PY2MINOR)/$$i \
			debian/python-uno/$(OODIR)/program/$$i; \
	done
	cp debian/python3-uno/$(OODIR)/program/pythonloader.py \
		debian/python-uno/$(OODIR)/program
	cp debian/python3-uno/$(OODIR)/program/services/pyuno.rdb \
		debian/python-uno/$(OODIR)/program/services
	cp debian/python3-uno/$(OODIR)/share/registry/pyuno.xcd \
		debian/python-uno/$(OODIR)/share/registry
	cp -r debian/python3-uno/$(OODIR)/share/Scripts/python \
		debian/python-uno/$(OODIR)/share/Scripts
    endif
  endif
  ifeq "$(ENABLE_SCRIPT_PROVIDER_PYTHON)" "y"
	rm -f debian/libreoffice-script-provider-python/$(OODIR)/share/extensions/script-provider-for-python/registration/LICENSE
  endif

	mkdir -p debian/python3-uno/usr/share/doc/python3-uno
	cp -r $(SOURCE_TREE)/pyuno/demo \
	  debian/python3-uno/usr/share/doc/python3-uno; \
	for i in $(SOURCE_TREE)/pyuno/doc/*; do \
		cp $$i debian/python3-uno/usr/share/doc/python3-uno; \
	done
	cd debian/python3-uno/usr/share/doc/python3-uno && \
		find . -type d -name "CVS" | xargs -r rm -rf
  ifneq "$(WHEEZY_BACKPORT)" "y"
    ifeq "$(ENABLE_PYTHON2)" "y"
	mkdir -p debian/python-uno/usr/share/doc/python-uno
	cp -r $(SOURCE_TREE)/pyuno/demo \
	  debian/python-uno/usr/share/doc/python-uno; \
	for i in $(SOURCE_TREE)/pyuno/doc/*; do \
		cp $$i debian/python-uno/usr/share/doc/python-uno; \
	done
	cd debian/python-uno/usr/share/doc/python-uno && \
		find . -type d -name "CVS" | xargs -r rm -rf
    endif
  endif
endif

ifeq "$(WHEEZY_BACKPORT)" "y"
	# OMG!!
	rm -rf debian/python-uno
	mv debian/python3-uno debian/python-uno
endif

	# should be empty now, remove if there
	rm -rf $(PKGDIR)-core/$(OODIR)/ure

ifeq "$(PACKAGE_SDK)" "y"
  ifeq "$(ENABLE_JAVA)" "y"
	# compat/safety symlink for SDK Java stuff moved to /usr/share
	rm -f $(PKGDIR)-dev/$(OOSDKDIR)/classes
	mkdir -p $(PKGDIR)-dev/$(OOSDKDIR)/classes/com/sun/star/lib/loader
	cd $(PKGDIR)-dev/$(OOSDKDIR)/classes/com/sun/star/lib/loader && \
		for i in $(CURDIR)/$(PKGDIR)-dev/$(shell echo $(OOSDKDIR) | sed -e s/lib/share/)/classes/com/sun/star/lib/loader/*.class; do \
			ln -s `echo $$i | sed -e 's,$(CURDIR)/$(PKGDIR)-dev,,'` `basename $$i`; \
		done
    ifeq "$(PACKAGE_UNOWINREG_DLL)" "y"
	mkdir -p $(PKGDIR)-dev/$(OOSDKDIR)/classes/win
	chmod 644 $(PKGDIR)-dev/$(shell echo $(OOSDKDIR) | sed -e s/lib/share/)/classes/win/unowinreg.dll
	ln -s /$(shell echo $(OOSDKDIR) | sed -e s/lib/share/)/classes/win/unowinreg.dll \
		$(PKGDIR)-dev/$(OOSDKDIR)/classes/win/unowinreg.dll
    else
	rm -rf $(PKGDIR)-dev/$(shell echo $(OOSDKDIR) | sed -e s/lib/share/)/classes/win 
    endif
  endif
	chmod 644 $(PKGDIR)-dev/$(OOSDKDIR)/configure.pl
	chmod 755 $(PKGDIR)-dev/$(OOSDKDIR)/setsdkenv_unix
	# create wrapper scripts
	cd $(PKGDIR)-dev/$(OOSDKDIR)/bin && \
	for i in *; do \
		mv $$i $$i.bin && \
		( \
		  echo "#!/bin/sh"; \
		  echo "# wrapper script for OOos SDK programs"; \
		  echo ""; \
		  echo 'LD_LIBRARY_PATH=/$(OOUREDIR)/lib /$(OOSDKDIR)/bin/`basename $$0`.bin "$$@"'; \
		) > $$i; \
		chmod 755 $$i; \
	done
        # remove symlink, it should be in -dev-doc
	cd $(PKGDIR)-dev/$(OOSDKDIR) && \
		rm docs

	# fix permissions
	find $(PKGDIR)-dev/usr/share/idl/$(OODIRNAME) -type f -exec chmod 644 {} \;

	rm -f $(PKGDIR)-dev/usr/share/doc/libreoffice/sdk/readme/LICENSE.gz
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
	rm -rf $(PKGDIR)-gcj/usr/lib/gcj
	mkdir -p $(PKGDIR)-gcj/usr/lib/gcj/$(OODIRNAME)
	cp -p debian/tmp/native-jars/gcj/* $(PKGDIR)-gcj/usr/lib/gcj/$(OODIRNAME)
	mkdir -p $(PKGDIR)-gcj/usr/share/gcj/classmap.d
	cp -p debian/tmp/native-jars/tmp.db \
		$(PKGDIR)-gcj/usr/share/gcj/classmap.d/libreoffice.db
  endif
endif

ifeq "$(ENABLE_JAVA)" "y"
	# hrmpf, again something like that, we really need to find the root cause for that
	ln -s libjava_uno.so \
		debian/ure/$(OOUREDIR)/lib/libjava_uno
endif

	# remove empty resource directories
	for i in draw base writer impress calc math; do \
		rm -rf $(PKGDIR)-$$i/$(OODIR)/program/resource; \
	done

ifeq "$(ENABLE_MINIMIZER)" "y"
	rm -f $(PKGDIR)-presentation-minimizer/$(OODIR)/share/extensions/presentation-minimizer/registration/LICENSE
endif

ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	rm -f usr/lib/libreoffice/share/extensions/presenter-screen/registration/LICENSE
endif

ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	rm -f $(PKGDIR)-mysql-connector/$(OODIR)/share/extensions/mysql-connector-ooo/registration/LICENSE
endif

ifeq "$(PACKAGE_SDK)" "y"
	# move ui-previewer into -dev
	mkdir -p $(PKGDIR)-dev/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/ui-previewer \
		$(PKGDIR)-dev/$(OODIR)/program
else
	rm -f $(PKGDIR)-core/$(OODIR)/program/ui-previewer
endif

# see https://bugs.freedesktop.org/show_bug.cgi?id=67349
# writer doesn't start without it.
ifeq (,$(filter lpsolve, $(SYSTEM_STUFF)))
	mv $(PKGDIR)-calc/$(OODIR)/program/liblpsolve55.so \
		$(PKGDIR)-core/$(OODIR)/program
endif

ifeq "$(USE_GSTREAMER)" "y"
	mkdir -p $(PKGDIR)-avmedia-backend-gstreamer/$(OODIR)/program
  ifeq "$(GSTREAMER_VERSION)" "1.0"
	mv $(PKGDIR)-core/$(OODIR)/program/libavmediagst.so \
		$(PKGDIR)-avmedia-backend-gstreamer/$(OODIR)/program
  else
	mv $(PKGDIR)-core/$(OODIR)/program/libavmediagst_0_10.so \
		$(PKGDIR)-avmedia-backend-gstreamer/$(OODIR)/program
  endif
endif
ifeq "$(USE_VLC)" "y"
	mkdir -p $(PKGDIR)-avmedia-backend-vlc/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/libavmediavlc.so \
		$(PKGDIR)-avmedia-backend-vlc/$(OODIR)/program
endif

ifeq "$(ENABLE_JAVA)" "y"
	mkdir -p $(PKGDIR)-sdbc-hsqldb/$(OODIR)/program
	mkdir -p $(PKGDIR)-sdbc-hsqldb/usr/lib/libreoffice/program/classes
	mkdir -p $(PKGDIR)-sdbc-hsqldb/usr/share/libreoffice/program/classes
	mv $(PKGDIR)-base/$(OODIR)/program/libhsqldb.so \
		$(PKGDIR)-sdbc-hsqldb/$(OODIR)/program
  ifneq (,$(filter hsqldb, $(SYSTEM_STUFF)))
	mv $(PKGDIR)-base/usr/lib/libreoffice/program/classes/hsqldb.jar \
		$(PKGDIR)-sdbc-hsqldb/usr/lib/libreoffice/program/classes
  endif
	for i in lib share; do \
		mv $(PKGDIR)-base/usr/$$i/libreoffice/program/classes/sdbc_hsqldb.jar \
			$(PKGDIR)-sdbc-hsqldb/usr/$$i/libreoffice/program/classes; \
	done
endif
ifeq "$(ENABLE_FIREBIRD)" "y"
	mkdir -p $(PKGDIR)-sdbc-firebird/$(OODIR)/program
	mv $(PKGDIR)-base/$(OODIR)/program/libfirebird_sdbclo.so \
		$(PKGDIR)-sdbc-firebird/$(OODIR)/program
endif
	mkdir -p $(PKGDIR)-base-drivers/$(OODIR)/program
	for i in `find $(PKGDIR)-base/$(OODIR)/program/ -name "*.so" \
		-a \! -name "libdbulo*" -a \! -name "libdbaxml*" -a \! -name "libdbp*" -a \! -name "libabplo.so"`; do \
		mv $$i \
			$(PKGDIR)-base-drivers/$(OODIR)/program; \
	done

ifeq "$(ENABLE_JAVA)" "y"
	# somehow --has-package-version doesn't overwrite version and without <version>...</version>
	# we get a NullPointerException when calling mh_installjar
	for i in juh jurt ridl; do \
		sed -e s/@version@/$(shell echo $(DEB_VERSION_UPSTREAM) | cut -d~ -f1)/ \
		< debian/pom.$$i.xml.in > debian/pom.$$i.xml; \
	done
	mh_installpoms -pure
	for i in juh jurt ridl; do \
		mh_installjar -pure -l debian/pom.$$i.xml instdir/ure/share/java/$$i.jar; \
	done
endif

	for i in $(ARCH_DEP_PACKAGES); do \
		if [ -e debian/$$i.bug-script.in ]; then \
			cat debian/$$i.bug-script.in \
				| sed -e "s/@PLATFORMID@/$(PLATFORMID)/" \
				| sed -e "s/@OOVER@/$(OOVER)/" \
				> debian/$$i.bug-script; \
		fi ;\
	done
	# generate .links files from *.in	
	for PKG in $(ARCH_DEP_PACKAGES); do \
	  LINKS=debian/$$PKG.links ; \
	  if [ -e $$LINKS.in ]; then \
	    sed -e "s#\@OODIR\@#$(OODIR)#g" \
		< $$LINKS.in > $$LINKS ; \
	  fi; \
	done
	for PKG in $(ARCH_DEP_PACKAGES); do \
		case $$PKG in \
		python-uno|uno-libs*|ure*) \
			;; \
		*) \
			cat debian/changelog \
			| sed -e '/^openoffice/,$$d' \
			> debian/$$PKG.changelog; \
			;; \
		esac; \
	done

	touch $@

# Install files generated by setup into arch-independent package directories
install-indep: $(STAMP_DIR)/install-indep
#$(STAMP_DIR)/install-indep: debian/libreoffice.install 
#$(STAMP_DIR)/install-indep: debian/libreoffice-mimelnk.install 
#$(STAMP_DIR)/install-indep: debian/libreoffice.dirs
$(STAMP_DIR)/install-indep: $(STAMP_DIR)/build-indep $(STAMP_DIR)/install-common
	dh_testdir
	dh_testroot

ifneq "$(shell echo $(USE_GSTREAMER)$(USE_VLC) | grep -q y && echo 0)" "0"
	# sound doesn't work anyway, remove the .wav files to save space
	rm -rf $(PKGDIR)-common/$(OODIR)/share/gallery/sounds
	rm -f $(PKGDIR)-common/$(OODIR)/share/gallery/sg9.*
endif

	rm -f $(PKGDIR)-common/$(OODIR)/program/oo_product.bmp

	# install openoffice-xlate-lang
	install -d -m755 $(PKGDIR)-common/usr/share/$(OODIRNAME)/bin
	install -m755 $(SOURCE_TREE)/bin/lo-xlate-lang \
		$(PKGDIR)-common/usr/share/$(OODIRNAME)/bin

ifeq "$(ENABLE_HELP)" "n"
	# when we don't build helpcontent2 here we are missing helpxsl.zip so
	# this file doesn't get installed either. Do it manually..
	mkdir -p -m755 $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help && \
	cp $(SOURCE_TREE)/xmlhelp/util/main_transform.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	cp $(SOURCE_TREE)/xmlhelp/util/idxcaption.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	cp $(SOURCE_TREE)/xmlhelp/util/idxcontent.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
endif

ifeq "$(PACKAGE_SDK)" "y"
	rm -f $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev-doc/LICENSE
	perl -pi -e 's,license.html,http://www.gnu.org/licenses/lgpl.html,' \
		$(PKGDIR)-dev-doc/$(OOSDKDIR)/index.html
	find $(PKGDIR)-dev-doc/$(OODIR)/sdk/examples -type f -exec chmod 644 {} \;
endif

ifeq "$(ENABLE_JAVA)" "y"
	# move common Java stuff to -java-common
	rm -rf $(PKGDIR)-java-common
	mkdir -p $(PKGDIR)-java-common/$(OODIR)/program/classes
	mkdir -p $(PKGDIR)-java-common/$(OODIR)/share/Scripts
	mkdir -p $(PKGDIR)-java-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes
	mv $(PKGDIR)-common/$(OODIR)/share/Scripts/java \
		$(PKGDIR)-java-common/$(OODIR)/share/Scripts
	mv $(PKGDIR)-common/$(OODIR)/program/classes/* \
		$(PKGDIR)-java-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes
	cd $(PKGDIR)-java-common/$(OODIR)/program/classes && \
		for i in $(CURDIR)/$(PKGDIR)-java-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/program/classes/*; do \
			case "`basename $$i`" in aportisdoc.jar|pexcel.jar|pocketword.jar) continue ;; \
			*) ln -s `echo $$i | sed -e 's,$(CURDIR)/$(PKGDIR)-java-common,,'` `basename $$i` ;; esac; \
	done

ifeq "$(BUILD_TEST_PACKAGE)" "y"
  ifeq "$(ENABLE_JUNIT4)" "y"
	rm -rf $(PKGDIR)-subsequentcheckbase
	mkdir -p $(PKGDIR)-subsequentcheckbase/$(OODIR)/program/classes/
	for jar in OOoRunner.jar OOoRunnerLight.jar test.jar test-tools.jar; do \
		cp workdir/Jar/$$jar $(PKGDIR)-subsequentcheckbase/$(OODIR)/program/classes/; \
	done
	for jar in ConnectivityTools.jar; do \
		cp workdir/Jar/$$jar $(PKGDIR)-subsequentcheckbase/$(OODIR)/program/classes/; \
	done
  endif
endif
endif

	# fix permissions
	for i in editpic poll savepic show webcast; do \
		chmod 755 $(PKGDIR)-common/$(OODIR)/share/config/webcast/$$i.pl; \
	done
	chmod 644 $(PKGDIR)-common/$(OODIR)/LICENSE.fodt
	chmod 644 $(PKGDIR)-common/$(OODIR)/CREDITS.fodt
	# FIXME. Do we really need this (ALV2 mandating it) or can this go?
	chmod 644 $(PKGDIR)-common/$(OODIR)/NOTICE
	rm -rf $(PKGDIR)-common/$(OODIR)/LICENSE

	# move uno_packages/cache to /var and create symlink for for
	# documentation referencing it...
	rm -rf $(PKGDIR)-common/$(OODIR)/share/uno_packages/cache
	mkdir -p $(PKGDIR)-common/var/spool/$(OODIRNAME)/uno_packages/cache
	ln -s /var/spool/$(OODIRNAME)/uno_packages/cache \
		$(PKGDIR)-common/$(OODIR)/share/uno_packages/cache
	perl -pi -e \
	      's,\$$UNO_SHARED_PACKAGES/cache,file:///var/spool/$(OODIRNAME)/uno_packages/cache,g' \
		$(PKGDIR)-common/$(OODIR)/program/unorc
	# FIXME: What is this? unorc per default only mentiones
	# share/uno_packages/cache...
	rm -rf $(PKGDIR)-common/$(OODIR)/presets/uno_packages

	# set PYTHONPATH in unopkg
	perl -pi -e 's,unset XENVIRONMENT,unset XENVIRONMENT\n\nexport PYTHONPATH=\"/$(OODIR)/program\"\n\n,' \
		$(PKGDIR)-common/$(OODIR)/program/unopkg

ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	mkdir -p debian/fonts-opensymbol/usr/share/fonts/truetype/openoffice
	mv $(PKGDIR)-common/$(OODIR)/share/fonts/truetype/opens___.ttf \
		debian/fonts-opensymbol/usr/share/fonts/truetype/openoffice
	rm -rf $(PKGDIR)-common/$(OODIR)/share/fonts/truetype
else
	rm -f $(PKGDIR)-common/$(OODIR)/share/fonts/truetype/opens___.ttf
endif

	# convert icons to xpm; we need them for the Debian menu policy...
	cd $(PKGDIR)-common/usr/share/icons/hicolor/32x32/apps && \
	  for x in *.png; do convert $$x `basename $$x .png`.xpm; done

	# remove extra license files
	rm -rf $(PKGDIR)-common/$(OODIR)/licenses
	rm -f $(PKGDIR)-common/$(OODIR)/share/readme/LICENSE*
	rm -f $(PKGDIR)-common/$(OODIR)/THIRDPARTYLICENSEREADME.html
	rm -f $(PKGDIR)-common/$(OODIR)/LICENSE.html

	# remove extra readme files
	rm -rf $(PKGDIR)-common/$(OODIR)/readmes
	rm -f $(PKGDIR)-common/$(OODIR)/share/readme/README*
	rm -f $(PKGDIR)-common/$(OODIR)/README.html
	rm -f $(PKGDIR)-common/$(OODIR)/README

	# URE got moved to /usr/lib, so this is obsolete
	for i in ure/lib ure; do \
		if [ -e $(PKGDIR)-common/$(OODIR)/$$i ]; then \
			rmdir $(PKGDIR)-common/$(OODIR)/$$i; \
		fi; \
	done

	# move psprint.conf into /etc
	mkdir -p $(PKGDIR)-common/etc/$(OODIRNAME)
	mv $(PKGDIR)-common/$(OODIR)/share/psprint/psprint.conf \
		$(PKGDIR)-common/etc/$(OODIRNAME)
	ln -s /etc/$(OODIRNAME)/psprint.conf \
		$(PKGDIR)-common/$(OODIR)/share/psprint/psprint.conf

	# prepare a fake sofficerc in the place where OOo expects it
	# which does nothing except reference the "normal" one
	# which we put into /etc
	mv $(PKGDIR)-common/$(OODIR)/program/sofficerc \
		$(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc
	( \
	  echo "# *DO NOT* CHANGE THIS FILE. IT ONLY TAKES THE SETTINGS FROM"; \
	  echo "# /etc/$(OODIRNAME)/sofficerc. CHANGE THAT FILE IF YOU"; \
	  echo "# REALLY WANT TO CHANGE SOMETHING."; \
	  echo "FHS_CONFIG_FILE=file:///etc/$(OODIRNAME)/sofficerc"; \
	  echo "" >> $(PKGDIR)-common/$(OODIR)/program/sofficerc; \
	) > $(PKGDIR)-common/$(OODIR)/program/sofficerc
	cat $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc \
		| perl -p -e 's/(.*)=(.*)/$$1=\$${\$$FHS_CONFIG_FILE:Bootstrap:$$1}/' \
		>> $(PKGDIR)-common/$(OODIR)/program/sofficerc
	# except for URE_BOOTSTRAP...
	TMP=`mktemp -q`; \
		grep -v URE_BOOTSTRAP $(PKGDIR)-common/$(OODIR)/program/sofficerc > $$TMP && mv $$TMP $(PKGDIR)-common/$(OODIR)/program/sofficerc && \
		grep URE_BOOTSTRAP $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc >> $(PKGDIR)-common/$(OODIR)/program/sofficerc && \
		grep -v URE_BOOTSTRAP $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc > $$TMP && mv $$TMP $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc

	install -m 644 debian/soffice.sh \
	  $(PKGDIR)-common/etc/$(OODIRNAME)/soffice.sh

ifeq "$(ENABLE_HELP)" "n"
	# the helpimgs are not included when we don't build with help here.
	# Add them now because libreoffice-help-* packaged in contrib or so
	# will need them
	set -e; \
	for i in $(IMAGES); do \
		s=_$$i.zip; \
		case "$$i" in default) s=.zip; esac; \
		z=images$$s; \
		echo "adding helpimgs to $$z..."; \
		rm -rf $$z; mkdir $$z; \
		cd $$z; \
		unzip -q $(CURDIR)/$(PKGDIR)-common/$(OODIR)/share/config/$$z && \
		cp -r $(CURDIR)/$(SOURCE_TREE)/default_images/res/helpimg res && \
		chmod +w $(CURDIR)/$(PKGDIR)-common/$(OODIR)/share/config/$$z && \
		zip -q -r $(CURDIR)/$(PKGDIR)-common/$(OODIR)/share/config/$$z *; \
		cd ..; \
		rm -rf $$z; \
	done
endif
	set -e; \
	mkdir -p $(PKGDIR)-style-$(DEFAULT_IMAGE)/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config; \
	mv $(PKGDIR)-common/$(OODIR)/share/config/images.zip \
                $(PKGDIR)-style-$(DEFAULT_IMAGE)/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config; \
	mkdir -p $(PKGDIR)-style-$(DEFAULT_IMAGE)/$(OODIR)/share/config; \
	ln -s /$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config/images.zip \
		$(PKGDIR)-style-$(DEFAULT_IMAGE)/$(OODIR)/share/config/images.zip; \
	for i in $(filter-out default,$(IMAGES)); do \
		z=images_$$i.zip; p=$$i; \
		mkdir -p $(PKGDIR)-style-$$p/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config; \
		mv $(PKGDIR)-common/$(OODIR)/share/config/$$z \
			$(PKGDIR)-style-$$p/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config/; \
		mkdir -p $(PKGDIR)-style-$$p/$(OODIR)/share/config; \
		ln -s /$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config/$$z \
			$(PKGDIR)-style-$$p/$(OODIR)/share/config/$$z; \
	done

	rm -rf debian/openoffice.org-dtd-officedocument1.0
	mkdir -p debian/openoffice.org-dtd-officedocument1.0/$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)/share/dtd
	mv $(PKGDIR)-common/$(OODIR)/share/dtd/officedocument \
		debian/openoffice.org-dtd-officedocument1.0/$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)/share/dtd
	cat debian/catalog.xml.in \
		| sed -e "s,\@OODIR\@,$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)," \
		> debian/openoffice.org-dtd-officedocument1.0/$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)/share/dtd/officedocument/1_0/catalog.xml
	cat debian/openoffice.org-dtd-officedocument1.0.xmlcatalogs.in \
		| sed -e "s,\@OODIR\@,$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)," \
		> debian/openoffice.org-dtd-officedocument1.0.xmlcatalogs
	# symlink, as it's in a openoffice.org-* package
	cd debian/openoffice.org-dtd-officedocument1.0 && \
		mkdir -p $(OODIR)/share/dtd && \
		cd $(OODIR)/share/dtd && ln -s /$(shell echo $(OODIR) | sed -e s/libreoffice/openoffice/)/share/dtd/officedocument

ifeq "$(DEB_VENDOR)" "Debian"
	# install Debian presentation template
	mkdir -p $(PKGDIR)-common/$(OODIR)/share/template/en-US/presnt
	install -m644 debian/templates/*.otp $(PKGDIR)-common/$(OODIR)/share/template/en-US/presnt/
endif

ifeq "$(PACKAGE_SDK)" "y"
	# add symlinks for docs and examples
	cd $(PKGDIR)-dev-doc/$(OOSDKDIR) && \
		rm -rf docs && \
		ln -sf /usr/share/doc/libreoffice-dev/docs docs
	mkdir -p $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev
	mkdir -p $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev-doc
	cd $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev-doc && \
		ln -s /usr/share/doc/libreoffice-dev/docs docs
	cd $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev-doc && \
		ln -s /$(OOSDKDIR)/examples examples
	cd $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev && \
		ln -s /$(OOSDKDIR)/examples examples
	# and the index
	cd $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev && \
		ln -s /$(OOSDKDIR)/index.html index.html
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(ENABLE_SCRIPT_PROVIDER_BSH)" "y"
	mkdir -p $(PKGDIR)-script-provider-bsh/$(OODIR)/share/Scripts
	mv $(PKGDIR)-common/$(OODIR)/share/Scripts/beanshell \
		$(PKGDIR)-script-provider-bsh/$(OODIR)/share/Scripts
  endif

  ifeq "$(ENABLE_SCRIPT_PROVIDER_JS)" "y"
	mkdir -p $(PKGDIR)-script-provider-js/$(OODIR)/share/Scripts
	mv $(PKGDIR)-common/$(OODIR)/share/Scripts/javascript \
		$(PKGDIR)-script-provider-js/$(OODIR)/share/Scripts
  endif
endif

ifeq "$(ENABLE_MEDIAWIKI)" "y"
	rm -f $(PKGDIR)-wiki-publisher/$(OODIR)/share/extensions/wiki-publisher/registration/LICENSE
	rm -f $(PKGDIR)-wiki-publisher/$(OODIR)/share/extensions/wiki-publisher/license/THIRDPARTYLICENSEREADME.html
endif

	# unopkg creates stuff in there.
	mkdir -p $(PKGDIR)-common/$(OODIR)/share/prereg
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/usr/var/)/share/prereg/bundled
	ln -s /$(shell echo $(OODIR) | sed -e s/usr/var/)/share/prereg/bundled \
		$(PKGDIR)-common/$(OODIR)/share/prereg/bundled

	for i in $(ARCH_INDEP_PACKAGES); do \
		if [ -e debian/$$i.bug-script.in ]; then \
			cat debian/$$i.bug-script.in \
				| sed -e "s/@PLATFORMID@/$(PLATFORMID)/" \
				> debian/$$i.bug-script; \
		fi ;\
	done
	# generate .links files from *.in	
	for PKG in $(ARCH_INDEP_PACKAGES); do \
	  LINKS=debian/$$PKG.links ; \
	  if [ -e $$LINKS.in ]; then \
	    sed -e "s#\@OODIR\@#$(OODIR)#g" \
		< $$LINKS.in > $$LINKS ; \
	  fi; \
	done
	for PKG in $(ARCH_INDEP_PACKAGES); do \
		case $$PKG in \
		openoffice.org-dtd-officedocument1.0) \
			;; \
		*) \
			cat debian/changelog \
			| sed -e '/^openoffice/,$$d' \
			> debian/$$PKG.changelog; \
			;; \
		esac; \
	done

	# install extension shell lib for use by extensions not from here
	install -D -m644 debian/shell-lib-extensions.sh \
		$(PKGDIR)-common/usr/share/$(OODIRNAME)/shell-lib-extensions.sh

ifneq "$(ENABLE_HELP)" "n"
	# those are needed in /usr/share, too
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)
	mv $(PKGDIR)-common/$(OODIR)/help \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)
endif
	# help is in /usr/share
	sed -i 's,$$(instpath)/help,/$(shell echo $(OODIR) | sed -e s/lib/share/)/help,' \
		$(PKGDIR)-common/$(OODIR)/share/registry/main.xcd

	# compat dirs, the split icons thing need it
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/program
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/program
	# three-layer symlinks also for /usr/share
	ln -s /$(OOUREDIR) \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/ure-link

	# enable session handling and recovery
	perl -pi -e 's,<prop oor:name="DocumentStoreUIEnabled" oor:type="xs:boolean"><value>false</value></prop>,<prop oor:name="DocumentStoreUIEnabled" oor:type="xs:boolean"><value>true</value></prop>,' $(PKGDIR)-common/$(OODIR)/share/registry/main.xcd

	# examples. move where they belong
	mkdir -p $(PKGDIR)-common/usr/share/doc/libreoffice-common/examples
	for i in oo-ldap.xcd.sample oo-ad-ldap.xcd.sample; do \
		mv $(PKGDIR)-common/$(OODIR)/share/registry/$$i \
			$(PKGDIR)-common/usr/share/doc/libreoffice-common/examples; \
		ln -s /usr/share/doc/libreoffice-common/examples/$$i $(PKGDIR)-common/$(OODIR)/share/registry/$$i; \
	done

	# install font config. Doesn't get installed with
	# --without-fonts.
	# FIXME: Shouldn't this be in /etc/fonts/conf.d with a symlink here?
	install -m644 -D $(SOURCE_TREE)/external/more_fonts/fonts/fc_local.conf \
		$(PKGDIR)-common/$(OODIR)/share/fonts/truetype/fc_local.conf

	# register technical.dic
	perl -pi -e 's/standard.dic;/standard.dic;technical.dic;/' $(PKGDIR)-common/$(OODIR)/share/registry/main.xcd

#ifeq "$(PACKAGE_SDK)" "y"
#	# install gengal stuff into -dev
#	mkdir -p $(PKGDIR)-dev/$(OODIR)/program
#	install -m644 $(SOURCE_TREE)/svx/$(shell .  $(SOURCE_TREE)/bin/get_config_variables OUTPATH PROEXT; echo $$OUTPATH$$PROEXT)/bin/gengalrc \
#		$(PKGDIR)-common/$(OODIR)/program/gengalrc
#endif

ifeq "$(ENABLE_JAVA)" "y"
	# somehow --has-package-version doesn't overwrite version and without <version>...</version>
	# we get a NullPointerException when calling mh_installjar
	sed -e s/@version@/$(shell echo $(DEB_VERSION_UPSTREAM) | cut -d~ -f1)/ \
		< debian/pom.unoil.xml.in > debian/pom.unoil.xml
	mh_installpoms -plibreoffice-java-common
	mh_installjar -plibreoffice-java-common -l debian/pom.unoil.xml instdir/program/classes/unoil.jar
endif

	touch $@

binary-arch: $(STAMP_DIR)/binary-arch
$(STAMP_DIR)/binary-arch: $(STAMP_DIR)/install-arch debian/control $(STAMP_DIR)/maintscripts
	dh_testdir
	dh_testroot

	for pkg in $(ARCH_DEP_PACKAGES) ; do \
	  rm -f debian/$$pkg.*.debhelper;\
	  rm -rf debian/$$pkg/DEBIAN;\
	done

	dh_installdocs -s -A
	for p in $(ARCH_DEP_PACKAGES); do \
		mkdir -p debian/$$p/usr/share/doc/$$p; \
		cp workdir/CustomTarget/readlicense_oo/readme/README_en-US \
			debian/$$p/usr/share/doc/$$p/README; \
	done 
	dh_installdebconf -s
	dh_installman -s
	for i in writer calc draw base math impress; do \
		for i in `find $(PKGDIR)-$$i -type l -name "lo*.1"`; do \
			mv $$i $$i.gz; \
			if [ "`readlink $$i`" != "libreoffice.1.gz" ]; then \
				ln -sf libreoffice.1.gz $$i.gz; \
			fi; \
		done; \
	done
	dh_installchangelogs -s -k
	dh_installmime -s
	dh_installmenu -s
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
	dh_nativejava -plibreoffice-gcj -o
  endif
endif
ifeq "$(WHEEZY_BACKPORT)" "y"
	dh_python2 -ppython-uno --no-guessing-versions --no-guessing-deps
	dh_python2 -ppython-uno --no-guessing-versions --no-guessing-deps $(OODIR)/program
else
	dh_python3 -ppython3-uno --no-ext-rename --no-guessing-deps
	dh_python3 -ppython3-uno --no-ext-rename --no-guessing-deps $(OODIR)/program
  ifeq "$(ENABLE_PYTHON2)" "y"
	dh_python2 -ppython-uno --no-guessing-versions --no-guessing-deps
	dh_python2 -ppython-uno --no-guessing-versions --no-guessing-deps $(OODIR)/program
  endif
endif
	dh_lintian -s
	dh_bugfiles -s -A
	dh_link -s -X.desktop
	dh_fixperms -s
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	dh_strip -s -Nure -Nuno-libs3 --dbg-package=libreoffice-dbg
	dh_strip -pure --dbg-package=ure-dbg
	dh_strip -puno-libs3 --dbg-package=uno-libs3-dbg
	# dh_strip --dbg-package= is not idempotent, force copying of the binaries
	# again...
	rm -f $(STAMP_DIR)/install-arch
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	mkdir -p $(PKGDIR)-dbg/usr/share/gdb/auto-load/$(OODIR)
	mv $(CURDIR)/debian/tmp/usr/share/gdb/auto-load/$(OODIR)/program \
		$(PKGDIR)-dbg/usr/share/gdb/auto-load/$(OODIR)
	# I think a -dbg-common is overkill. Although this means that this all only
	# will work if libreoffice-dbg is installed..
	mkdir -p $(PKGDIR)-dbg/usr/share/libreoffice/gdb
	mv $(CURDIR)/debian/tmp/usr/share/libreoffice/gdb/libreoffice \
		$(PKGDIR)-dbg/usr/share/libreoffice/gdb
	# FIXME: or better ure-dbg (ure/lib?). Then again ure-link is a link which is in -common
	# anyways...
	mkdir -p debian/uno-libs3-dbg/usr/share/gdb/auto-load/$(OOUREDIR)/lib
	mv $(CURDIR)/debian/tmp//usr/share/gdb/auto-load/$(OODIR)/ure/lib/* \
		debian/uno-libs3-dbg/usr/share/gdb/auto-load/$(OOUREDIR)/lib
	mkdir -p debian/uno-libs3-dbg/usr/share/libreoffice/gdb/libreoffice
	mv $(PKGDIR)-dbg/usr/share/libreoffice/gdb/libreoffice/cppu.py \
		debian/uno-libs3-dbg/usr/share/libreoffice/gdb/libreoffice
	mv $(PKGDIR)-dbg/usr/share/libreoffice/gdb/libreoffice/sal.py \
		debian/uno-libs3-dbg/usr/share/libreoffice/gdb/libreoffice
endif
else
	dh_strip -s
endif
	dh_icons -s
	dh_compress -s -X.py -X.mk -X.sxd
	dh_makeshlibs -puno-libs3 -V"uno-libs3 (>= $(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }' | cut -d. -f1-3)~), ure" -- -c0 -d -V -v`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_makeshlibs -n -pure -V"ure (>= $(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }' | cut -d. -f1-3)~)" -- -d -V -v`echo $(BINARY_VERSION) | cut -d: -f2`
	# ugly hack, but why does that happen? It's not in .symbols...
	TMP=`mktemp -q`; \
	grep -v PRIVATE debian/uno-libs3/DEBIAN/symbols > $$TMP && \
	mv $$TMP debian/uno-libs3/DEBIAN/symbols && \
	chmod 644 debian/uno-libs3/DEBIAN/symbols
	dh_installdeb -s
	cat debian/shlibs.override.libc >> debian/shlibs.local
ifeq (,$(filter icu, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.icu >> debian/shlibs.local
endif
ifneq (,$(filter libvisio, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.libvisio >> debian/shlibs.local
endif
ifeq (,$(filter libwps, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.libwps >> debian/shlibs.local
endif
ifeq (,$(filter libodfgen, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.libodfgen >> debian/shlibs.local
endif
ifeq (,$(filter libmwaw, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.libmwaw >> debian/shlibs.local
endif
ifeq (,$(filter librevenge, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.librevenge >> debian/shlibs.local
endif
ifeq (,$(filter glew, $(SYSTEM_STUFF)))
	cat debian/shlibs.override.glew >> debian/shlibs.local
endif
	# we need to do it in two steps. The new dpkg-shlibdeps doesn't find
	# /usr/lib/libgcj-bc.so when specifying -l$(GCJ_JAWT_DIR)
	# and therefore we must not use it for -gcj. But we *do* need it
	# for -officebean (libjawt.so is referenced there)
	LD_LIBRARY_PATH="$(FAKEROOT_LIBDIR):debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program:$(PKGDIR)-base-core/$(OODIR)/program:$(PKGDIR)-base/$(OODIR)/program:$(PKGDIR)-writer/$(OODIR)/program" \
		dh_shlibdeps -s -Nlibreoffice-officebean \
			-Lure -Luno-libs3 \
			-ldebian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program:$(PKGDIR)-base/$(OODIR)/program:$(shell dirname $(shell dpkg -L `echo $(GCJ_JAWT_DEPENDS) | sed -e s/-awt//` | grep _bc)) \
			$(SHLIBS_OVERRIDE)
ifneq (,$(filter redland, $(SYSTEM_STUFF)))
	# dpkg-shlibdeps "in practice" always will look for this in
        # /usr/lib/openoffice/basisX.Y/program due to the RPATH and the
	# dh_shlibdeps would fail. It's excluded, and we now need to do it
	# manually. Saves us a versioned build-conflict with ourselves
	# which quickly can get outdated
	perl -pi -e 's/(shlibs.*$$)/$$1, $(shell cat /var/lib/dpkg/info/$(shell dpkg -S /usr/lib/$(DEB_HOST_MULTIARCH)/`objdump -p $(PKGDIR)-core/$(OODIR)/program/libunordf*.so | grep NEEDED | grep librdf | awk '{ print $$2 }'` | cut -d: -f1)\:$(DEB_HOST_ARCH).shlibs | awk '{ print $$3,$$4,$$5 }')/' $(PKGDIR)-core.substvars
endif
	# Clean up .substvars values added by uno-libs3.symbols (adds uno-libs3, ure):
	# 1) don't make uno-libs3 depend on ure...
	perl -pi -e 's/, ure$$//' debian/uno-libs3.substvars
	# 2) and prevent ure to depend on itself..
	perl -pi -e 's/, ure \(.*\)$$//' debian/ure.substvars
ifeq "$(ENABLE_JAVA)" "y"
	LD_LIBRARY_PATH="$(FAKEROOT_LIBDIR):debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
		dh_shlibdeps -plibreoffice-officebean \
			-Lure -Luno-libs3 \
			-ldebian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program:$(GCJ_JAWT_DIR) \
			$(SHLIBS_OVERRIDE)
endif
ifeq "$(ENABLE_JAVA)" "y"
	for p in $(ARCH_DEP_PACKAGES); do \
		if [ "$$p" = "libreoffice-presentation-console" ]; then continue; fi; \
		jh_depends -p$$p -Xlibreoffice-gcj -Xlibreoffice-dbg -Xure; \
	done
  ifeq "$(PACKAGE_BASE)" "y"
    ifeq "$(WHEEZY_BACKPORT)" "y"
	perl -pi -e "s/libhsqldb-java/$(BASE_HSQLDB_DEPENDS)/" \
		debian/libreoffice-sdbc-hsqldb.substvars
    endif
	perl -pi -e "s/base-files,//" \
		debian/libreoffice-sdbc-hsqldb.substvars
  endif
	# jh_depends adds ure (${source:Version}) entries. They are overly strict
	# and do not fit anyway given ure has a different versioning scheme. Excluded
	# above, readd here  unversioned
	perl -pi -e 's/^(java:Depends.*$$)/\1, ure/' \
		debian/libreoffice-officebean.substvars
endif
# This switch to dh_shlibdeps reduces the 'libXXX not found' warnings but
# causes ldd crashes sometimes when used with fakeroot:
#          -l $(PKGDIR)-core/$(OPENOFFICEDIR)/program
	dh_gencontrol -s $(DEBHELPER_OPTIONS) -Nure -Nure-dbg -Nuno-libs3 -Nuno-libs3-dbg \
		-Nlibreoffice-presentation-minimizer \
		-Nlibreoffice-mysql-connector -- \
		-V"ure:Version=$(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }')" \
		-V'base-version=$(BASE_VERSION)' \
		-V'oover=$(OOVER)' \
		-V'next-oover=$(NEXT_OOVER)' \
		-V'help-l10n-virtual-version=$(HELP_L10N_VIRTUAL_VERSION)' \
		-V'base-hsqldb-depends=$(BASE_HSQLDB_DEPENDS)' \
		-V'java-common-depends=$(JAVA_COMMON_DEPENDS) $(JAVA_COMMON_DEPENDS_VERSION)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-V'java-gcj-depends=$(JAVA_GCJ_DEPENDS)' \
		-V'Binary-Version=$(BINARY_VERSION)' \
		-V'ooo-officebean-dep=$(OOO_OFFICEBEAN_DEP)' \
		-V'kde-iconset-dep=$(KDE_ICONSET_DEP)' \
		-V'lpsolve-dep=$(LPSOLVE_DEP)' \
		-V'gstreamer-plugins-suggests=$(GSTREAMER_PLUGINS_SUGGESTS)' \
		-V'libebook-dep=$(shell debian/scripts/get_libebook_dep.sh)' \
		-V'libvlc-dep=$(shell debian/scripts/get_libvlc_dep.sh)' \
		-V'idlc-cpp-depends=$(IDLC_CPP_DEPENDS)' \
		-V'pyuno-depends=$(PYUNO_DEPENDS)' \
		-V'avmedia-be-depends=$(AVMEDIA_BE_DEPENDS)' \
		-V'dejavu-depends=$(DEJAVU_DEPENDS)' \
		-V'opencl-sug=$(OPENCL_SUGGESTS)' \
		-V'dbg-dbg-suggests=$(DBG_DBG_SUGGESTS)' \
		-v$(BINARY_VERSION)
ifeq "$(ENABLE_JAVA)" "y"
	perl -pi -e "s/java-gcj-compat/java-gcj-compat (>= 1.0.77-4)/" \
		debian/libreoffice-officebean/DEBIAN/control
endif
ifneq (,$(findstring $(DEB_HOST_ARCH),$(OOO_ARCH_DEP_EXTENSIONS_ARCHS)))
ifeq "$(PACKAGE_BASE)" "y"
  ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	dh_gencontrol -plibreoffice-mysql-connector -- \
		-v$(shell grep "<version" $(SOURCE_TREE)/mysqlc/source/description.xml | perl -pi -e 's,<version value=\"(.*)\" />,\1,; s/^\s+//; s/\s+$$//')+LibO`echo $(BINARY_VERSION) | cut -d: -f2`
  endif
endif
endif
	dh_gencontrol -pure -puno-libs3 -- \
		-V"ure:Version=`echo $(BINARY_VERSION) | cut -d: -f2`" \
		-v"`echo $(BINARY_VERSION) | cut -d: -f2`"
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	dh_gencontrol -pure-dbg -puno-libs3-dbg -- \
		-V"ure:Version=`echo $(BINARY_VERSION) | cut -d: -f2`" \
		-v"`echo $(BINARY_VERSION) | cut -d: -f2`"
endif
	dh_md5sums -s
	dh_builddeb -s $(DEBHELPER_OPTIONS) $(BUILDDEB_OPTIONS)

	touch $@

binary-indep: $(GSI_EXPORT_STAMP) $(STAMP_DIR)/binary-indep
$(STAMP_DIR)/binary-indep: $(STAMP_DIR)/install-indep debian/control $(STAMP_DIR)/maintscripts $(STAMP_DIR)/langpacks
ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),$(OOO_JAVA_ARCHS)))
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "For uploads with binary-all packages, please use arches where Java is enabled!!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
endif
	dh_testdir
ifneq ($(PACKAGE_SDK_DOCS),y)
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "For uploads with binary-all packages, please use arches where the SDK docs are enabled!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
endif
	dh_testdir
	dh_testroot

	for pkg in $(ARCH_INDEP_PACKAGES) ; do \
	  rm -f debian/$$pkg.*.debhelper;\
	  rm -rf debian/$$pkg/DEBIAN;\
	done

ifeq "$(PACKAGE_SDK)" "y"
	for i in common cpp java; do \
		cat debian/lo-$$i-ref.in \
			| sed -e "s/@lo_sources_ver@/$(lo_sources_ver)/" \
			> debian/libreoffice-dev-doc.doc-base.lo-$$i-ref; \
	done
	# remove Autodoc_DiagnosticMessages.txt
	find $(PKGDIR)-dev-doc/usr/share/doc/libreoffice-dev \
		-name "Autodoc_DiagnosticMessages.txt" -exec rm {} \;
	UDK_CPP_FILES=`find $(CURDIR)/debian/libreoffice-dev-doc/usr/share/doc/libreoffice-dev/docs/cpp/ref | sed -e 's,$(CURDIR)/debian/libreoffice-dev-doc,,g' | xargs`; \
	echo "Files: $$UDK_CPP_FILES" >> debian/libreoffice-dev-doc.doc-base.lo-cpp-ref
  ifeq "$(ENABLE_JAVA)" "y"
	UDK_JAVA_FILES=`find $(CURDIR)/debian/libreoffice-dev-doc/usr/share/doc/libreoffice-dev/docs/java/ref | sed -e 's,$(CURDIR)/debian/libreoffice-dev-doc,,g' | xargs`; \
	echo "Files: $$UDK_JAVA_FILES" >> debian/libreoffice-dev-doc.doc-base.lo-java-ref
  endif
	# xargs strips the many files here so we need to post-process it.
	UDK_COMMON_FILES=`find $(CURDIR)/debian/libreoffice-dev-doc/usr/share/doc/libreoffice-dev/docs/common/ref | sed -e 's,$(CURDIR)/debian/libreoffice-dev-doc,,g' | xargs`; \
	TMP=`mktemp -q`; \
	cp debian/libreoffice-dev-doc.doc-base.lo-idl-ref $$TMP; \
	echo "Files: $$UDK_COMMON_FILES" >> $$TMP; \
	cat $$TMP | perl -e 'while(<>) { if (/^Files/) {$$f=1;} if ($$f eq "1") { chomp(); } print $$_; }' > debian/libreoffice-dev-doc.doc-base.lo-idl-ref; \
	rm -f $$TMP
	# no idea why this happens; afais this can't come from above
	# since it doesn't affect the files at the end of the lines...
	# But fix it..
	perl -pi -e 's,html/,html /,g' debian/libreoffice-dev-doc.doc-base.lo-idl-ref
endif
	dh_installdocs -i -A 
	for p in $(ARCH_INDEP_PACKAGES); do \
		mkdir -p debian/$$p/usr/share/doc/$$p; \
		cp workdir/CustomTarget/readlicense_oo/readme/README_en-US \
			debian/$$p/usr/share/doc/$$p/README; \
	done 
	dh_installman -i
	for i in `find $(PKGDIR)-common -type l -name "lo*.1"`; do \
		mv $$i $$i.gz; \
		if [ "`readlink $$i`" != "libreoffice.1.gz" ]; then \
			ln -sf libreoffice.1.gz $$i.gz; \
		fi; \
	done
	dh_installchangelogs -i -Nlibreoffice-librelogo -k
ifeq "$(PACKAGE_LIBRELOGO)" "y"
	 dh_installchangelogs -plibreoffice-librelogo -k librelogo/source/ChangeLog
endif
ifeq "$(PACKAGE_SDK_DOCS)" "y"
	dh_doxygen -plibreoffice-dev-doc
endif
	dh_installmime -i
	dh_lintian -i
	dh_bugfiles -i -A
	dh_link -i -X.desktop
	# dh_link -X does not work for .links stuff. And adding it there and
	# fixing it up later because it's relative doesn't make that much sense.
	# So do it here.
	mkdir -p $(PKGDIR)-common/usr/share/applications
	cd $(PKGDIR)-common/usr/share/applications && \
		ln -sf /$(OODIR)/share/xdg/startcenter.desktop libreoffice-startcenter.desktop
	dh_fixperms -i
	dh_icons -i
	dh_installxmlcatalogs -i
	dh_compress -i -X.py -X.mk -X.sxd -X.xcd.sample
	dh_installdeb -i
ifeq "$(ENABLE_JAVA)" "y"
	for p in $(ARCH_INDEP_PACKAGES); do \
                if echo "$$p" | grep -q help; then continue; fi; \
                jh_depends -p$$p -Xlibreoffice-gcj -Xlibreoffice-dbg \
			-Xlibreoffice-report-builder; \
        done
endif
	dh_gencontrol -i $(DEBHELPER_OPTIONS) \
		-Nlibreoffice-wiki-publisher \
		-Nfonts-opensymbol \
		-Nopenoffice.org-dtd-officedocument1.0 -- \
		-V'base-version=$(BASE_VERSION)' \
		-V'oover=$(OOVER)' \
		-V'next-oover=$(NEXT_OOVER)' \
		-V'help-l10n-virtual-version=$(HELP_L10N_VIRTUAL_VERSION)' \
		-V'bsh-depends=$(BSH_DEPENDS)' \
		-V'java-common-depends=$(JAVA_COMMON_DEPENDS)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-V'textcat-data-recommends=$(TEXTCAT_DATA_RECOMMENDS)' \
		-V'pyuno-depends=$(PYUNO_DEPENDS)' \
		-V'Binary-Version=$(BINARY_VERSION)' \
		-V'dbg-dbg-suggests=$(DBG_DBG_SUGGESTS)' \
		-v$(BINARY_VERSION)
ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	dh_gencontrol -pfonts-opensymbol -- \
		-v$(shell echo `echo $(BINARY_VERSION) | cut -d: -f1` + 1 | bc):$(shell fontforge -lang=ff -c 'Open($$1); Print ($$fontversion); Quit(0);' debian/fonts-opensymbol/usr/share/fonts/truetype/openoffice/opens___.ttf)+LibO`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_MEDIAWIKI)" "y"
	dh_gencontrol -plibreoffice-wiki-publisher -- \
		-V'mediawiki-jar-depends=$(MEDIAWIKI_JAR_DEPENDS)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-v$(shell grep "<version" $(SOURCE_TREE)/swext/mediawiki/src/description.xml | perl -pi -e 's,<version value=\"(.*)\"/>,\1,; s/^\s+//')+LibO`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_REPORTDESIGN)" "y"
	dh_gencontrol -plibreoffice-report-builder -- \
		-V'base-version=$(BASE_VERSION)' \
		-V'report-builder-jar-depends=$(REPORT_BUILDER_JAR_DEPENDS)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)'
endif
	dh_gencontrol -popenoffice.org-dtd-officedocument1.0 -- \
		-v$(shell echo `echo $(BINARY_VERSION) | cut -d: -f1` + 1 | bc):1.0+LibO`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_md5sums -i
	dh_builddeb -i $(DEBHELPER_OPTIONS) $(BUILDDEB_OPTIONS)

	touch $@

binary: binary-arch binary-indep

ifeq "$(USE_GIT_TARBALLS)" "y"

# $(1) is the upstream name of the repo
# $(2) is the name of the tarball
# $(3) is the path to archive (empty for everything)
#
# according to policy get-orig-source has to download to the current dir, thus
# should not require a dh_testdir. However, like this we can have clean deps
# from build and download the source, configure, build, pack in on piece. As
# get-orig-source is an optional target anyway, we stick to support only this
# case and not random dirs. see also: debian bug 494141
# also, we need to run configure to create the external tarball anyway

GIT_INSTALLED:=$(shell which git >/dev/null 2>/dev/null && echo "y")

get_orig_tarball=$(CURDIR)/../libreoffice_$(DEB_VERSION_UPSTREAM).orig$(1).tar.xz

define pack_gittarball
$(if $(GIT_INSTALLED),,$(error You need git.))
dh_testdir
TMPD=`mktemp -d $(if $(TMP),-p $(TMP))` && \
mkdir $${TMPD}/archive && \
git clone --bare $(GIT_BASEURL)/$(1) $${TMPD}/repo -b $(GIT_BRANCH) && \
git archive --remote $${TMPD}/repo --format=tar --prefix libreoffice-$(DEB_VERSION_UPSTREAM)/ $(GIT_TAG) |tar x -C $${TMPD}/archive && \
tar cvJf $(2) -C $${TMPD}/archive/$(3) --transform 's,./,,' . && \
rm -rf $${TMPD}
endef

define unpack_gittarball
dh_testdir
mkdir -p $(CURDIR)/$(1)
test -f $(CURDIR)/$(1)/.gitignore || tar xvJf $(2) -C $(CURDIR)/$(1) $(3)
endef

ifneq ($(filter get-orig-source unpack,$(MAKECMDGOALS)),)
$(call get_orig_tarball):
	$(call pack_gittarball,core,$@,)

$(call get_orig_tarball,-helpcontent2):
	$(call pack_gittarball,help,$@,libreoffice-$(DEB_VERSION_UPSTREAM)/)

$(call get_orig_tarball,-%):
	$(call pack_gittarball,$*,$@,libreoffice-$(DEB_VERSION_UPSTREAM)/)

# Get upstream external sources
$(call get_orig_tarball,-external): helpcontent2/makefile.pmk translations/makefile.mk .gitignore
	dh_testdir
	rm -rf $(TARFIILE_LOCATION)
	mkdir -p $(TARFILE_LOCATION)
	./autogen.sh --with-all-tarballs
	$(MAKE) download
	tar cvJf $@ -C external --transform 's,./,,' .

# using flag files for unpacking
.gitignore: $(call get_orig_tarball)
	$(call unpack_gittarball,,$<,--strip-components=1)

translations/makefile.mk:  $(call get_orig_tarball,-translations)
	$(call unpack_gittarball,translations,$<,)

helpcontent2/makefile.pmk:  $(call get_orig_tarball,-helpcontent2)
	$(call unpack_gittarball,helpcontent2,$<,)

external/tarballs/fetch.log: $(call get_orig_tarball,-external) patched
	$(call unpack_gittarball,external,$<,)

get-orig-source: $(call get_orig_tarball,-external) external/tarballs/fetch.log
	dh_testdir

unpack: external/fetch.log
	dh_testdir
endif
endif


.PHONY: control
.PHONY: clean-debdir clean-instsetoo clean-objectdirs clean default
.PHONY: prepare build build-indep build-arch install-arch install-indep
.PHONY: get-orig-source unpack patched
.PHONY: $(stampdir_targets)

# vim:set noet ai sts=8 sw=8 tw=0:
