#!/usr/bin/make -f
################################################################################
# OpenOffice.org source package rules file
#
# Please see debian/README for detailed documentation about the build system, and
# how to build OpenOffice.org.
################################################################################
# Authors:
# Chris Halls <halls@debian.org>
# Rene Engelhard <rene@debian.org>
# Copyright 2002-2009 Software in the Public Interest, Inc.
# 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>.
################################################################################

PKGSOURCE := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2;exit 0}')
SOURCE_VERSION:=$(shell head -1 debian/changelog | cut -d\( -f2 | cut -d\) -f1)
UPSTREAM_VERSION:=$(shell echo "$(SOURCE_VERSION)"| cut -d: -f2 | cut -d- -f1)
BASE_VERSION:=$(shell echo $(SOURCE_VERSION) | cut -d: -f1):$(UPSTREAM_VERSION)
BINARY_VERSION=$(SOURCE_VERSION)
#BINARY_VERSION=1:2.4.0-$(shell dpkg-parsechangelog  | grep urgency \
	| awk '{print $$2}' | sed -e s/"("// -e s/")"// | cut -d"-" -f2)
#HELP_L10N_VIRTUAL_VERSION:=$(shell echo $(UPSTREAM_VERSION) | cut -d: -f2 | tr [~] [\\-])
HELP_L10N_VIRTUAL_VERSION:=3.2
#VER:=3
OOVER:=3.2
BASIS_VERSION:=$(OOVER)

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

OS := $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
DIST := $(shell lsb_release -is)
DISTREL := $(shell lsb_release -cs)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
SHELL:=/bin/bash

PKGDIR:=debian/openoffice.org$(VER)
OODIRNAME=openoffice$(VER)
OOBRANDDIR:=usr/lib/$(OODIRNAME)
OOBASISDIR:=$(OOBRANDDIR)/basis$(BASIS_VERSION)
OOSDKDIR:=$(OOBASISDIR)/sdk
OOUREDIR:=usr/lib/ure
# compatability
OODIR:=$(OOBASISDIR)

# Figure out who's building this package.
OOO_VENDOR:=Debian
ifeq "$(DIST)" "Ubuntu"
OOO_VENDOR+= 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"

# work around tcsh bugs.debian.org/339034: tcsh: Unknown colorls variable `su'
unexport LS_COLORS

ifneq (,$(filter $(ARCH), arm armel))
	export ICU_ARCH_FLAGS = -Os
endif

MWS=OOO320
#MILESTONE:=$(shell echo "$(UPSTREAM_VERSION)" | cut -d~ -f2 | sed -e s/$(shell echo $(MWS) | tr A-Z a-z)//)
MILESTONE=m12
#TAG=$(shell echo $(MWS) | tr A-Z a-z)-$(MILESTONE)
TAG=$(MWS)_$(MILESTONE)
OOO_BUILD_BRANCH=ooo-build-3-2
OOO_BUILD_VERSION=3.2.0.10
OOO_BUILD_TAG=OOO_BUILD_$(shell echo $(OOO_BUILD_VERSION) | sed -e 's/\./_/g')
OOO_BUILD_TREE=ooo-build-$(shell echo $(OOO_BUILD_VERSION) | sed -e 's/\./-/g')
SOURCE_TREE=$(OOO_BUILD_TREE)/build/$(TAG)
STAMP_DIR=debian/stampdir
# unused yet but will get important for OOo 3.3
TARFILE_LOCATION=$(CURDIR)/ext-sources
export TARFILE_LOCATION

ifeq "$(DISTREL)" "lenny"
 LENNY_BACKPORT=y
endif

#########
# Default package configuration
#
BUILD_AMD64=y
BUILD_IA64=y
BUILD_PPC64=y
BUILD_S390X=y
BUILD_SPARC=y
BUILD_ARMEL=y
BUILD_HPPA=y
BUILD_ALPHA=y
PATCHSET=$(DIST)
BUILD_DEPS=
BUILD_PYUNO=y
USE_PYCENTRAL=y
USE_PYSUPPORT=n
PACKAGE_TTF_OPENSYMBOL=y
ifneq "$(ARCH)" "powerpc"
  ifneq "$(ARCH)" "ppc64"
    BUILD_JARS_NATIVE=y
 endif
endif
BUILD_BINFILTERS=y
BUILD_ONLY_EN_US=n
ENABLE_JAVA=y
JDK=openjdk
ifeq "$(ARCH)" "ia64"
  JDK=gcj-jdk
endif
ifneq (,$(findstring mips,$(ARCH)))
  JDK=gcj-jdk
endif
ifneq (,$(findstring kfreebsd,$(ARCH)))
  JDK=gcj-jdk
endif
ifeq "$(ARCH)" "hppa"
  JDK=gcj-jdk
endif
ENABLE_MONO=y
MONO2=y
ifeq "$(MONO2)" "y"
  MONO_MINVER= (>= 2.4.2.3)
else
  MONO_MINVER= (>= 1.2.3)
endif
USE_SYSTEM_HUNSPELL=y
HUNSPELL_MIN_VER= (>= 1.1.5-2)
SYSTEM_ALTLINUXHYPH=y
USE_LIBHYPHEN=y
LIBALTLINUXHYPH_MINVER= (>= 0.1.1-11)
LIBHYPHEN_MINVER= (>= 2.4)
USE_AGG=n
SYSTEM_AGG=n
USE_STLPORT=n
USE_SYSTEM_STLPORT=y
USE_SYSTEM_BOOST=y
BOOST_VERSION=default
ifeq "$(BOOST_VERSION)" "default"
  BOOST_MINVER= (>= 1.38)
endif
ifeq "$(BOOST_VERSION)" "1.39"
  BOOST_MINVER= (>= 1.39.0-2)
endif
USE_SYSTEM_VIGRA=y
USE_EXTERNAL_CXXLIBS=y
LIBWPD8_MINVER= (>= 0.8.3-3)
USE_SYSTEM_SABLOT=n
USE_LIBXSLT=y
USE_EXTERNAL_MYTHES=n
USE_SYSTEM_ICU=y
ICU_MINVER= (>= 4.0)
USE_SYSTEM_LIBWPG=y
USE_SYSTEM_LIBWPS=y
USE_SYSTEM_XMLSEC=n
BUILD_CAIROCANVAS=y
USE_SYSTEM_CAIRO=y
CAIRO_FONTS_PATCH=y
BUILD_KDE=y
KDE_VER=4
ifeq "$(BUILD_KDE)" "y"
  ifeq "$(KDE_VER)" "3"
    ENABLE_KDEAB=y
  else
    ENABLE_KDEAB=n
  endif
endif
ifeq "$(KDE_VER)" "3"
  KDELIBS_MINVER= (>= 4:3.4.3-2)
endif
ifeq "$(KDE_VER)" "4"
  QT_MINVER= (>= 4.5)
  # somehow lenny-backport picks this up although
  # KDE is 3...
  ifneq "$(LENNY_BACKPORT)" "y"
    KDELIBS_MINVER= (>= 4:4.3.4)
  endif
endif  
BUILD_DBG_PACKAGE=y
USE_SYSTEM_BSH=y
USE_SYSTEM_HSQLDB=y
HSQLDB_MINVER= (>> 1.8.0.10)
# disabled because system-saxon breaks all kinds exports using XSLT transforms
# (e.g. M$ Word/Excel 2003 XML, Mediawiki, XHTML, UOF, ...)
# It does *NOT* fail with _plain_ saxon 9.0.0.8 built with OOos build.xml
# for UOF, but still for e.g. M$.
USE_SYSTEM_SAXON=n
USE_SYSTEM_LUCENE=y
USE_SYSTEM_LPSOLVE=y
USE_SHARED_LPSOLVE=y
LPSOLVE_MIN_VERSION= (>= 5.5.0.13-5+b1)
USE_DBUS=y
USE_GSTREAMER=y
USE_SYSTEM_NEON=y
NEON_SECTYPE=gnutls
NEONSONR=27
USE_SYSTEM_REDLAND=y
USE_OOO_BUILD_DESKTOPS=n
PACKAGE_SDK=y
RUN_SMOKETEST=n
RUN_API_TESTS=n
RUN_UNIT_TESTS=n
USE_LIBCURL4=y
CURL_SECTYPE=gnutls
USE_SYSTEM_DMAKE=y
USE_LIBSUITESPARSE=y
SUITESPARSE_MIN_VERSION= (>= 1:3.4.0)
PARALLEL_BUILD=n
USE_COMMON_DOCDIR=n
MOZILLA=libxul
ENABLE_LDAP=y
USE_OPENLDAP=y
ENABLE_OPENGL=y
SYSTEM_OPENSSL=y
NEW_DPKG_SHLIBDEPS=y
ifeq "$(ENABLE_JAVA)" "y"
  # can be reenabled after cws rptfix04
  ENABLE_REPORTDESIGN=y
  USE_SYSTEM_JFREEREPORT=y
  ENABLE_MEDIAWIKI=y
  USE_SYSTEM_APACHE_COMMONS=y
else
  ENABLE_REPORTDESIGN=n
  ENABLE_MEDIAWIKI=n
endif
ENABLE_SDBC_POSTGRESQL=y
ENABLE_MINIMIZER=y
ENABLE_PRESENTER_CONSOLE=y
ENABLE_PDFIMPORT=y
BUILD_GTK=y
ENABLE_EVO2=y
ENABLE_GVFS=y
ENABLE_GCONF=y
# broken!
ENABLE_GIO=n
ENABLE_RANDR=y
ENABLE_LAYOUT=y
ifeq "$(BUILD_GTK)" "y"
  PACKAGE_NPSOPLUGIN=y
endif
# "new" source split? This is to be n when to use
# Suns tarballs.
WITH_SPLIT=n
ENABLE_GRAPHITE=y
USE_SYSTEM_GRAPHITE=y
ALLOC=system
DEBSRC_VERSION=3.0

# when we have a package we want to have to be installed on older things with some older
# C++ ABI (like it was the case with openoffice.org2), we need to set this. Don't touch
# otherwise
INTERNAL_STDLIBS=n
DEFAULT_IMAGE=galaxy
IMAGES:=$(DEFAULT_IMAGE) industrial crystal hicontrast tango oxygen classic
ENABLE_MYSQLNATIVE=y
# cannot be disabled, unless you have a internal MySQL somewhere :-)
USE_SYSTEM_MYSQLCLIENT=y
USE_SYSTEM_MYSQLCPPCONN=y
MYSQLCPPCONN_MINVER= (>= 1.1.0~r791)
DICT_DIR=/usr/share/hunspell
HYPH_DIR=/usr/share/hyphen
THES_DIR=/usr/share/mythes

# Default flags to pass to configure of ooo-build
CONFIGURE_FLAGS= --disable-post-install-scripts \
                 --with-tag=$(TAG) \
                --with-distro=$(PATCHSET) \
		--with-vendor='$(OOO_VENDOR)' \
                --enable-package-directories \
                --with-installed-ooo-dirname=$(OODIRNAME) \
                --mandir=/usr/share/man \
                --with-docdir=/usr/share/doc/openoffice.org \
                --with-build-version="ooo-build $(OOO_BUILD_VERSION), Debian $(BINARY_VERSION), `LC_ALL=C date`" \
                --disable-strip \
                --enable-lockdown \
		--with-drink=coffee \
		--libdir=/usr/lib \
		--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		--enable-hids \
		--with-system-dicts \
		--with-additional-sections="$(ADDITIONAL_SECTIONS)" \
		--without-git

ifneq "$(WITH_SPLIT)" "y"
	CONFIGURE_FLAGS += --without-split
endif

# distro-configs is too late; it already gets searched in unpack
# when we don't do that here, too.
CONFIGURE_FLAGS += --disable-access

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

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

# Debian
ifeq "$(DIST)" "Debian"
  # we don't need to build all languages and the thesaurus on the buildds;
  # they do binary-only builds anyway
  ifeq (buildd,$(shell whoami))
       BUILD_ONLY_EN_US=y
  endif
endif

ifeq "$(DIST)" "Ubuntu"
  # common settings
  PATCHSET=$(DIST)$(shell perl -e 'print ucfirst("$(DISTREL)");')
  CONFIGURE_FLAGS += \
       --with-about-bitmaps=$(CURDIR)/debian/ubuntu/openabout_ubuntu_oracle.bmp \
       --with-intro-bitmaps=$(CURDIR)/debian/ubuntu/openintro_ubuntu_oracle.bmp

  BUILD_DEPS += , translate-toolkit (>= 1.1.1)

  HUMAN=human
  IMAGES += $(HUMAN)

  BUILD_ARMEL=y
  BUILD_DBG_PACKAGE=n
  # GVFS broken and obsolete
  ENABLE_GVFS=n
  USE_COMMON_DOCDIR=y
  USE_LZMA_COMPRESS=y
  USE_OOO_BUILD_DESKTOPS=y
  # won't fit on CD
  USE_SYSTEM_LUCENE=n

  # find extra translations here
  export DEB_GSIDIR=$(CURDIR)/debian/ubuntu/l10n

  ifeq "$(DISTREL)" "lucid"
    BOOST_VERSION=1.40
    BOOST_MINVER=(>= 1.40.0)
    # in universe and too late in the cycle
    USE_SYSTEM_MYSQLCPPCONN=n

  else ifeq "$(DISTREL)" "karmic"
    BOOST_VERSION=1.38
    BOOST_MINVER=(>= 1.38.0)
    DEBSRC_VERSION=1.0
    ENABLE_MYSQLNATIVE=n
    DICT_DIR=/usr/share/myspell/dicts
    HYPH_DIR=/usr/share/myspell/dicts
    THES_DIR=/usr/share/myspell/dicts
    PRUNE_OOOBUILD=n
    # too old
    USE_SYSTEM_GRAPHITE=n
    ifeq "$(KDE_VER)" "4"
      KDELIBS_MINVER=
    endif  

  else ifeq "$(DISTREL)" "hardy"
    DEBSRC_VERSION=1.0
    PRUNE_OOOBUILD=n
    KDE_VER=3
    KDELIBS_MINVER= (>= 4:3.4.3-2)
    #ENABLE_MYSQLNATIVE=n
    DICT_DIR=/usr/share/myspell/dicts
    HYPH_DIR=/usr/share/myspell/dicts
    THES_DIR=/usr/share/myspell/dicts
    # too old
    BUILD_JARS_NATIVE=n
    ENABLE_MONO=n
    ENABLE_PDFIMPORT=n
    SYSTEM_ALTLINUXHYPH=n
    USE_LIBHYPHEN=n
    USE_SYSTEM_BOOST=n
    USE_SYSTEM_GRAPHITE=n
    USE_SYSTEM_HSQLDB=n
    USE_SYSTEM_ICU=n
    USE_SYSTEM_JFREEREPORT=n
    USE_SYSTEM_LPSOLVE=n
    USE_SYSTEM_REDLAND=n

  else # fallback

  endif

  ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
    INSTALLED_ODK=n
    export OOO_RUN_SDK_INSTALLER = no
  endif

endif

# Debian Lenny
ifeq "$(LENNY_BACKPORT)" "y"
  USE_SYSTEM_LUCENE=n
  USE_SYSTEM_ICU=n
  MONO_MINVER= (>= 1.2.3)
  MONO2=n
  USE_SYSTEM_BOOST=n
  LPSOLVE_MIN_VERSION= (>= 5.5.0.10-10)
  SUITESPARSE_MIN_VERSION= (>= 3.1.0)
  USE_SYSTEM_JFREEREPORT=n
  BUILD_KDE=y
ifeq "$(BUILD_KDE)" "y"
  ENABLE_KDEAB=y
endif
  KDE_VER=3
  CURL_SECTYPE=openssl
  HSQLDB_MINVER= (>> 1.8.0.9)
ifeq "$(ARCH)" "ia64"
  JDK=java-gcj-compat-dev
endif
ifneq (,$(findstring mips,$(ARCH)))
  JDK=java-gcj-compat-dev
endif
ifneq (,$(findstring kfreebsd,$(ARCH)))
  JDK=java-gcj-compat-dev
endif
  DICT_DIR=/usr/share/myspell/dicts
  HYPH_DIR=/usr/share/myspell/dicts
  THES_DIR=/usr/share/myspell/dicts
  MOZILLA=iceape
  # only works with system-mysqlcppconn on lenny (the thing has a hardoced
  # so.16). And mysql-connector-c++ is not in lenny.
  ENABLE_MYSQLNATIVE=n
  DEBSRC_VERSION=1.0
  USE_SYSTEM_REDLAND=n
endif

ifeq "$(DIST)" "Debian"
# the archive only accepts bzip2 compressed members on 3.0 (quilt)
ifeq "$(DEBSRC_VERSION)" "3.0"
  USE_BZIP_COMPRESS=y
  PRUNE_OOOBUILD=n
else
  USE_BZIP_COMPRESS=n
  PRUNE_OOOBUILD=y
endif
endif

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

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

# ./configure defaults to STLport on i386 and we should keep it for
# ABI-compatability
OOO_STLPORT_ARCHS= i386
ifeq "$(ARCH)" "i386"
	USE_STLPORT=y
endif
# graphite and mysqlconnector built against libstc++s STL but OOo wants them
# with STLport. Not possible without patch.
ifeq ($(ARCH),$(findstring $(ARCH),$(OOO_STLPORT_ARCHS)))
#	USE_SYSTEM_GRAPHITE=n
#	USE_SYSTEM_MYSQLCPPCONN=n
endif

ifeq "$(ENABLE_OPENGL)" "y"
# doesn't make that much sense on arm(el) and mips(el), does it? :)
OOO_OGLTRANS_ARCHS= i386 powerpc s390
ifeq "$(BUILD_AMD64)" "y"
  OOO_OGLTRANS_ARCHS+= amd64
endif
ifeq "$(BUILD_IA64)" "y"
  OOO_OGLTRANS_ARCHS+= ia64
endif
ifeq "$(BUILD_PPC64)" "y"
  OOO_OGLTRANS_ARCHS+= ppc64
endif
ifeq "$(BUILD_S390X)" "y"
  OOO_OGLTRANS_ARCHS+= s390x
endif
ifeq "$(BUILD_SPARC)" "y"
  OOO_OGLTRANS_ARCHS+= sparc
endif
ifeq (,$(findstring $(ARCH),$(OOO_OGLTRANS_ARCHS)))
       ENABLE_OPENGL=n
endif
else
  OOO_OGLTRANS_ARCHS=
endif

OOO_ARCHS= i386 m68k mips mipsel powerpc s390
ifeq "$(BUILD_ALPHA)" "y"
  OOO_ARCHS += alpha
  OOO_64BIT_ARCHS += alpha
endif
ifeq "$(BUILD_AMD64)" "y"
  OOO_ARCHS += amd64
  OOO_64BIT_ARCHS += amd64
endif
ifeq "$(BUILD_ARMEL)" "y"
  OOO_ARCHS += armel
endif
ifeq "$(BUILD_HPPA)" "y"
  OOO_ARCHS += hppa
endif
ifeq "$(BUILD_IA64)" "y"
  OOO_ARCHS += ia64
  OOO_64BIT_ARCHS += ia64
endif
ifeq "$(BUILD_PPC64)" "y"
  OOO_ARCHS += ppc64
  OOO_64BIT_ARCHS += ppc64
endif
ifeq "$(BUILD_S390X)" "y"
  OOO_ARCHS += s390x
  OOO_64BIT_ARCHS += s390x
endif
ifeq "$(BUILD_SPARC)" "y"
  OOO_ARCHS += sparc
endif

# Java...
OOO_JAVA_ARCHS = i386 mips mipsel powerpc s390
ifeq "$(BUILD_ALPHA)" "y"
  OOO_JAVA_ARCHS+= alpha
endif
ifeq "$(BUILD_AMD64)" "y"
  OOO_JAVA_ARCHS+= amd64
endif
ifeq "$(BUILD_ARMEL)" "y"
  OOO_JAVA_ARCHS+= armel
endif
ifeq "$(BUILD_HPPA)" "y"
  OOO_JAVA_ARCHS+= hppa
endif
ifeq "$(BUILD_IA64)" "y"
  OOO_JAVA_ARCHS+= ia64
endif
ifeq "$(BUILD_PPC64)" "y"
  OOO_JAVA_ARCHS+= ppc64
endif
ifeq "$(BUILD_S390X)" "y"
  OOO_JAVA_ARCHS+= s390x
endif
ifeq "$(BUILD_SPARC)" "y"
  OOO_JAVA_ARCHS+= sparc
endif

# gcj does not work on ppc, so no need to build -gcj for it
OOO_GCJ_ARCHS := $(filter-out ppc64,$(filter-out powerpc,$(OOO_JAVA_ARCHS)))

OOO_GCJ_JDK_ARCHS := hppa ia64 kfreebsd-i386 kfreebsd-amd64 mips mipsel
OOO_OPENJDK_ARCHS := $(filter-out $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))

OOO_ARCH_DEP_EXTENSIONS_ARCHS := $(filter-out armel,$(OOO_ARCHS))

ifeq (,$(findstring $(ARCH),$(OOO_ARCH_DEP_EXTENSIONS_ARCHS)))
	ENABLE_MINIMIZER=n
	ENABLE_PDFIMPORT=n
	ENABLE_PRESENTER_CONSOLE=n
	ENABLE_SDBC_POSTGRESQL=n
endif

ifeq (,$(findstring $(ARCH),$(OOO_JAVA_ARCHS)))
	ENABLE_JAVA=n
	ENABLE_REPORTDESIGN=n
	ENABLE_MEDIAWIKI=n
else
	# extra step needed for arm, as the if matches the arm in armel..
  ifeq "$(ARCH)" "arm"
	ENABLE_JAVA=n
	ENABLE_REPORTDESIGN=n
	ENABLE_MEDIAWIKI=n
  endif
endif

ifeq "$(ENABLE_MONO)" "y"
# mono
# ppc fails (#412967), arm(el), too
OOO_MONO_ARCHS = i386
ifeq "$(BUILD_AMD64)" "y"
  OOO_MONO_ARCHS += amd64
endif
ifeq "$(BUILD_IA64)" "y"
  OOO_MONO_ARCHS += ia64
endif
ifeq "$(BUILD_SPARC)" "y"
  OOO_MONO_ARCHS += sparc
endif
ifeq (,$(findstring $(ARCH),$(OOO_MONO_ARCHS)))
       ENABLE_MONO=n
endif
else
OOO_MONO_ARCHS=
endif

ifeq "$(PACKAGE_NPSOPLUGIN)" "y"
OOO_NPSOPLUGIN_ARCHS = $(OOO_ARCHS)
else
OOO_NPSOPLUGIN_ARCHS=
endif

ifeq "$(DIST)" "Debian"
# builds long and is for legacy filters. probably not needed on {arm,mips}{,el}
ifneq (,$(findstring arm,$(ARCH)))
	BUILD_BINFILTERS=n
endif
ifneq (,$(findstring mips,$(ARCH)))
	BUILD_BINFILTERS=n
endif
ifneq (,$(findstring m68k,$(ARCH)))
	BUILD_BINFILTERS=n
endif
OOO_BINFILTER_ARCHS:=$(filter-out arm,$(filter-out armel,$(OOO_ARCHS)))
OOO_BINFILTER_ARCHS:=$(filter-out mips,$(filter-out mipsel,$(OOO_BINFILTER_ARCHS)))
OOO_BINFILTER_ARCHS:=$(filter-out m68k,$(OOO_BINFILTER_ARCHS))
else
OOO_BINFILTER_ARCHS:=$(OOO_ARCHS)
endif

ifeq "$(ARCH)-linux-gnu" "sparc-linux-gnu"
	# use 32-bit compiler
	CC_PREFIX=sparc-linux-gnu-
else
	CC_PREFIX=$(shell gcc -dumpmachine)-
endif

ifeq (s390,$(findstring s390,$(OOO_ARCHS)))
	BUILD_DEPS += , g++ (>> 4.3.0) [s390], gcc (>> 4.3.0) [s390]
endif
ifeq "$(shell gcc --version | head -n 1 | awk '{print $$4}' | cut -d. -f1,2)" "4.4"
  ifeq (armel,$(findstring armel,$(OOO_ARCHS)))
	BUILD_DEPS += , g++-4.4 (>= 4.4.2-5) [armel]
  endif
endif

# Note that this does *NOT* only affect the mozilla plugin but also
# stuff like the xmlsecurity (which uses nss). For the plugin only,
# change the OOO_NPSOPLUGIN_ARCHS
OOO_MOZILLA_ARCHS=i386 mips mipsel powerpc s390
ifeq "$(BUILD_ALPHA)" "y"
	OOO_MOZILLA_ARCHS += alpha
endif
ifeq "$(BUILD_AMD64)" "y"
	OOO_MOZILLA_ARCHS += amd64
endif
ifeq "$(BUILD_ARMEL)" "y"
       OOO_MOZILLA_ARCHS += armel
endif
ifeq "$(BUILD_HPPA)" "y"
	OOO_MOZILLA_ARCHS += hppa
endif
ifeq "$(BUILD_IA64)" "y"
	OOO_MOZILLA_ARCHS += ia64
endif
ifeq "$(BUILD_PPC64)" "y"
	OOO_MOZILLA_ARCHS += ppc64
endif
ifeq "$(BUILD_S390X)" "y"
	OOO_MOZILLA_ARCHS += s390x
endif
ifeq "$(BUILD_SPARC)" "y"
	OOO_MOZILLA_ARCHS += sparc
endif

ifeq "$(USE_BZIP_COMPRESS)" "y"
	DPKG_DEPENDS = dpkg (>= 1.10.24)
	BUILDDEB_OPTIONS = -- -Zbzip2
endif

ifeq "$(USE_LZMA_COMPRESS)" "y"
	DPKG_DEPENDS = dpkg (>= 1.14.12ubuntu3)
  ifneq "$(ARCH)" "armel"
	BUILDDEB_OPTIONS = -- -Zlzma
  endif
endif

ifeq "$(DEBSRC_VERSION)" "3.0"
  ifeq "$(LENNY_BACKPORT)" "y"
	BUILD_DEPS += , dpkg-dev (>= 1.14.27)
  else
	BUILD_DEPS += , dpkg-dev (>= 1.15.1)
  endif
else
  ifeq "$(NEW_DPKG_SHLIBDEPS)" "y"
	# new dpkg-dev whcih works - in contrast to 1.4.9 and .10 -
	# without --ignore-missing-info
	BUILD_DEPS += , dpkg-dev (>= 1.14.11)
  endif
endif

ifeq "$(DEBSRC_VERSION)" "1.0"
	BUILD_DEPS += , quilt
endif

ifneq "$(OOO_OGLTRANS_ARCHS)" ""
	BUILD_DEPS += , libgl1-mesa-dev [$(OOO_OGLTRANS_ARCHS)], libglu1-mesa-dev [$(OOO_OGLTRANS_ARCHS)]
endif
ifeq "$(ENABLE_OPENGL)" "y"
	CONFIGURE_FLAGS += --enable-opengl
endif

ifneq "$(PACKAGE_SDK)" "y"
	CONFIGURE_FLAGS += --disable-odk
endif

ifeq "$(ENABLE_MINIMIZER)" "y"
	CONFIGURE_FLAGS += --enable-minimizer
endif
ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	CONFIGURE_FLAGS += --enable-presenter-console
endif
ifeq "$(ENABLE_PDFIMPORT)" "y"
	CONFIGURE_FLAGS += --enable-pdfimport
	BUILD_DEPS += , libpoppler-dev (>= 0.8.0)
endif

ifeq "$(ENABLE_GRAPHITE)" "y"
  ifeq "$(USE_SYSTEM_GRAPHITE)" "y"
	BUILD_DEPS += , libgraphite-dev [$(OOO_ARCHS)]
	CONFIGURE_FLAGS += --with-system-graphite
    ifeq "$(USE_STLPORT)" "y"
	ADDITIONAL_SECTIONS += SystemGraphiteWithSTLport
    endif
  endif
else
	CONFIGURE_FLAGS += --disable-graphite
endif

ifeq "$(USE_LIBCURL4)" "y"
	BUILD_DEPS += , libcurl4-$(CURL_SECTYPE)-dev
else
	BUILD_DEPS += , libcurl3-$(CURL_SECTYPE)-dev
endif

ifeq "$(SYSTEM_OPENSSL)" "y"
	BUILD_DEPS += , libssl-dev
	CONFIGURE_FLAGS += --with-system-openssl
	DBG_DBG_SUGGESTS += , libssl$(shell readlink /usr/lib/libssl.so | cut -d"." -f3,4,5)-dbg
endif

	BUILD_DEPS += , libdb-dev
	DBG_DBG_SUGGESTS += , $(shell apt-cache show libdb-dev | grep Depends | awk '{ print $$2 }' | sed -e s/dev/dbg/)

ifneq "$(BUILD_DBG_PACKAGE)" "y"
	# build with small symbols anyway
	SMALL_SYMBOLS = y
else
  # -g gives a far too big deb (>400M, ca. 1GB I-S)
  ifeq (debug,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	# ooo-build defaults to --enable-symbols (without SMALL)
	SMALL_SYMBOLS = n
  else
	SMALL_SYMBOLS = y
  endif
	DBG_DBG_SUGGESTS+= , libc6.1-dbg [alpha ia64], libc0.1-dbg [kfreebsd-i386 kfreebsd-amd64], libc0.3-dbg [hurd-i386], libc6-dbg [!ia64 !alpha !kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libatk1.0-dbg, libglib2.0-0-dbg, libgnomevfs2-0-dbg, libstdc++6-$(shell g++ --version | head -n 1 | cut -d' ' -f3 | cut -d'.' -f1,2)-dbg, libx11-6-dbg, libxext6-dbg, libxaw7-dbg, libxml2-dbg, libgtk2.0-0-dbg, libxau6-dbg, libice6-dbg, libsm6-dbg, libxinerama1-dbg, libfontconfig1-dbg
  ifeq "$(USE_LIBCURL4)" "y"
	DBG_DBG_SUGGESTS+= , libcurl3-dbg
  else
	DBG_DBG_SUGGESTS+= , libcurl4-dbg
  endif
endif
# Small symbols?
ifeq "$(SMALL_SYMBOLS)" "y"
	CONFIGURE_FLAGS += --enable-symbols=SMALL
endif

ifeq (noopt,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	ARCH_FLAGS += -O0
endif

# Workaround for LP: #555977
ifneq (,$(filter $(ARCH), arm armel))
	ARCH_FLAGS += -marm
endif

ifeq "$(BUILD_PYUNO)" "y"
  ifeq "$(USE_PYCENTRAL)" "y"
	BUILD_DEPS += , python-central (>= 0.5)
  endif
  ifeq "$(USE_PYSUPPORT)" "y"
    ifeq "$(PYMAJOR).$(PYMINOR)" "2.6"
	BUILD_DEPS += , python-support (>= 0.90.4)
    else
	BUILD_DEPS += , python-support
    endif
  endif
	DBG_DBG_SUGGESTS+= , python-dbg
	BUILD_DEPS += , python-dev, python-all
else
	BUILD_DEPS += , python
endif

	BUILD_DEPS += , debhelper (>= 7.2.3~)

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
    ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	STAMP_NATIVE_JARS = $(STAMP_DIR)/native-jars
    endif
    ifeq "$(NEW_DPKG_SHLIBDEPS)" "n"
	BUILD_DEPS += , dpkg-dev (>= 1.13.19)
    endif
	JAVA_GCJ_DEPENDS = libgcj-common (>= 1:4.1.1-14)
  endif
endif

	CONFIGURE_FLAGS += --disable-qadevooo

ifeq "$(RUN_SMOKETEST)" "y"
	BUILD_DEPS += , xvfb, xbase-clients, xfonts-base
endif
ifeq "$(RUN_API_TESTS)" "y"
	BUILD_DEPS += , tcsh
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')
	HELPISOS=$(shell echo "$(DEB_BUILD_OPTIONS) " | sed -n 's/^.*lang=\([^\s].*\)\s.*/\1/p' | awk '{ print $$1 }' | sed -e 's/,/ /g')
	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 $(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -i all')
	ISOS:=en-US af ar as ast be-BY bg bn br bs ca cs cy da de dz el \
	  en-GB en-ZA eo es et eu fa fi fr ga gl gu he hi-IN hr hu id it ja \
	  ka km ko ku lt lv mk mn ml mr nb ne nl nn nr ns 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
	#HELPISOS:=$(shell $(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -i all') 
	HELPISOS:=en-US ca cs da de dz el en-GB es et eu fi fr gl hi-IN hu it \
	  ja km ko nl om pl pt pt-BR ru sl sv zh-CN zh-TW
	#LANGPACKISOS:=$(shell $(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -i all')
	LANGPACKISOS:=en-US af ar as ast be-BY bg bn br bs ca cs cy da de dz el \
	  en-GB en-ZA eo es et eu fa fi fr ga gl gu he hi-IN hr hu id it ja \
	  ka km ko ku lt lv mk mn ml mr nb ne nl nn nr ns 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 "$(DIST)" "Ubuntu"
	# additional things built in Ubuntu, having belocs-locales
	ISOS := en-US $(sort $(filter-out en-US, $(ISOS)) kn)
	HELPISOS := en-US $(sort $(filter-out en-US, $(HELPISOS)) br)
	LANGPACKISOS := en-US $(sort $(filter-out en-US, $(LANGPACKISOS)) kn)
	REMOVE_HELP := bs cy lt lv sh-YU sr-CS
	FILTER_HELP := ga hr pl rw sk th tr vi
    endif
  endif
else
	ISOS=en-US
	HELPISOS=en-US
	LANGPACKISOS=en-US
endif
BUILD_ISOS = $(ISOS)

ifeq "$(DIST)" "Ubuntu"
	LANGUAGES := $(ISOS)
  ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"
	BUILD_ONLY_EN_US=y
	ISOS := en-US
	LANGPACKISOS := $(ISOS)
	HELPISOS := 
	OOO_L10N_DIR = $(CURDIR)/debian/l10n
# Disable for now
#    ifeq (,$(findstring nogsi, $(DEB_BUILD_OPTIONS)))
#	GSI_EXPORT_STAMP = $(STAMP_DIR)/gsi-export
#    endif
    # don't merge and extract for normal ppa builds, use something else if needed for ppa uploads
    ifneq (,$(findstring ppa, $(SOURCE_VERSION)))
	GSI_EXPORT_STAMP =
    endif
  endif
  ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	DEBHELPER_OPTIONS += $(foreach p, $(shell echo $(PACKAGES) | egrep -v l10n) openoffice.org$(VER)-l10n-en-us,-N$(p))
  endif
endif

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

ifeq "$(USE_COMMON_DOCDIR)" "y"
	HELP_PACKAGES = $(filter-out %-common, $(filter openoffice.org$(VER)-help-%, $(PACKAGES)))
	LANG_PACKAGES = $(filter-out %-common, $(filter openoffice.org$(VER)-l10n-%, $(PACKAGES)))
endif

ifeq "$(VER)" ""
	CONFIGURE_FLAGS += --with-binsuffix=no
else
	CONFIGURE_FLAGS += --with-binsuffix=$(VER)
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(JDK)" "default"
	JAVA_HOME=/usr/lib/jvm/default-java
	BUILD_DEPS += , default-jdk-builddep [$(OOO_JAVA_ARCHS)]
  endif
  ifeq "$(JDK)" "java-gcj-compat"
	JAVA_HOME=/usr/lib/jvm/java-gcj
    ifneq (,$(findstring armel,$(OOO_JAVA_ARCHS)))
	BUILD_DEPS += , gcj-4.3 (>= 4.3.1-2) [armel]
    endif
  endif
  ifeq "$(JDK)" "gcj-jdk"
	JAVA_HOME=/usr/lib/jvm/java-gcj
	BUILD_DEPS += , gcj-jdk [$(OOO_JAVA_ARCHS)]
  endif
  ifeq "$(JDK)" "openjdk"
	BUILD_DEPS += , openjdk-6-jdk [$(filter-out $(OOO_GCJ_JDK_ARCHS),$(OOO_JAVA_ARCHS))]
	JAVA_HOME=/usr/lib/jvm/java-6-openjdk
	CONFIGURE_FLAGS += --with-java-target-version=1.5
  endif
  ifeq "$(BUILD_JARS_NATIVE)" "y"
	CONFIGURE_FLAGS += --enable-gcjaot
    ifeq "$(LENNY_BACKPORT)" "y"
	BUILD_DEPS += , gij [$(OOO_GCJ_ARCHS)], java-gcj-compat-dev (>= 1.0.76-7) [$(OOO_GCJ_ARCHS)], libgcj-bc [$(OOO_GCJ_ARCHS)]
    else
 	BUILD_DEPS += , gcj-jdk [$(OOO_GCJ_ARCHS)], libgcj-common (>= 1:4.4.1) [$(OOO_GCJ_ARCHS)]
    endif
  else
    ifneq "$(OOO_GCJ_JDK_ARCHS)" ""
	BUILD_DEPS += , gcj-jdk [$(OOO_GCJ_JDK_ARCHS)]
    endif
  endif
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	BUILD_DEPS += , ant (>= 1.7.0) [$(OOO_JAVA_ARCHS)], ant-optional (>= 1.7.0) [$(OOO_JAVA_ARCHS)]
  else
	BUILD_DEPS += , ant (>= 1.6.5) [$(OOO_JAVA_ARCHS)]
  endif
	GCJ_VERSION = $(shell basename `readlink $(JAVA_HOME)/bin/gcj` | sed -e s/gcj-//)
	GCJ_JAWT_DEPENDS= $(shell dpkg -S /usr/lib/`readlink /usr/lib/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 | java-gcj-compat
#  ifneq (,$(GCJ_JAWT_DEPENDS))
#	JAVA_RUNTIME_DEPENDS += | $(GCJ_JAWT_DEPENDS)
#  endif
  ifneq (,$(filter $(ARCH), alpha amd64 i386 m68k mips mipsel powerpc s390 sparc))
	JAVA_RUNTIME_DEPENDS += | openjdk-6-jre
  endif
  ifneq (,$(filter $(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= , openoffice.org$(VER)-java-common
  ifeq "$(USE_SYSTEM_SAXON)" "y"
	CONFIGURE_FLAGS += --with-system-saxon --with-saxon-jar=/usr/share/java/saxonb.jar
	BUILD_DEPS += , libsaxonb-java [$(OOO_JAVA_ARCHS)]
	JAVA_COMMON_JAVA_DEPENDS+= , libsaxonb-java
  endif
  ifeq "$(PACKAGE_SDK)" "y"
    ifeq "$(DIST)" "Debian"
      ifeq "$(shell gcc --version | head -n 1 | awk '{print $$4}' | cut -d. -f1,2)" "4.4"
	BUILD_DEPS += , gcc-mingw32 [$(OOO_JAVA_ARCHS)], mingw32-runtime [$(OOO_JAVA_ARCHS)]
      else
        ifeq "$(GCC_VERSION)" "4.4"
          BUILD_DEPS += , gcc-mingw32 [$(OOO_JAVA_ARCHS)], mingw32-runtime [$(OOO_JAVA_ARCHS)]
        else
	  BUILD_DEPS += , mingw32 [$(OOO_JAVA_ARCHS)]
        endif
      endif
	  CONFIGURE_FLAGS += --with-mingwin=i586-mingw32msvc-g++
    endif
  endif
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	CONFIGURE_FLAGS += --enable-wiki-publisher
    ifeq "$(USE_SYSTEM_APACHE_COMMONS)" "y"
	MEDIAWIKI_BUILD_DEPS += , libcommons-codec-java [$(OOO_JAVA_ARCHS)], libcommons-httpclient-java [$(OOO_JAVA_ARCHS)], libcommons-lang-java [$(OOO_JAVA_ARCHS)], libcommons-logging-java [$(OOO_JAVA_ARCHS)]
	MEDIAWIKI_JAR_DEPENDS := $(MEDIAWIKI_BUILD_DEPS)
	BUILD_DEPS += $(MEDIAWIKI_BUILD_DEPS)
	CONFIGURE_FLAGS += --with-system-apache-commons --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
      ifeq "$(LENNY_BACKPORT)" "y"
	CONFIGURE_FLAGS += --with-system-servlet-api --with-servlet-api-jar=$(shell dpkg -L `apt-cache show libcommons-logging-java | grep Depends | cut -d"," -f2 | sed -e s/^\ //` | grep \.jar$$)
      else
	CONFIGURE_FLAGS += --with-system-servlet-api --with-servlet-api-jar=$(shell dpkg -L `apt-cache show libcommons-logging-java | grep Suggests | cut -d"," -f1 | sed -e s/^\ // | awk '{ print $$2 }'` | grep servlet-api.*\.jar$ | head -n 1)
 	BUILD_DEPS += , $(shell apt-cache show libcommons-logging-java | grep Suggests | cut -d"," -f1 | sed -e s/^\ // | awk '{ print $$2 }')
      endif
    endif
  endif
  ifeq "$(ENABLE_REPORTDESIGN)" "y"
	# report-builder
    ifeq "$(USE_SYSTEM_JFREEREPORT)" "y"
	REPORT_BUILDER_BUILD_DEPS += , libbase-java-openoffice.org [$(OOO_JAVA_ARCHS)], libsac-java [$(OOO_JAVA_ARCHS)], libxml-java-openoffice.org [$(OOO_JAVA_ARCHS)], libflute-java-openoffice.org [$(OOO_JAVA_ARCHS)], libpentaho-reporting-flow-engine-java-openoffice.org [$(OOO_JAVA_ARCHS)], liblayout-java-openoffice.org [$(OOO_JAVA_ARCHS)], libloader-java-openoffice.org [$(OOO_JAVA_ARCHS)], libformula-java-openoffice.org [$(OOO_JAVA_ARCHS)], librepository-java-openoffice.org [$(OOO_JAVA_ARCHS)], libfonts-java-openoffice.org [$(OOO_JAVA_ARCHS)], libserializer-java-openoffice.org [$(OOO_JAVA_ARCHS)]
	REPORT_BUILDER_JAR_DEPENDS := $(REPORT_BUILDER_BUILD_DEPS)
	BUILD_DEPS += $(REPORT_BUILDER_BUILD_DEPS)
	CONFIGURE_FLAGS += --with-system-jfreereport --with-libbase-jar=/usr/share/java/openoffice/libbase.jar --with-libxml-jar=/usr/share/java/openoffice/libxml.jar --with-flute-jar=/usr/share/java/openoffice/flute.jar --with-jfreereport-jar=/usr/share/java/openoffice/flow-engine.jar --with-liblayout-jar=/usr/share/java/openoffice/liblayout.jar --with-libloader-jar=/usr/share/java/openoffice/libloader.jar --with-libformula-jar=/usr/share/java/openoffice/libformula.jar --with-librepository-jar=/usr/share/java/openoffice/librepository.jar --with-libfonts-jar=/usr/share/java/openoffice/libfonts.jar --with-libserializer-jar=/usr/share/java/openoffice/libserializer.jar
    endif
    ifeq "$(USE_SYSTEM_APACHE_COMMONS)" "y"
	REPORT_BUILDER_BUILD_DEPS += , libcommons-logging-java [$(OOO_JAVA_ARCHS)]
	REPORT_BUILDER_JAR_DEPENDS += , libcommons-logging-java [$(OOO_JAVA_ARCHS)]
	CONFIGURE_FLAGS += --with-commons-logging-jar=/usr/share/java/commons-logging.jar
      ifeq "$(LENNY_BACKPORT)" "y"
	CONFIGURE_FLAGS += --with-system-servlet-api --with-servlet-api-jar=$(shell dpkg -L `apt-cache show libcommons-logging-java | grep Depends | cut -d"," -f2 | sed -e s/^\ //` | grep \.jar$$)
      else
	CONFIGURE_FLAGS += --with-system-servlet-api --with-servlet-api-jar=$(shell dpkg -L `apt-cache show libcommons-logging-java | grep Suggests | cut -d"," -f1 | sed -e s/^\ // | awk '{ print $$2 }'` | grep servlet-api.*\.jar$ | head -n 1)
 	BUILD_DEPS += , $(shell apt-cache show libcommons-logging-java | grep Suggests | cut -d"," -f1 | sed -e s/^\ // | awk '{ print $$2 }')
      endif
    endif
	CONFIGURE_FLAGS += --enable-report-builder
  endif
	OOO_OFFICEBEAN_DEP = openoffice.org$(VER)-officebean
else
	CONFIGURE_FLAGS += --without-java
	DEBHELPER_OPTIONS += -Nopenoffice.org$(VER)-officebean -Nopenoffice.org$(VER)-java-common -Nopenoffice.org$(VER)-filter-mobiledev -Nopenoffice.org$(VER)-gcj
endif

ifneq "$(MOZILLA)" ""
  ifneq "$(OOO_MOZILLA_ARCHS)" ""
    ifeq "$(MOZILLA)" "xulrunner"
	BUILD_DEPS+= , libxul-dev [$(OOO_MOZILLA_ARCHS)], libnss3-dev (>= 3.12.3) [$(OOO_MOZILLA_ARCHS)]
	DBG_DBG_SUGGESTS+= , libnss3-1d-dbg, libnspr4-0d-dbg
    else
      ifeq "$(MOZILLA)" "libxul"
	BUILD_DEPS+= , xulrunner-dev [$(OOO_MOZILLA_ARCHS)] | xulrunner-1.9-dev [$(OOO_MOZILLA_ARCHS)], libnss3-dev (>= 3.12.3) [$(OOO_MOZILLA_ARCHS)]
      else
        ifeq "$(MOZILLA)" "iceape"
	BUILD_DEPS += , $(MOZILLA)-dev (>= 1.1.9-5) [$(OOO_MOZILLA_ARCHS)], libnss3-dev (>= 3.12.3) [$(OOO_MOZILLA_ARCHS)]
        else
	BUILD_DEPS += , $(MOZILLA)-dev [$(OOO_MOZILLA_ARCHS)]
        endif
      endif
	DBG_DBG_SUGGESTS+= , libnss3-1d-dbg, libnspr4-0d-dbg
    endif
  endif
endif
ifneq (,$(findstring $(ARCH),$(OOO_MOZILLA_ARCHS)))
	CONFIGURE_FLAGS += --with-system-mozilla=$(MOZILLA)
else
	CONFIGURE_FLAGS += --disable-mozilla --without-system-mozilla
	PACKAGE_NPSOPLUGIN=n
endif

ifeq "$(USE_SYSTEM_DMAKE)" "y"
	BUILD_DEPS += , dmake (>= 1:4.11)
endif

ifneq "$(OOO_MONO_ARCHS)" ""
  ifeq "$(MONO2)" "y"
	BUILD_DEPS += , mono-devel $(MONO_MINVER) [$(OOO_MONO_ARCHS)], libmono-dev $(MONO_MINVER) [$(OOO_MONO_ARCHS)], mono-utils $(MONO_MINVER) [$(OOO_MONO_ARCHS)], cli-common-dev (>= 0.5.7) [$(OOO_MONO_ARCHS)]
  else
	# mono-gmcs for gmcs itself and mkbundle2
	# mono-mcs for mcs itself and al
	BUILD_DEPS += , mono-mcs $(MONO_MINVER) [$(OOO_MONO_ARCHS)], mono-gmcs $(MONO_MINVER) [$(OOO_MONO_ARCHS)], libmono-dev $(MONO_MINVER) [$(OOO_MONO_ARCHS)], mono-utils $(MONO_MINVER) [$(OOO_MONO_ARCHS)], cli-common-dev (>= 0.5.7) [$(OOO_MONO_ARCHS)], mono-1.0-devel [$(OOO_MONO_ARCHS)], mono-2.0-devel [$(OOO_MONO_ARCHS)]
  endif
endif
ifeq "$(ENABLE_MONO)" "y"
	# http://pkg-mono.alioth.debian.org/cli-policy/ch-mono.html#s7.3
	MONO_SHARED_DIR = $(CURDIR)
	export MONO_SHARED_DIR
	CONFIGURE_FLAGS+= --enable-mono
  ifeq "$(MONO2)" "y"
	CONFIGURE_FLAGS += MCS=/usr/bin/mono-csc GMCS=/usr/bin/mono-csc MKBUNDLE2=/usr/bin/mkbundle
  endif
	DBG_DBG_SUGGESTS += , mono-jit-dbg [$(OOO_MONO_ARCHS)], libmono0-dbg [$(OOO_MONO_ARCHS)], mono-dbg [$(OOO_MONO_ARCHS)]
else
	CONFIGURE_FLAGS+= --disable-mono
	DEBHELPER_OPTIONS += -Nlibuno-cli-basetypes1.0-cil -Nlibuno-cli-uretypes1.0-cil -Nlibuno-cli-oootypes1.0-cil -Nlibuno-cli-cppuhelper1.0-cil -Nlibuno-cli-ure1.0-cil
endif

ifeq "$(USE_SYSTEM_HUNSPELL)" "y"
	BUILD_DEPS += , libhunspell-dev $(HUNSPELL_MIN_VER)
	CONFIGURE_FLAGS+= --with-system-hunspell
endif
	CONFIGURE_FLAGS += --with-external-dict-dir=$(DICT_DIR)

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

ifeq "$(USE_AGG)" "y"
	CONFIGURE_FLAGS+= --with-agg
  ifeq "$(SYSTEM_AGG)" "y"
	BUILD_DEPS += , libagg-dev (>= 2.3-2)
	CONFIGURE_FLAGS += --with-system-agg
  endif
endif

ifneq "$(OOO_STLPORT_ARCHS)" ""
  ifeq "$(USE_SYSTEM_STLPORT)" "y"
	LIBSTLPORT_MINVER= (>= 4.6.2-3)
	BUILD_DEPS += , libstlport4.6-dev $(LIBSTLPORT_MINVER) [$(OOO_STLPORT_ARCHS)]
	DEV_STL_DEPENDS=, libstlport4.6-dev $(LIBSTLPORT_MINVER) [$(OOO_STLPORT_ARCHS)]
   endif
endif
ifneq "$(USE_STLPORT)" "y"
	CONFIGURE_FLAGS += --without-stlport
else
        CONFIGURE_FLAGS += --with-stlport
  ifeq "$(USE_SYSTEM_STLPORT)" "y"
	CONFIGURE_FLAGS+= --with-stlport=$(CURDIR)/stlport
  endif
endif

ifeq "$(USE_SYSTEM_BOOST)" "y"
  ifeq "$(BOOST_VERSION)" "1.34"
    ifeq "$(shell gcc --version | head -n 1 | cut -d' ' -f4 | cut -d. -f1,2)" "4.4"
	BUILD_DEPS += , libboost-dev (>= 1.34.1-15)
    else
	BUILD_DEPS += , libboost-dev
    endif
  else
    ifneq "$(BOOST_VERSION)" "default"
	BUILD_DEPS += , libboost$(BOOST_VERSION)-dev $(BOOST_MINVER)
    else
	BUILD_DEPS += , libboost-dev $(BOOST_MINVER)
    endif
  endif
	CONFIGURE_FLAGS += --with-system-boost
endif

ifeq "$(USE_SYSTEM_VIGRA)" "y"
	BUILD_DEPS += , libvigraimpex-dev
	CONFIGURE_FLAGS += --with-system-vigra
endif

ifeq "$(USE_EXTERNAL_CXXLIBS)" "y"
	BUILD_DEPS += , libwpd8-dev $(LIBWPD8_MINVER)
	CONFIGURE_FLAGS+=  --with-system-libwpd
  ifeq "$(USE_SYSTEM_SABLOT)" "y"
	BUILD_DEPS += , libsablot0-dev (>= 1.0.2-4)
	CONFIGURE_FLAGS += --with-system-sablot
  endif
  ifeq "$(USE_EXTERNAL_MYTHES)" "y"
	BUILD_DEPS += , libmythes-dev (>= 1:1.0-3)
	CONFIGURE_FLAGS += --with-system-mythes
	DEBHELPER_OPTIONS+= -Nlibmythes-dev
  endif
  ifeq "$(USE_SYSTEM_LIBWPS)" "y"
	BUILD_DEPS += , libwps-dev
	CONFIGURE_FLAGS += --with-system-libwps
  endif
  ifeq "$(USE_SYSTEM_LIBWPG)" "y"
	BUILD_DEPS += , libwpg-dev
	CONFIGURE_FLAGS += --with-system-libwpg
  endif
endif
	CONFIGURE_FLAGS += --with-external-thes-dir=$(THES_DIR)

ifeq "$(USE_SYSTEM_ICU)" "y"
	BUILD_DEPS += , libicu-dev $(ICU_MINVER)
	CONFIGURE_FLAGS += --with-system-icu
endif

ifeq "$(USE_LIBXSLT)" "y"
	CONFIGURE_FLAGS += --with-system-libxslt
	BUILD_DEPS += , libxslt1-dev
	DBG_DBG_SUGGESTS+= , libxslt1-dbg
endif

ifeq "$(USE_SYSTEM_XMLSEC)" "y"
  ifneq (,$(findstring xul,$(MOZILLA)))
	BUILD_DEPS += , libxmlsec1-dev (>= 1.2.9-1.1), libxmlsec1-nss (>= 1.2.9-1.1), libxmlsec1-openssl (>= 1.2.9-1.1)
  else
	BUILD_DEPS += , libxmlsec1-dev (>= 1.2.9), libxmlsec1-nss (>= 1.2.9), libxmlsec1-openssl (>= 1.2.9)
  endif
	CONFIGURE_FLAGS += --with-system-xmlsec
endif

ifeq "$(BUILD_CAIROCANVAS)" "y"
  ifeq "$(USE_SYSTEM_CAIRO)" "y"
	BUILD_DEPS+= , libcairo2-dev
	CONFIGURE_FLAGS+= --with-system-cairo
  endif
else
	CONFIGURE_FLAGS+= --disable-cairo
endif

ifeq "$(BUILD_KDE)" "n"
	CONFIGURE_FLAGS+= --disable-kde
	CONFIGURE_FLAGS-= --disable-kde4
	CONFIGURE_FLAGS+= --with-images="$(IMAGES)"
else
  ifeq "$(KDE_VER)" "4"
	CONFIGURE_FLAGS += --disable-kde
	KDE_ICONSET_DEP=openoffice.org$(VER)-style-oxygen
  else
	CONFIGURE_FLAGS += --disable-kde4
	KDE_ICONSET_DEP=openoffice.org$(VER)-style-crystal
  endif
	BUILD_DEPS += , kdelibs$(shell expr $(KDE_VER) + 1)-dev $(KDELIBS_MINVER)
  ifeq "$(KDE_VER)" "4"
	BUILD_DEPS += , libqt$(KDE_VER)-dev $(QT_MINVER)
	DBG_DBG_SUGGESTS+= , kdelibs$(shell expr $(KDE_VER) + 1)-dbg, libqt$(KDE_VER)-dbg
  else
	DBG_DBG_SUGGESTS+= , kdelibs-dbg, qt-x11-free-dbg
  endif
  ifeq "$(ENABLE_KDEAB)" "y"
    ifeq "$(KDE_VER)" "4"
	ADDITIONAL_SECTIONS += KDE4Experimental
	BUILD_DEPS += , kdepimlibs$(shell expr $(KDE_VER) + 1)-dev
    endif
  else
	CONFIGURE_FLAGS+= --disable-kdeab
	DEBHELPER_OPTIONS += -Nopenoffice.org$(VER)-kab
  endif
endif

ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	CONFIGURE_FLAGS += --enable-mysql-connector
  ifeq "$(USE_SYSTEM_MYSQLCLIENT)" "y"
	CONFIGURE_FLAGS += --with-system-mysql
	BUILD_DEPS += , libmysqlclient-dev
  endif
  ifeq "$(USE_SYSTEM_MYSQLCPPCONN)" "y"
	CONFIGURE_FLAGS += --with-system-mysql-cppconn
	BUILD_DEPS += , libmysqlcppconn-dev $(MYSQLCPPCONN_MINVER) [$(OOO_ARCHS)]
    ifeq "$(USE_STLPORT)" "y"
	ADDITIONAL_SECTIONS += SystemMySQLWithSTLport
    endif
  endif
endif

ifeq "$(BUILD_GTK)" "n"
	CONFIGURE_FLAGS+= --disable-gtk
	DEBHELPER_OPTIONS+= -Nopenoffice.org$(VER)-gtk -Nopenoffice.org$(VER)-gnome
	CONFIGURE_FLAGS+= --with-images="$(IMAGES)"
endif

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

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

ifneq "$(ENABLE_LAYOUT)" "y"
	CONFIGURE_FLAGS += --disable-layout
endif

ifeq "$(BUILD_BINFILTERS)" "y"
	CONFIGURE_FLAGS+= --enable-binfilter
	OOO_BINFILTER_DEP = openoffice.org$(VER)-filter-binfilter
else
	DEBHELPER_OPTIONS+= -Nopenoffice.org$(VER)-filter-binfilter
endif

ifneq "$(BUILD_PYUNO)" "y"
	DEBHELPER_OPTIONS+= -Npython-uno
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(USE_SYSTEM_LUCENE)" "y"
	BUILD_DEPS += , liblucene2-java (>= 2.3.2) [$(OOO_JAVA_ARCHS)]
	LUCENE_DEPENDS = liblucene2-java (>= 2.3.2)
        # safety measure; e.g. lucene 2.9 index cannot be handled by lucene 2.4
        LUCENE_CONFLICTS = liblucene2-java (<< $(shell dpkg -l liblucene2-java | grep ^ii | awk '{ print $$3 }' | cut -d. -f1,2)~)
	CONFIGURE_FLAGS += --with-system-lucene --with-lucene-core-jar=/usr/share/java/lucene-core.jar --with-lucene-analyzers-jar=/usr/share/java/lucene-analyzers.jar
  endif
  ifeq "$(USE_SYSTEM_HSQLDB)" "y"
	BUILD_DEPS += , libhsqldb-java $(HSQLDB_MINVER) [$(OOO_JAVA_ARCHS)]
	BASE_HSQLDB_DEPENDS = libhsqldb-java $(HSQLDB_MINVER)
	CONFIGURE_FLAGS+= --with-system-hsqldb
	JAVA_GCJ_DEPENDS += , libhsqldb-java-gcj
  endif
  ifeq "$(USE_SYSTEM_BSH)" "y"
	BUILD_DEPS += , bsh (>= 2.0b4) [$(OOO_JAVA_ARCHS)]
	COMMON_BSH_DEPENDS = bsh (>= 2.0b4)
	CONFIGURE_FLAGS+= --with-system-beanshell
	JAVA_GCJ_DEPENDS += , bsh-gcj
  endif
endif

ifeq "$(USE_SYSTEM_LPSOLVE)" "y"
  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
	CONFIGURE_FLAGS += --with-system-lpsolve
  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.60)
	CONFIGURE_FLAGS += --enable-dbus
endif

ifeq "$(USE_GSTREAMER)" "y"
	BUILD_DEPS += , libgstreamer-plugins-base0.10-dev
	GSTREAMER_PLUGINS_SUGGESTS += , gstreamer0.10-plugins-base, gstreamer0.10-plugins-good, gstreamer0.10-plugins-ugly, gstreamer0.10-plugins-bad, gstreamer0.10-ffmpeg
	DBG_DBG_SUGGESTS+= , libgstreamer0.10-0-dbg
else
	CONFIGURE_FLAGS += --disable-gstreamer
endif

ifeq "$(USE_SYSTEM_NEON)" "y"
  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
	CONFIGURE_FLAGS += --with-system-neon
endif

ifeq "$(USE_SYSTEM_REDLAND)" "y"
	BUILD_DEPS += , librdf0-dev (>= 1.0.8)
	CONFIGURE_FLAGS += --with-system-redland
	SHLIBS_OVERRIDE += -Xunordf
endif

# CairoFonts patchset is applied for sid and this patch needs Gtk 2.10
ifneq "$(CAIRO_FONTS_PATCH)" "y"
	BUILD_DEPS += , libgtk2.0-dev
else
	BUILD_DEPS += , libgtk2.0-dev (>= 2.10)
  # cairo canvas might be disabled, but the patch needs cairo headers
  ifneq "$(BUILD_CAIROCANVAS)" "y"
	BUILD_DEPS += , libcairo2-dev
	CONFIGURE_FLAGS += --with-system-cairo
  endif
endif

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

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

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

# Use compiler cache?  Include ccache in DEB_BUILD_OPTIONS for much faster rebuild times
# A complete build uses about 200Mb of compiler cache.
ifeq (ccache,$(findstring ccache,$(DEB_BUILD_OPTIONS)))
	CONFIGURE_FLAGS += --with-gcc-speedup=ccache
endif

# Build n projects in parallel?
# DEB_BUILD_OPTIONS=parallel=<n>
NUM_CPUS=$(shell echo "$(DEB_BUILD_OPTIONS)," | sed -n 's/^\(.*\s\)\?parallel=\([0-9]\+\).*/\2/p')
AVAIL_CPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
ifeq "$(NUM_CPUS)" ""
	NUM_CPUS := 1
  ifeq "$(PARALLEL_BUILD)" "y"
	# according to Pavel Janik, build -P<number of cores> -- -P2
	# is ideal. This sets the first -P according to the number
	# of CPUs (where dual-core CPUS report 2, too)
    ifneq ($(AVAIL_CPUS),1)
	NUM_CPUS := $(shell expr $(AVAIL_CPUS))
    endif
  endif
endif
	CONFIGURE_FLAGS += --with-num-cpus=$(NUM_CPUS)
	# breaks. At least with 2
#	CONFIGURE_FLAGS += --with-max-jobs=$(NUM_CPUS)

CURDIR ?= $(shell pwd)

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
	BUILD_DEPS += , gcc-$(GCC_VERSION), g++-$(GCC_VERSION)
  endif
endif
BUILD_PATH := $(CURDIR)/debian/usr/bin:$(BUILD_PATH)
BUILD_LD_LIBRARY_PATH := $(BUILD_LD_LIBRARY_PATH):$(GCJ_JAWT_DIR)

ifeq "$(ENABLE_LDAP)" "y"
  ifeq "$(USE_OPENLDAP)" "y"
    BUILD_DEPS += , libldap2-dev
    LDAP_LIB := $(shell echo libldap-`grep LDAP_VENDOR_VERSION_M /usr/include/ldap_features.h | cut -d: -f2 | awk '{ print $$3 }' | xargs | sed -e "s/ /\./"`-`grep LDAP_VENDOR_VERSION_MAJOR /usr/include/ldap_features.h | cut -d: -f2 | awk '{ print $$3 }'`)
   else
     CONFIGURE_FLAGS += --without-openldap
   endif
else
  CONFIGURE_FLAGS += --disable-ldap
endif

# 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=files.backup icons.scale patch.apply build.prepare.artwork 
stampdir_targets+=build.prepare configure
stampdir_targets+=setupins setup install install-arch install-indep
stampdir_targets+=langpacks binary-common 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
	rm -f debian/*.postinst debian/*.postrm debian/*.preinst debian/*.prerm
	rm -f $(STAMP_DIR)/setup
ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	rm -rf debian/ttf-opensymbol \
	       debian/openoffice.org$(VER)-common \
	       debian/openoffice.org$(VER)-dev-doc \
	       debian/openoffice.org$(VER)-java-common \
	       debian/openoffice.org$(VER)-l10n-en-us
endif
	dh_clean

# Clean compilation results, but leave solver (about 600Mb in addition to instsetoo)
clean-objectdirs: clean-instsetoo
	dh_testdir
	find $(SOURCE_TREE) -maxdepth 2 -name $(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT) -type d -exec rm -rf {} \;

ifeq "$(DEBSRC_VERSION)" "1.0"
include /usr/share/quilt/quilt.make
endif

ifeq "$(DEBSRC_VERSION)" "1.0"
clean: unpatch
else
clean:
endif
	dh_testroot
	dh_testdir

	# openoffice.applications and openoffice*.keys are not removed via make distclean
	# although they are generated files. Work around this.
	# FIXME: Fix the makefiles in ooo-build directly
	if [ -e $(OOO_BUILD_TREE)/desktop/openoffice.applications ]; then \
		$(MAKE) -C $(OOO_BUILD_TREE)//desktop clean || true;\
	fi
	if [ -r $(OOO_BUILD_TREE)/Makefile ]; then \
	  $(MAKE) -C $(OOO_BUILD_TREE) distclean || true ;\
	fi

ifeq "$(PRUNE_OOOBUILD)" "y"
	# prune upstream ooo-build files
	set -e; \
	cd $(OOO_BUILD_TREE) ;\
	rm -rf \
	 2005-10-23-huston.ppt \
	 doc/class_diagram.odg \
	 scratch/offapi-vba/constants/constant_types.rdb \
	 src/*.ico \
	 src/*.jpg \
	 src/*.xcf \
	 src/*_nld.* \
	 src/Draft.jpg \
	 src/file-bug*.png \
	 src/open*.png \
	 src/open{intro,about}*.bmp \
	 src/eval/open{intro,about}*.bmp \
	 src/easter/*.png \
	 src/sg3.* \
	 patches/test/*.tar \
	 www/images/*.png \
	 www/l10n/*.gif
	 if [ -d $(OOO_BUILD_TREE)/test ]; then \
		find $(OOO_BUILD_TREE)/test $(OOO_BUILD_TREE)/doc $(OOO_BUILD_TREE)/scratch -type f \
			\( -name '*.123' -o -name '*.doc' -o -name '*.lwp' \
			-o -name '*.odp' -o -name "*.ods" -o -name '*.odt' \
			-o -name '*.png' -o -name '*.ppt' -o -name '*.sx?' \
			-o -name '*.wb2' -o -name '*.WB2' -o -name '*.xls' \
			-o -name '*.XLS' -o -name '*.xlsx' -o -name '*.xls.gz' \
			-o -name '*.xls.bz2' \) \
			-exec rm {} \; ;\
	 fi
	 find $(OOO_BUILD_TREE)/scratch $(OOO_BUILD_TREE)/src -type f \
		\( -name '*.odg' -o -name '*.ods' -o -name '*.ott' \) \
		-exec rm {} \;
endif

	# remove file with space in the name
	rm -f $(OOO_BUILD_TREE)/test/macro/clock\ chart.xls

	rm -rf $(OOO_BUILD_TREE)/autom4ate.cache
	rm -rf $(OOO_BUILD_TREE)/build
	rm -rf $(OOO_BUILD_TREE)/desktop/*.desktop
	rm -f $(OOO_BUILD_TREE)/fonts/symbols.xls
	rm -f $(OOO_BUILD_TREE)/po/.intltool-merge-cache
	rm -f $(OOO_BUILD_TREE)/src/GSI*.sdf

	# remove generated symlinks / java wrappers
	rm -rf debian/usr

	# stlport home
	rm -rf $(CURDIR)/stlport
	# convenience link
	rm -f build

	rm -f $(OOO_BUILD_TREE)/src/GSI*err
	rm -f $(OOO_BUILD_TREE)/config.*

ifneq "$(OOO_L10N_DIR)" ""
	rm -rf $(OOO_L10N_DIR)
endif

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	rm -rf debian/ttf-opensymbol \
	       debian/openoffice.org$(VER)-common \
	       debian/openoffice.org$(VER)-dev-doc \
	       debian/openoffice.org$(VER)-java-common \
	       debian/openoffice.org$(VER)-l10n-en-us
endif

ifeq "$(DEBSRC_VERSION)" "1.0"
	# uuencode upstream ooo-build binary files
	set -e; \
	cd $(OOO_BUILD_TREE) ; \
	 for f in \
	   *.png \
	   desktop/*/*.png \
	   doc/*.odg \
	   doc/*.ods \
	   doc/*.sxw \
	   patches/test/*.tar \
	   scratch/ocrimport/*.png \
	   scratch/ocrimport/bitmaps/*.png \
	   scratch/offapi-vba/constants/*.rdb \
	   scratch/rcsutil/*.ods \
	   scratch/sc-vba/testvba/TestDocuments/*.ods \
	   scratch/sc-vba/testvba/TestDocuments/*.xls \
	   scratch/sc-vba/testvba/TestDocuments/notwork/*.ods \
	   scratch/sc-vba/testvba/TestDocuments/notwork/*.xls \
	   scratch/sc-vba/TestDocuments/*.xls \
	   scratch/sw-vba/TestDocuments/*.doc \
	   src/*.bmp \
	   src/*.ico \
	   src/*.jpg \
	   src/*.odb \
	   src/*.png \
	   src/*.sdg \
	   src/*.sdv \
	   src/*.thm \
	   src/acor_ru-RU.dat \
	   src/acor_sk-SK.dat \
	   src/easter/*.png \
	   src/eval/*.bmp \
	   src/icons/*.png \
	   src/icons/tango/*.png \
	   src/layout/*.png \
	   src/layout/default_images/res/commandimagelist/*.png \
	   src/layout/ooo_custom_images/industrial/res/commandimagelist/*.png \
	   src/layout/ooo_custom_images/tango/res/commandimagelist/*.png \
	   src/icons/*.png \
	   src/icons/tango/*.png \
	   templates/*.ott \
	   test/Lwp/*.lwp \
	   test/Lwp/*.png \
	   test/calc/*.ods \
	   test/calc/*.xls \
	   test/draw/*.odp \
	   test/draw/*.ppt \
	   test/draw/*.sxd \
	   test/excel/*.xls \
	   test/excel/*.xlsx \
	   test/excel/*.xls.gz \
	   test/excel/*.xls.bz2 \
	   test/excel/perf/*.xls.bz2 \
	   test/lotus/*.123 \
	   test/macro/*.doc \
	   test/macro/*.ods \
	   test/macro/*.xls \
	   test/macro/ConvertTests/*.xls \
	   test/macro/vba_donated_docs/*.XLS \
	   test/macro/vba_donated_docs/*.xls \
	   test/qpro/*.png \
	   test/qpro/*.WB2 \
	   test/qpro/*.wb2 \
	   test/qpro/*.xls \
	   test/writer/*.odt \
	   test/writer/*.sxw \
	   desktop/mimetypes/16x16/*.png \
	   desktop/mimetypes/22x22/*.png \
	   desktop/mimetypes/24x24/*.png \
	   desktop/mimetypes/32x32/*.png \
	   desktop/mimetypes/48x48/*.png \
	   www/images/*.png \
	   www/l10n/*.gif \
	   doc/class_diagram.odg \
	   extensions/coooder/icons/image1_16.bmp \
	   extensions/coooder/icons/image1_16h.bmp \
	   extensions/coooder/icons/image1_26.bmp \
	   extensions/coooder/icons/image1_26h.bmp \
	   src/default_images/svx/res/doc_modified_no_14.png \
	   src/default_images/svx/res/doc_modified_yes_14.png \
	   src/default_images/sc/res/popup_select_current.png \
	   src/default_images/sc/res/popup_unselect_current.png \
	   ; do \
	  if [ -s $$f ]; then \
	   uuencode $$f $$f > $$f.uu.tmp && \
	   ../debian/scripts/move-if-change $$f.uu.tmp $$f.uu; \
	   touch -r $$f $$f.uu ; \
	   rm -f $$f ; \
	  fi ; \
	 done

	# uuencode add-on ooo-build binary files
	set -e; \
	cd $(OOO_BUILD_TREE) ; \
	 for f in \
	   src/*.bz2 \
	   src/*.dll \
	   src/*.gz \
	   src/*.zip \
	   ; do \
	  if [ -s $$f ]; then \
	   case "$$f" in src/$(TAG)*) continue ; esac ; \
	   case "$$f" in src/OOo*_src*) continue ; esac; \
	   uuencode $$f $$f > $$f.uu.tmp && \
	   ../debian/scripts/move-if-change $$f.uu.tmp $$f.uu; \
	   touch -r $$f $$f.uu ; \
	   rm -f $$f ; \
	  fi ; \
	 done
	
	set -e; \
	for i in `cat debian/source/components | grep -v ^$(OOO_BUILD_TREE)` ; do \
	cd $$i && \
	 for f in \
	   *.bz2 \
	   *.gz \
	   *.zip \
	   ; do \
	  if [ -s $$f ]; then \
	   uuencode $$f $$f > $$f.uu.tmp && \
	   ../debian/scripts/move-if-change $$f.uu.tmp $$f.uu; \
	   touch -r $$f $$f.uu ; \
	   rm -f $$f ; \
	  fi ; done; \
	 cd ..; \
	 done

ifeq "$(DIST)" "Ubuntu"
	# uuencode ubuntu binary files
	set -e; \
	cd debian/ubuntu ; \
	 for f in \
	   *.bmp \
	   *.bz2 \
	   *.otp \
	   *.pdf \
	   ; do \
	  if [ -s $$f ]; then \
	   uuencode $$f $$f > $$f.uu.tmp && \
	   ../scripts/move-if-change $$f.uu.tmp $$f.uu; \
	   touch -r $$f $$f.uu ; \
	   rm -f $$f ; \
	  fi ; \
	 done
endif
endif
	dh_clean

	# Files created in debian directory
	rm -f debian/*.postinst debian/*.postrm debian/*.preinst debian/*.prerm
	if [ -d "$(STAMP_DIR)" ]; then rm -rf "$(STAMP_DIR)"; fi
	rm -f debian/shlibs.override.stdlibs
	rm -f debian/*.bug-script
	rm -f debian/scripts/aotcompile.py*

ifeq "$(ENABLE_MONO)" "y"
	rm -rf $(MONO_SHARED_DIR)/.wapi
endif

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

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

	rm -f debian/openoffice.org-dev-doc.doc-base.*
	rm -f debian/*.menu
	for i in base calc core common draw impress math writer; do \
		rm -f debian/openoffice.org-$$i.lintian-overrides; \
	done
	rm -f debian/*.install debian/*.dirs
	rm -f debian/openoffice.org-dtd-officedocument1.0.xmlcatalogs
	rm -f download.list

ifeq "$(WITH_SPLIT)" "y"
	rm -f $(OOO_BUILD_TREE)/src/$(TAG)*
else
	rm -f $(OOO_BUILD_TREE)/src/OOo*_src*
endif
	rm -f $(OOO_BUILD_TREE)/src/GSI*

	for i in ext-sources-$(OOO_BUILD_TREE)/*; do \
		rm -f $(OOO_BUILD_TREE)/src/`basename $$i`; \
	done

	for i in `find $(OOO_BUILD_TREE)/patches/dev300 -name "*.in" ! -name "Makefile*"`; do \
		if [ -e `echo $$i | sed -e s/\.in$$//` ]; then \
			rm `echo $$i | sed -e s/\.in$$//`; \
		fi; \
	done
	rm -f $(OOO_BUILD_TREE)/bin/setup
	rm -f $(OOO_BUILD_TREE)/bin/piece/sys-setup
	rm -f $(OOO_BUILD_TREE)/download
	rm -f $(OOO_BUILD_TREE)/distro-configs/*.conf
	rm -f $(OOO_BUILD_TREE)/patches/apply.pl

ifeq "$(DEBSRC_VERSION)" "1.0"
	# default is 3.0 (quilt), so revert to 1.0 for lenny
	echo "1.0" > debian/source/format
endif

	$(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) $(OOO_BUILD_TREE)/bin/openoffice-xlate-lang  debian/rules
	chmod 755 $(OOO_BUILD_TREE)/bin/openoffice-xlate-lang
	sed -e "s#openoffice.orgVER#openoffice.org$(VER)#g" \
	    -e "s#broffice.orgVER#broffice.org$(VER)#g" \
	    -e "s#%$(DIST)=\([^%]*\)%#, \1#g#" \
	    -e "s#%[A-Za-z]*=[^%]*%##g#" \
	    -e "s#%BUILD_DEPS%#$(strip $(BUILD_DEPS))#g" \
	    < debian/control.in > debian/control

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	awk '{print} /^ *$$/ {exit}' debian/control > debian/control.l10n
	sed 's/Build-Depends:/Build-Depends-Indep:/' debian/control.l10n > debian/control
	rm -f debian/control.l10n

	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
	       >> debian/control < debian/control.l10n.in
endif

	for LNUM in $(filter-out en-US,$(LANGPACKISOS)) ; do \
	    [ "$$LNUM" = en-US -a "$(PKGSOURCE)" = "openoffice.org$(VER)-l10n" ] && continue; \
	    LNAME=`$(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -l $$LNUM | perl -e 'print ucfirst(<STDIN>);'`; \
	    LCODE=`$(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -i $$LNUM | tr A-Z a-z`; \
	    CCODE=`echo $$LCODE | sed 's/-.*//'`; \
	    case "$$LCODE" in \
		bn|gu|pa-in|ml|or|te|ta) \
			FONT_SUGGESTS=", ttf-`echo $$LNAME | tr A-Z a-z`-fonts"; \
			;; \
		hi-in|ne|mr) \
			FONT_SUGGESTS=", ttf-devanagari-fonts"; \
			;; \
		he) \
			FONT_SUGGESTS=", culmus"; \
			;; \
		km) \
			FONT_SUGGESTS=", ttf-khmeros"; \
			;; \
		ar) \
			FONT_SUGGESTS=", ttf-arabeyes"; \
			;; \
		fa) \
			FONT_SUGGESTS=", ttf-farsiweb"; \
			;; \
		dz) \
			FONT_SUGGESTS=", ttf-dzongkha"; \
			;; \
		th) \
			FONT_SUGGESTS=", ttf-thai-tlwg"; \
			;; \
		*) \
			FONT_SUGGESTS= ;; \
	    esac; \
	    case "$$LCODE" in \
		rw) \
			LOCALES_DEPENDS="locales (>= 2.3.6) | belocs-locales-data | locales-all (>= 2.3.6)" \
			;; \
		ss|ts|km|ns|tn) \
			LOCALES_DEPENDS="locales (>= 2.3.5-12) | belocs-locales-data | locales-all" \
			;; \
		sr) \
			LOCALES_DEPENDS="locales (>= 2.3.6.ds1-5) |  belocs-locales-data | locales-all" \
			;; \
		as|or|nr) \
			LOCALES_DEPENDS="locales (>= 2.3.6.ds1-1) | locales-all (>= 2.3.6.ds1-1)" \
			;; \
		*) \
			LOCALES_DEPENDS="locales | belocs-locales-data | locales-all" \
			;; \
	    esac; \
	    L10N_COMMON=; \
	    if [ "$(USE_COMMON_DOCDIR)" = y ]; then \
	        case "$$LCODE" in \
	            en-us) ;; \
	            *) L10N_COMMON='openoffice.orgVER-l10n-common (>= $${base-version}), '; \
	        esac; \
	        LOCALES_DEPENDS="openoffice.org$(VER)-common (>= \$${base-version}) | language-support-translations-$$CCODE, openoffice.org$(VER)-common (<< \$${base-version}.1) | language-support-translations-$$CCODE"; \
	    fi; \
	    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:@L10N_COMMON@:$$L10N_COMMON:g" \
			-e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		-e "s|@LDAP_LIB@|$(LDAP_LIB)|g" \
	        >> debian/control < debian/control.lang.in; \
	done

ifneq "$(HELPISOS)" ""
	for LNUM in $(HELPISOS) ; do \
	    LNAME=`$(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -l $$LNUM | perl -e 'print ucfirst(<STDIN>);'`; \
	    LCODE=`$(OOO_BUILD_TREE)/bin/openoffice-xlate-lang -i $$LNUM | tr A-Z a-z`; \
	    CCODE=`echo $$LCODE | sed 's/-.*//'`; \
	    sed -e "s|@LNAME@|$$LNAME|g" -e "s|@LCODE@|$$LCODE|g" \
		-e "s|@CCODE@|$$CCODE|g" \
			-e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
	        >> debian/control < debian/control.help.in; \
	done
	# en_US is in -common
	perl -pi -e 's|(Depends: openoffice.org$(VER)-writer \| language-support-translations-en), openoffice.org$(VER)-l10n-en-us|\1|' \
		debian/control
	perl -pi -e 's|(Depends: openoffice.org$(VER)-writer, openoffice.org$(VER)-l10n-en-us)|\1, ttf-devanagari-fonts|' \
		debian/control
endif

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"

	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.ure.in
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.gcj.in
  endif
endif
ifneq "$(OOO_MONO_ARCHS)" ""
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.mono.in
endif
ifneq "$(OOO_NPSOPLUGIN_ARCHS)" ""
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.mozilla.in
endif
ifneq "$(OOO_OGLTRANS_ARCHS)" ""
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.ogltrans.in
endif
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(ENABLE_MEDIAWIKI)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.mediawiki.in
  endif
  ifeq "$(ENABLE_REPORTDESIGN)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.reportdesign.in
  endif
endif
ifeq "$(ENABLE_MINIMIZER)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.minimizer.in
endif
ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.presenter.in
endif
ifeq "$(ENABLE_PDFIMPORT)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.pdfimport.in
endif
ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.fonts.in
endif
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.debug.in
endif
ifeq "$(PACKAGE_SDK)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.sdk.in
endif
ifeq "$(BUILD_KDE)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.kde.in
	  perl -pi -e 's/ openoffice.org$(VER)-gnome,/ openoffice.org-gnome | openoffice.org$(VER)-kde,/' debian/control
endif
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.postgresql.in
ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.mysql.in
endif
endif
ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	sed -e "s|openoffice.orgVER|openoffice.org$(VER)|g" \
		>> debian/control < debian/control.lenny_squeeze_transitional.in
	for o in as-IN gu-IN ml-IN mr-IN or-IN ta-IN te-IN; do \
		n=`echo $$o | cut -d- -f1`; \
		os=`echo $$o | tr A-Z a-z`; \
		perl -pi -e 's/\n/, openoffice.org-l10n-$${os}\n/ if /^Replaces:.*l10n-$${n}$$/' debian/control; \
	done
endif

	perl -pi -e "s,%OOO_ARCHS%,$(OOO_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_MONO_ARCHS%,$(OOO_MONO_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_NPSOPLUGIN_ARCHS%,$(OOO_NPSOPLUGIN_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_OGLTRANS_ARCHS%,$(OOO_OGLTRANS_ARCHS),g" debian/control
	perl -pi -e "s,%OOO_BINFILTER_ARCHS%,$(OOO_BINFILTER_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

ifeq (he,$(findstring he,$(LANGPACKISOS)))
	perl -pi -e 's/openoffice.org-help-he$$/openoffice.org-help-he, openoffice.org-ctl-he/' debian/control
endif

	perl -pi -e 's/Package: openoffice.org$(VER)-help-en-us/Package: openoffice.org$(VER)-help-en-us\nReplaces: openoffice.org$(VER)-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

ifneq "$(LENNY_BACKPORT)" "y"	
	perl -pi -e "s/(Build-Conflicts: .*)/\1, base-files (= 5)/" debian/control
endif

ifneq "$(USE_SYSTEM_STLPORT)" "y"
	# at least here it crashes the build in some funny way.
	perl -pi -e "s/(Build-Conflicts: .*)/\1, libstlport4.6-dev/" debian/control
endif

ifeq (4.4,$(shell LANG="C" gcc --version | head -n 1 | awk '{ print $$4 }'))
	perl -pi -e 's/flex \|/flex (>= 2.5.25-7) |/' debian/control
endif

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

ifeq "$(VER)" ""
	# no conflict with Suns packages as they have the version in their
	# names thankfully now
	perl -pi -e 's/openoffice.org-unbundled, //' debian/control
endif

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

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

ifeq "$(ENABLE_LDAP)" "y"
	perl -pi -e 's/paperconf$$/paperconf\n  * $(LDAP_LIB): LDAP client library; needed for OOo getting its profiles\n    from LDAP/' debian/control
endif

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

.DELETE_ON_ERROR: debian/control

pre-build:
# used for test builds
#ifneq (,$(filter $(ARCH), i386 arm armel))
#	@echo Build ...
#else
#	@echo Explicitely fail the build on architecture $(ARCH)
#	false
#endif

build: pre-build build-arch build-indep
build-arch: $(STAMP_DIR)/build
build-indep: $(STAMP_DIR)/build

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

configure: $(OOO_BUILD_TREE)/config.status
ifeq "$(DEBSRC_VERSION)" "1.0"
$(OOO_BUILD_TREE)/config.status: $(QUILT_STAMPFN) $(OOO_BUILD_TREE)/configure
else
$(OOO_BUILD_TREE)/config.status: $(OOO_BUILD_TREE)/configure
endif
	dh_testdir

	# Make sure needed scripts are executable
	set -e;\
	for FILE in debian/scripts/move-if-change \
		    debian/scripts/cleandupes \
		    debian/scripts/fix_image_rgb \
		    debian/scripts/get_libebook_dep.sh \
		    $(OOO_BUILD_TREE)/configure \
		    $(OOO_BUILD_TREE)/bin/[a-z]* \
		    $(OOO_BUILD_TREE)/bin/piece/[a-z]* ;\
	do \
	  chmod 755 $$FILE ;\
	done

	mkdir -p $(STAMP_DIR)

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
  ifeq "$(DIST)" "Ubuntu"
	cp -p $(OOO_BUILD_TREE)/distro-configs/$(PATCHSET).conf.in $(OOO_BUILD_TREE)/distro-configs/UbuntuL10n.conf.in
  endif
endif

ifneq "$(DEBSRC_VERSION)" "3.0"
	# uudecode files, omit GSI files
	set -e; \
	for uu in \
	  `find . -name *.uu` \
	  ; do \
	 case "$$uu" in $(OOO_BUILD_TREE)/src/GSI*) continue ; esac ; \
	 orig="`echo "$$uu" |sed -e 's#.uu$$##'`" ;\
	 if [ ! -s $$orig ]; then \
	  uudecode -o $$orig $$uu ; \
	  touch -r $$uu $$orig ; \
	 fi ; \
	done
endif

	cp -a ext-sources-$(OOO_BUILD_TREE)/* $(OOO_BUILD_TREE)/src
	cp -a ooo-build/src/* $(OOO_BUILD_TREE)/src

ifneq ($(GCC_VERSION),)
  ifneq ($(GCC_VERSION),snapshot)
	# create links for gcc and g++ (and gij and gcj), ooo-build does not
	# honour overriding CC and CXX and we need to use gcc/g++ 4.0 or /
	# ant.mk wants gcj at the moment...
	mkdir -p $(CURDIR)/debian/usr/bin
	ln -sf /usr/bin/$(CC_PREFIX)gcc-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/gcc
	ln -sf /usr/bin/$(CC_PREFIX)g++-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/g++
	ln -sf /usr/bin/$(CC_PREFIX)gcc-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/$(CC_PREFIX)gcc
	ln -sf /usr/bin/$(CC_PREFIX)g++-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/$(CC_PREFIX)g++
	#ln -sf /usr/bin/$(CC_PREFIX)gcj-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/gcj
	#ln -sf /usr/bin/gij-$(GCC_VERSION) $(CURDIR)/debian/usr/bin/gij
  else
    ifneq "$(CC_PREFIX)" ""
	mkdir -p $(CURDIR)/debian/usr/bin
	ln -sf /usr/lib/gcc-snapshot/bin/$(CC_PREFIX)gcc $(CURDIR)/debian/usr/bin/gcc
	ln -sf /usr/lib/gcc-snapshot/bin/$(CC_PREFIX)g++ $(CURDIR)/debian/usr/bin/g++
	ln -sf /usr/lib/gcc-snapshot/bin/$(CC_PREFIX)gcj $(CURDIR)/debian/usr/bin/gcj
	ln -sf /usr/lib/gcc-snapshot/bin/$(CC_PREFIX)gij $(CURDIR)/debian/usr/bin/gij
    endif
  endif
endif

ifeq "$(BUILD_KDE)" "y"
	# be sure we use the right moc, it's an alternative and can point
	# to either Qt3 or Qt4s moc.
	mkdir -p $(CURDIR)/debian/usr/bin
	ln -sf /usr/bin/moc-qt$(KDE_VER) $(CURDIR)/debian/usr/bin/moc
endif

ifeq "$(USE_STLPORT)" "y"
  ifeq "$(USE_SYSTEM_STLPORT)" "y"
	# stlport home
	if [ ! -d stlport ]; then \
		mkdir -p stlport; \
		ln -sf /usr/include/stlport stlport/stlport; \
		ln -sf /usr/lib stlport/lib; \
	fi
  endif
endif

ifneq "$(BUILD_ONLY_EN_US)" "y"
  ifneq "$(LANGPACKISOS)" "en-US"
	# copy and extract extra GSIs 
	cp translation-updates-*/* $(OOO_BUILD_TREE)/src
	find $(OOO_BUILD_TREE)/src -name "*.sdf.bz2" -exec bunzip2 -k \{\} \;
	for i in `find $(OOO_BUILD_TREE)/src/*.sdf.gz`; do gunzip -dc "$$i" > \
		$(OOO_BUILD_TREE)/src/`basename $$i .gz`; done
	# work around broken stuff in the GSI breaking the build in svx
	for iso in lv sh-YU sr-CS; do \
	  case " $(LANGPACKISOS) " in *\ $$iso\ *) ;; *) continue; esac; \
	  [ -f $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf ] || continue; \
	  TMP=`mktemp -q`; \
	  grep -v OOO_LICENSE $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf \
	    > $$TMP && mv $$TMP $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf; \
	done
	# we change the message, and those translations therefore don't match anymore.
	for iso in $(LANGPACKISOS); do \
	  [ -f $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf ] || continue; \
	  if [ "$$iso" = "ku" ]; then continue; fi; \
	  TMP=`mktemp -q`; \
	  grep -v RID_STR_EXTENSION_NOT_PRESENT $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf \
	    > $$TMP && mv $$TMP $(OOO_BUILD_TREE)/src/GSI_$$iso.sdf; \
	done
    ifeq (he,$(findstring he,$(LANGPACKISOS)))
	# TKOS_BUILD_DATE is bogus, too
	if [ -f $(OOO_BUILD_TREE)/src/GSI_he.sdf ]; then \
	 TMP=`mktemp -q`; \
	 sed -e "s/TKOS_BUILD_DATE//g" < $(OOO_BUILD_TREE)/src/GSI_he.sdf \
	   > $$TMP && mv $$TMP $(OOO_BUILD_TREE)/src/GSI_he.sdf ; \
	fi
    endif
    ifeq (da,$(findstring da,$(LANGPACKISOS)))
	if [ -f $(OOO_BUILD_TREE)/src/GSI_da.sdf ]; then \
	  perl -pi -e 's/\s\(.*på engelsk\)//' $(OOO_BUILD_TREE)/src/GSI_da.sdf; \
	fi
    endif
  endif
endif

	# Make convenience link
	if [ ! -L build ]; then ln -s $(SOURCE_TREE) build ; fi

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

	# hrmpf. Empty in ooo-build and patch does not give them to us but
	# configure need them. Create them...
	touch $(OOO_BUILD_TREE)/distro-configs/Win32.conf.in
	touch $(OOO_BUILD_TREE)/distro-configs/Solaris.conf.in

	cd $(OOO_BUILD_TREE) ; \
		PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) ../$(OOO_BUILD_TREE)/configure $(CONFIGURE_FLAGS)

	touch $@

build: $(STAMP_DIR)/build
$(STAMP_DIR)/build: $(OOO_BUILD_TREE)/config.status
	dh_testdir

ifeq "$(BUILD_KDE)" "n"
	# hack to tell we want crystal icons nevertheless and they should be
	# extracted...
	if ! grep -q crystal $(OOO_BUILD_TREE)/bin/setup; then \
		cp $(OOO_BUILD_TREE)/bin/setup $(OOO_BUILD_TREE)/bin/setup.bak && \
		cat $(OOO_BUILD_TREE)/bin/setup.bak \
			| sed -e s/\'industrial/\'industrial\ crystal/ \
			> $(OOO_BUILD_TREE)/bin/setup && rm $(OOO_BUILD_TREE)/bin/setup.bak; \
	fi
endif

ifeq (buildd,$(shell whoami))
	cd $(OOO_BUILD_TREE) ; PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) DEFAULT_TO_ENGLISH_FOR_PACKING=1 ARCH_FLAGS=$(ARCH_FLAGS) TMP=/tmp $(MAKE)
else
	cd $(OOO_BUILD_TREE) ; PATH=$(BUILD_PATH) LD_LIBRARY_PATH=$(BUILD_LD_LIBRARY_PATH) DEFAULT_TO_ENGLISH_FOR_PACKING=1 VERBOSE=true ARCH_FLAGS=$(ARCH_FLAGS) TMP=/tmp $(MAKE)
endif

	# apparently setting this here globally doesn't work, so hack around.
	# If we don't do this we get loads of harmless, but log-bloating
	# warnings
	if ! grep fakeroot $(SOURCE_TREE)/*.sh; then \
		perl -pi -e 's,LD_LIBRARY_PATH=\"(.*)\",LD_LIBRARY_PATH=\"/usr/lib/libfakeroot:\1\",' $(SOURCE_TREE)/*.sh; \
	fi

	# DPKG is only set on with-EPM build what we don't do and the menu stuff
	# is only built wenn DPKG is set.. Same with PKGFORMAT.
	cd $(SOURCE_TREE)/sysui; \
		. $(CURDIR)/$(SOURCE_TREE)/*.sh; \
		PATH=$(BUILD_PATH) DPKG="dpkg" PKGFORMAT="deb" NO_PKG_MANGLE=go-away \
		../solenv/bin/build.pl && ../solenv/bin/deliver.pl

ifneq "$(USE_EXTERNAL_MYTHES)" "y"
	# build non-PIC version of libmythes
	cd $(SOURCE_TREE)/lingucomponent/source/thesaurus/mythes && \
		$(CXX) -O2 -Wall -ansi -pedantic -I. -I../../../inc/pch \
			-c mythes.cxx && \
		ar rc libmythes_nopic.a mythes.o && ranlib libmythes_nopic.a && \
		mv libmythes_nopic.a $(CURDIR)/$(SOURCE_TREE)
endif

	touch $@

test: $(STAMP_DIR)/test
$(STAMP_DIR)/test: $(STAMP_DIR)/build
ifneq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
ifeq "$(RUN_UNIT_TESTS)" "y"
	# build/run unit tests
	-cd $(SOURCE_TREE)/instsetoo_native; \
		. $(CURDIR)/$(SOURCE_TREE)/*.sh; \
		PATH=$(BUILD_PATH) DPKG="dpkg" PKGFORMAT="deb" NO_PKG_MANGLE=go-away \
		../solenv/bin/build.pl --ignore --all check
endif
ifeq "$(RUN_SMOKETEST)" "y"
	# smoketest
	cd $(SOURCE_TREE)/smoketestoo_native && \
		. $(CURDIR)/$(SOURCE_TREE)/*.sh; \
		export PATH=$(BUILD_PATH); \
		if [ -n "$$DISPLAY" ]; then \
			../solenv/bin/build.pl; \
		else \
			xvfb-run -a ../solenv/bin/build.pl; \
		fi
endif
ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(RUN_API_TESTS)" "y"
	# API tests
	cd $(SOURCE_TREE) && \
		export PATH=$(BUILD_PATH); \
		. $(CURDIR)/$(SOURCE_TREE)/*.sh; \
		solenv/bin/cwscheckapi -o -a
  endif
endif
endif

	touch $@

install: $(STAMP_DIR)/install
$(STAMP_DIR)/install: $(STAMP_DIR)/build $(STAMP_DIR)/test
	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/OpenOffice

	# install OpenOffice.org.
	cd $(OOO_BUILD_TREE)/; PATH=$(BUILD_PATH) \
		LD_LIBRARY_PATH="/usr/lib/libfakeroot:$(BUILD_LD_LIBRARY_PATH)" \
		 DESTDIR=$(CURDIR)/debian/tmp $(MAKE) install

	# 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" = "openoffice.org-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/openoffice.org-l10n-en-US.dirs >> debian/openoffice.org-common.dirs
	cat debian/openoffice.org-l10n-en-US.install >> debian/openoffice.org-common.install
	rm -f debian/openoffice.org-l10n-en-US.dirs debian/openoffice.org-l10n-en-US.install

	# 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/openoffice.org-l10n-$$iso.dirs -a \
			  -e debian/openoffice.org-l10n-$$iso.install ]; then \
				mv debian/openoffice.org-l10n-$$iso.dirs \
					debian/openoffice.org-l10n-$$pkgiso.dirs; \
				mv debian/openoffice.org-l10n-$$iso.install \
					debian/openoffice.org-l10n-$$pkgiso.install; \
			fi; \
			if [ -e debian/openoffice.org-help-$$iso.dirs -a \
			  -e debian/openoffice.org-help-$$iso.install ]; then \
				mv debian/openoffice.org-help-$$iso.dirs \
					debian/openoffice.org-help-$$pkgiso.dirs; \
				mv debian/openoffice.org-help-$$iso.install \
					debian/openoffice.org-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/openoffice.org$(VER)-common.install
	perl -pi -e 's,\./,,' debian/ure.install

ifneq "$(HELPISOS)" ""
	# 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`; then \
			pkgiso=`echo $$iso | tr A-Z a-z`; \
			rm -rf debian/tmp/pkg/openoffice.org-help-$$iso; \
			rm -f debian/openoffice.org-help-$$pkgiso.dirs; \
			rm -f debian/openoffice.org-help-$$pkgiso.install; \
		fi; \
	done
else ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"
	rm -rf debian/tmp/pkg/openoffice.org-help-en-US
endif

	install -m755 debian/ubuntu/ooo87965.execute.sh debian/tmp/pkg/openoffice.org-common/$(OODIR)/program

	# FIXME: Fix in ooo-build
	rm -rf debian/tmp/pkg/openoffice.org-qa-tools

	dh_installdirs -A
ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"
	dh_install -A --sourcedir=debian/tmp/pkg --fail-missing
else
	dh_install -A --sourcedir=debian/tmp/pkg
endif
	rm -rf debian/tmp/pkg

	# 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

	# add registered-components dir
	mkdir -p $(PKGDIR)-core/$(OOBASISDIR)/registered-components

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"
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/java move here already
	mkdir -p $(PKGDIR)-core/usr/share/java/$(OODIRNAME); \
	mv $(PKGDIR)-common/$(OODIR)/program/classes/officebean.jar \
		$(PKGDIR)-core/usr/share/java/$(OODIRNAME)

	# 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/usr/share/java/$(OODIRNAME); \
	mkdir -p $(PKGDIR)-base/$(OODIR)/program/classes; \
	mv $(PKGDIR)-common/$(OODIR)/program/classes/sdbc_hsqldb.jar \
		$(PKGDIR)-base/usr/share/java/$(OODIRNAME); \
	ln -s /usr/share/java/$(OODIRNAME)/sdbc_hsqldb.jar \
		$(PKGDIR)-base/$(OODIR)/program/classes/sdbc_hsqldb.jar

  ifneq "$(USE_SYSTEM_HSQLDB)" "y"
	# 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
endif

ifeq "$(ENABLE_MONO)" "y"
	mkdir -p $(PKGDIR)-core/$(OOBRANDDIR)/ure/lib; \
	mv $(PKGDIR)-common/$(OOBRANDDIR)/ure/lib/cli_uno_bridge.dll*  \
		$(PKGDIR)-core/$(OOBRANDDIR)/ure/lib
	for i in `dh_listpackages | grep libuno-cli`; do \
		if echo "$$i" | grep -q oootypes; then p=openoffice.org-common; d=$(OODIR)/program; \
		else p=ure; d=$(OOBRANDDIR)/ure/lib; fi; \
		rm -rf debian/$$i && mkdir -p -m755 debian/$$i/usr/lib/cli/uno-`echo $$i | perl -pi -e 's/.*(\d.\d).*/$$1/'`; \
		mv debian/$$p/$$d/`echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.dll \
			debian/$$i/usr/lib/cli/uno-`echo $$i | perl -pi -e 's/.*(\d.\d).*/$$1/'`; \
		mv debian/$$p/$$d/`echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.config \
			debian/$$i/usr/lib/cli/uno-`echo $$i | perl -pi -e 's/.*(\d.\d).*/$$1/'`/`echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.dll.config; \
	ln -s `echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.dll.config \
			debian/$$i/usr/lib/cli/uno-`echo $$i | perl -pi -e 's/.*(\d.\d).*/$$1/'`/`echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.config; \
		mv debian/$$p/$$d/policy.*.`echo $$i | sed -e "s/libuno-//" | sed -e "s/-cil$$//" | sed -e "s/-/_/" | perl -pi -e 's/\d.\d//'`.dll \
			debian/$$i/usr/lib/cli/uno-`echo $$i | perl -pi -e 's/.*(\d.\d).*/$$1/'`; \
	done
endif

	# remove eventually sneaked in .testtoolrc
	rm -f $(PKGDIR)-common/$(OODIR)/program/.testtoolrc

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

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

ifeq "$(PACKAGE_SDK)" "y"
	# move SDK documentation into own package
	rm -rf $(PKGDIR)-dev-doc
	mkdir -p $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev-doc
	mv $(PKGDIR)-dev/usr/share/doc/openoffice.org \
		$(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev && \
	mv $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/sdk/docs \
		$(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev
	mkdir -p $(PKGDIR)-dev-doc/$(OOSDKDIR)
	mv $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/sdk/index.html \
		$(PKGDIR)-dev-doc/$(OOSDKDIR)
	rm -f $(PKGDIR)-dev/$(OOSDKDIR)/index.html
	rm -rf $(PKGDIR)-dev/usr/share/doc/openoffice.org \
		$(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/sdk
	mv $(PKGDIR)-dev/$(OOSDKDIR)/examples \
		$(PKGDIR)-dev-doc/$(OOSDKDIR)
endif

	# fixup ure-link symlink. The move is done in install-arch
	# but the link is in -common so we need to do it here.
	cd $(PKGDIR)-common/$(OOBASISDIR) && \
		rm ure-link && ln -sf /$(OOUREDIR) ure-link

ifeq "$(ENABLE_GIO)" "y"
	# the config for gio should be  there where gio itself is, shouldn't it?
	mkdir -p $(PKGDIR)-gnome/$(OOBASISDIR)/share/registry/modules/org/openoffice/ucb/Configuration
	mv $(PKGDIR)-common/$(OOBASISDIR)/share/registry/modules/org/openoffice/ucb/Configuration/Configuration-gio.xcu \
		$(PKGDIR)-gnome/$(OOBASISDIR)/share/registry/modules/org/openoffice/ucb/Configuration
endif
endif # ifeq "$(PKGSOURCE)" "openoffice.org$(VER)"

	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/scripts/vars.$(ARCH) debian/control
	dh_testdir

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

	# generate .link files from *.in	
	for PKG in $(PACKAGES); do \
	  LINKS=debian/$$PKG.links ; \
	  if [ -e $$LINKS.in ]; then \
	    sed -e "s/\@LIBSUFFIX\@/$(LIBSUFFIX)/g" $$LINKS.in > $$LINKS ; \
	  fi; \
	done

	# generate maintainer scripts from *.in
	for PKG in $(PACKAGES); do \
	  if [ "$(DIST)" = Ubuntu ]; then \
	    case $$PKG in *l10n-*|*help-*) continue; esac; \
	  fi; \
	  for FILE in postinst postrm preinst prerm; 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 echo $(ARCH_DEP_PACKAGES) | grep -q $$PKG; then \
	        grep LIBSUFFIX debian/scripts/vars.$(ARCH) >> $$MAINTSCRIPT; \
	        grep PLATFORMID debian/scripts/vars.$(ARCH) >> $$MAINTSCRIPT; \
 	      fi; \
	      echo "" >> $$MAINTSCRIPT; \
	      if grep -q conffile $$MAINTSCRIPT.in; then \
		 cat debian/shell-lib-conffiles.sh >> $$MAINTSCRIPT; \
	      elif egrep -q "(add|remove)_extension" $$MAINTSCRIPT.in; then \
		 echo ". /usr/share/debconf/confmodule" >> $$MAINTSCRIPT; \
		 echo "" >> $$MAINTSCRIPT; \
		 cat debian/shell-lib-extensions.sh >> $$MAINTSCRIPT; \
	      elif grep -q services_rdb $$MAINTSCRIPT.in; then \
		 echo ". /usr/share/debconf/confmodule" >> $$MAINTSCRIPT; \
		 echo "" >> $$MAINTSCRIPT; \
		 cat debian/shell-lib-components.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; \
	      perl -pi -e "s,\@OOBRANDDIR\@,$(OOBRANDDIR),g" $$MAINTSCRIPT; \
	      perl -pi -e "s,\@OOBASISDIR\@,$(OOBASISDIR),g" $$MAINTSCRIPT; \
	      perl -pi -e "s/\@VER\@/$(VER)/g" $$MAINTSCRIPT; \
	    fi; \
	  done; \
	done

	touch $@

# Install files generated by setup into package directories
langpacks: $(STAMP_DIR)/langpacks
$(STAMP_DIR)/langpacks: $(STAMP_DIR)/install $(STAMP_DIR)/install-indep $(OOO_BUILD_TREE)/bin/openoffice-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

	# replace duplicate files in the langpacks with symlinks
	fdupes --quiet --recurse --sameline --size \
		debian/openoffice.org$(VER)-common/$(OODIR) \
		$(foreach d,$(shell echo $(filter-out en-US,$(LANGPACKISOS)) | tr A-Z a-z),debian/openoffice.org$(VER)-l10n-$(d)/$(OODIR)) \
		> l10n.fdupes
	debian/scripts/cleandupes --base=openoffice.org$(VER) --prefix=debian < l10n.fdupes

ifeq "$(DIST)" "Ubuntu"
	# install Ubuntu templates
	otps=`cd debian/ubuntu; echo *.otp`; \
	for iso in $(LANGPACKISOS); do \
	  [ "$$iso" = "en-US" ] && continue; \
	  pkgiso=`echo $$iso | tr \[:upper:\] \[:lower:\]`; \
	  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

	touch $@

native-jars: $(STAMP_NATIVE_JARS)
$(STAMP_NATIVE_JARS): $(STAMP_DIR)/install
	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/usr/share/java/$(OODIRNAME)/*.jar \
	        debian/tmp/native-jars/
	cp -a \
	    $(PKGDIR)-base/usr/share/java/$(OODIRNAME)/*.jar \
	        debian/tmp/native-jars/
	: # remove problematic ones
	rm -f debian/tmp/native-jars/ridl.jar
ifneq "$(USE_SYSTEM_SAXON)" "y"
	rm -f debian/tmp/native-jars/saxon9.jar
endif
	: # 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 java-gcj-compat package so this
	# hack here is needed.
	if [ -e /usr/lib/gcc/aotcompile.py ]; then \
		aotcompile_py=/usr/lib/gcc/aotcompile.py; \
	elif [ -e /usr/share/pyshared/aotcompile.py ]; then \
		aotcompile_py=/usr/share/pyshared/aotcompile.py; \
	fi && \
	cp $$aotcompile_py debian/scripts
	cd debian/scripts && \
		patch -p0 < $(CURDIR)/debian/aotcompile-256M-default.diff
	PYTHONPATH="debian/scripts:$(shell python$$v -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())')" \
	AOT_MAKEFLAGS=-j$(NUM_CPUS) aot-compile -L /usr/lib/gcj/openoffice \
	    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
	touch $@

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

ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"

ifeq "$(ENABLE_EVO2)" "y"
	debian/ure/$(OOBRANDDIR)/ure/bin/regcomp -revoke \
		-r $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-br $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-c 'vnd.sun.star.expand:$$OOO_BASE_DIR/program/libevoab$(LIBSUFFIX).so'
endif
ifeq "$(ENABLE_KDEAB)" "y"
	debian/ure/$(OOBRANDDIR)/ure/bin/regcomp -revoke \
		-r $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-br $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-c 'vnd.sun.star.expand:$$OOO_BASE_DIR/program/libkab1.so'
endif
ifeq "$(BUILD_BINFILTERS)" "y"
	debian/ure/$(OOBRANDDIR)/ure/bin/regcomp -revoke \
		-r $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-br $(PKGDIR)-core/$(OODIR)/program/services.rdb \
		-c 'vnd.sun.star.expand:$$OOO_BASE_DIR/program/libbf_migratefilter$(LIBSUFFIX).so'
endif

	# move the URE to /usr/lib/ure
	mv debian/ure/$(OOBRANDDIR)/ure debian/ure/usr/lib
	rmdir debian/ure/$(OOBRANDDIR)
	# move URE Java stuff to /usr/share/java
	mkdir -p debian/ure/usr/share/java/$(OODIRNAME)
ifeq "$(ENABLE_JAVA)" "y"
	mv debian/ure/$(OOUREDIR)/lib/JREProperties.class \
		debian/ure/usr/share/java/$(OODIRNAME)
	mv debian/ure/$(OOUREDIR)/share/java/* \
		debian/ure/usr/share/java/$(OODIRNAME)
	ln -sf /usr/share/java/$(OODIRNAME)/JREProperties.class \
		debian/ure/$(OOUREDIR)/lib/JREProperties.class
	cd debian/ure/$(OOUREDIR)/share/java && \
		for i in $(CURDIR)/debian/ure/usr/share/java/$(OODIRNAME)/*.jar; do \
			ln -sf `echo $$i | sed -e 's,$(CURDIR)/debian/ure,,'` `basename $$i`; \
		done
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

ifeq "$(BUILD_KDE)" "y"
	mkdir -p -m755 $(PKGDIR)-kde/$(OODIR)/program
	mkdir -p -m755 $(PKGDIR)-kde/$(OOBRANDDIR)/program
	for f in fps_kde*.uno.so libvclplug_kde*.so; do \
	  mv $(PKGDIR)-core/$(OODIR)/program/$$f $(PKGDIR)-kde/$(OODIR)/program || exit 1 ;\
	done
  ifeq "$(KDE_VER)" "3"
	mv $(PKGDIR)-core/$(OOBRANDDIR)/program/kdefilepicker \
		$(PKGDIR)-kde/$(OOBRANDDIR)/program
  endif

	# 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/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/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/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/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
ifeq "$(ENABLE_KDEAB)" "y"
	rm -rf $(PKGDIR)-kab
	mkdir -p -m755 $(PKGDIR)-kab/$(OODIR)/program
	for f in libkab*so; do \
	  mv $(PKGDIR)-core/$(OODIR)/program/$$f $(PKGDIR)-kab/$(OODIR)/program || exit 1 ;\
	done
endif

	# move the GNOME stuff which are *not* in gid_Module_Optional_Gnome
	# (which is moved into -gnome in package-ooo) into -gnome
	mkdir -p -m755 $(PKGDIR)-gnome/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/gnome-open-url.bin $(PKGDIR)-gnome/$(OODIR)/program || exit 1
ifeq "$(BUILD_GTK)" "y"
	for f in fps_gnome.uno.so libvclplug_gtk*.so; do \
	  mv $(PKGDIR)-core/$(OODIR)/program/$$f $(PKGDIR)-gnome/$(OODIR)/program || exit 1;\
	done
	for f in libeggtray* libqstart_gtk*; do \
	  mv $(PKGDIR)-core/$(OODIR)/program/$$f $(PKGDIR)-gnome/$(OODIR)/program || exit 1;\
	done
endif

	# split out gtk stuff
	rm -rf $(PKGDIR)-gtk
	mkdir -p -m755 $(PKGDIR)-gtk/$(OODIR)/program
	mv $(PKGDIR)-gnome/$(OODIR)/program/* $(PKGDIR)-gtk/$(OODIR)/program/
	mkdir -p -m755 $(PKGDIR)-gtk/$(OOBRANDDIR)/share
ifeq "$(BUILD_GTK)" "y"
	mv $(PKGDIR)-gnome/$(OOBRANDDIR)/share/xdg $(PKGDIR)-gtk/$(OOBRANDDIR)/share && \
		rmdir $(PKGDIR)-gnome/$(OOBRANDDIR)/share
  # Hmm. Weird. The location of confbe changes on whether GIO is enabled
  # or not...
  ifeq "$(ENABLE_GIO)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/ucpgio1.uno.so \
		$(PKGDIR)-gnome/$(OODIR)/program/
    ifeq "$(ENABLE_GCONF)" "y"
	mv $(PKGDIR)-core/$(OODIR)/program/gconfbe* \
		$(PKGDIR)-gnome/$(OODIR)/program
    endif
  endif
  ifeq "$(ENABLE_GVFS)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/ucpgvfs1.uno.so \
		$(PKGDIR)-gnome/$(OODIR)/program/
    ifeq "$(ENABLE_GCONF)" "y"
	mv $(PKGDIR)-gtk/$(OODIR)/program/gconfbe* \
		$(PKGDIR)-gnome/$(OODIR)/program
    endif
  endif
endif

# we dirst need to find out whether it works on lenny, see issue 105172
ifneq "$(LENNY_BACKPORT)" "y"
	install -D -m644 debian/Recovery.xcu \
		$(PKGDIR)-gnome/$(OODIR)/share/registry/data/org/openoffice/Office/Recovery.xcu
endif

ifeq "$(ENABLE_EVO2)" "y"
	mkdir -p -m755 $(PKGDIR)-evolution/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/libevoab*.so $(PKGDIR)-evolution/$(OODIR)/program
endif

ifeq "$(PACKAGE_NPSOPLUGIN)" "y"
	# libnpsoplugins.so two times with different sizes? Oh my.
	# Upstream has it this way, too, but..
	mkdir -p -m755 debian/mozilla-openoffice.org$(VER)/$(OODIR)/program
	mkdir -p -m755 debian/mozilla-openoffice.org$(VER)/$(OOBRANDDIR)/program
	for f in libnpsoplugin.so nsplugin; do \
		mv $(PKGDIR)-core/$(OODIR)/program/$$f debian/mozilla-openoffice.org$(VER)/$(OODIR)/program; \
	done
	mv $(PKGDIR)-core/$(OOBRANDDIR)/program/libnpsoplugin.so debian/mozilla-openoffice.org$(VER)/$(OOBRANDDIR)/program
	cd debian/mozilla-openoffice.org$(VER) && \
		mkdir -p usr/lib/mozilla/plugins && \
			ln -sf /$(OOBRANDDIR)/program/libnpsoplugin.so \
			   usr/lib/mozilla/plugins/libnpsoplugin.so
else
	rm -f $(PKGDIR)-core/$(OODIR)/program/libnpsoplugin.so
	rm -f $(PKGDIR)-core/$(OODIR)/program/nsplugin
endif

	# OOo's package split sucks...
	mv $(PKGDIR)-core/$(OODIR)/program/libsw* \
		$(PKGDIR)-writer/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/libsd$(LIBSUFFIX)* \
	   $(PKGDIR)-core/$(OODIR)/program/libsdd* \
	   $(PKGDIR)-core/$(OODIR)/program/libsdui* \
	   $(PKGDIR)-core/$(OODIR)/program/libsdfilt* \
		$(PKGDIR)-draw/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/slideshow.uno.so \
		$(PKGDIR)-impress/$(OODIR)/program
	mkdir -p -m755 $(PKGDIR)-base/$(OODIR)/program
	mv $(PKGDIR)-core/$(OODIR)/program/libdba* \
		$(PKGDIR)-base/$(OODIR)/program
	# except for libdba680l?.so itself
	rm -rf $(PKGDIR)-base-core
	mkdir -p $(PKGDIR)-base-core/$(OODIR)/program
	mv $(PKGDIR)-base/$(OODIR)/program/libdba$(LIBSUFFIX).so \
		 $(PKGDIR)-base-core/$(OODIR)/program
	for i in odbcbase dbpool2 odbc sdbc2 mysql adabas; do \
		mv $(PKGDIR)-core/$(OODIR)/program/lib$$i* \
		   $(PKGDIR)-base/$(OODIR)/program; \
	done
ifeq "$(ENABLE_JAVA)" "y"
	for i in jdbc hsqldb; do \
		mv $(PKGDIR)-core/$(OODIR)/program/lib$$i* \
		   $(PKGDIR)-base/$(OODIR)/program; \
	done
endif
	mv $(PKGDIR)-core/$(OODIR)/program/libflat*so \
		$(PKGDIR)-base/$(OODIR)/program
	# http://www.openoffice.org/issues/show_bug.cgi?id=107779
	mv $(PKGDIR)-calc/$(OODIR)/program/libcalc*so \
		$(PKGDIR)-base/$(OODIR)/program; \

	# move vba stuff into -calc, they are calc-only and linked to
	# libsc*
	for i in libvbaobj vbaevents; do \
		mv $(PKGDIR)-core/$(OODIR)/program/$$i*uno.so \
			$(PKGDIR)-calc/$(OODIR)/program; \
	done

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(USE_SYSTEM_HSQLDB)" "y"
	# link to system hsqldb
	mkdir -p $(PKGDIR)-base/$(OODIR)/program/classes
	ln -sf /usr/share/java/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/usr/share/java
	mv $(PKGDIR)-core/usr/share/java/$(OODIRNAME) \
		$(PKGDIR)-officebean/usr/share/java
	ln -s /usr/share/java/$(OODIRNAME)/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

ifeq "$(USE_OOO_BUILD_DESKTOPS)" "n"
	# menu files from sysui
	dirname="`cd $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/desktopshare >/dev/null; pwd`" ;\
	for p in writer calc impress draw math base; do \
		mkdir -p -m755 $(PKGDIR)-$$p/usr/share/applications ;\
		sed -e 's,Exec=$${UNIXPRODUCTNAME}$${PRODUCTVERSION} \(.*\) %U,Exec=ooffice$(VER) \1 %F,' \
		    -e 's,Icon=$${WITHOUTDOTUNIXPRODUCTNAME}[0123456789]\+,Icon=ooo,' \
		    -e 's,Name=$${PRODUCTNAME} $${PRODUCTVERSION},Name=OpenOffice.org $(VER),' \
		    -e 's/  / /' \
		   < $$dirname/$$p.desktop \
		   > $(PKGDIR)-$$p/usr/share/applications/openoffice.org$(VER)-$$p.desktop || exit 1 ;\
	done

ifeq "$(BUILD_GTK)" "y"
	# qstart.desktop is different to the above. Should be handled by
	# --with-unix-wrapper of ooo-build but that somehow doesn't work as
	# expected. FIXME.
	PRODUCTVERSION=`grep PRODUCTVERSION $(SOURCE_TREE)/sysui/desktop/productversion.mk | head -n 1 | cut -d"=" -f2 | sed -e s/\ //g`; \
	sed -i -e "s,Exec=openoffice.org$$PRODUCTVERSION,Exec=ooffice$(VER)," \
		-e "s,Name=OpenOffice.org $$PRODUCTVERSION,Name=OpenOffice.org $(VER)," \
		-e "s/  / /" \
		$(PKGDIR)-gtk/$(OOBRANDDIR)/share/xdg/qstart.desktop
endif
	# we don't need the share/xdgs except qstart
	for f in `find debian -name '*.desktop' | grep xdg | grep -v qstart`; do \
		rm -f $$f; done
	for f in `find debian -name '*.desktop' ! -name "*soffice.od*"`; do \
		sed -i -e '/^Comment\[de\]/s/- *\([a-zA-Z0-9]*\) *macht.*glich.*$$/mit \1/' $$f; \
		if ! grep -q X-KDE-Protocols $$f; then \
			echo 'X-KDE-Protocols=file,http,smb,ftp,webdav' >> $$f; \
		fi; \
	done
	sed -i -e 's/Office;/Office;Graphics;/' $(PKGDIR)-draw/usr/share/applications/openoffice.org$(VER)-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/usr/share/applications/openoffice.org$(VER)-$$i.desktop; \
	done
	perl -pi -e 's/Application;//' $(PKGDIR)-gtk/$(OOBRANDDIR)/share/xdg/qstart.desktop
else
	# menu files from $(OOO_BUILD_TREE)/desktop
	for p in writer calc impress draw math base; do \
		mkdir -p -m755 $(PKGDIR)-$$p/usr/share/applications ;\
			sed -e '/^TryExec=.*/d' \
			    -e "s,^Exec=.*,Exec=ooffice$(VER) -$$p %F," \
			    -e "s,^Icon=.*,Icon=ooo-$$p," \
			    -e '/^Name=/s,  , ,' \
			    -e 's/@STARTUPNOTIFY@/true/' \
			    -e '/^Categories/s/Office/Application;Office/' \
				$(OOO_BUILD_TREE)/desktop/$$p.desktop \
				> $(PKGDIR)-$$p/usr/share/applications/openoffice.org$(VER)-$$p.desktop || exit 1 ;\
	done
endif
	# add version to .menu and .lintian-overrides
	ICONVERSION=`grep PRODUCTVERSION $(SOURCE_TREE)/sysui/desktop/productversion.mk | head -n 1 | cut -d"=" -f2 | cut -d"." -f1 | sed -e s/\ //g`; \
	for i in base calc draw impress math writer; do \
		cat debian/openoffice.org$(VER)-$$i.menu.in \
			| sed -e s/@ICONVERSION@/$$ICONVERSION/ \
			| sed -e s/@VER@/$(VER)/ \
			> debian/openoffice.org$(VER)-$$i.menu; \
	done; \
	for i in base calc core draw impress math writer; do \
		cat debian/openoffice.org$(VER)-$$i.lintian-overrides.in \
			| sed -e s/@ICONVERSION@/$$ICONVERSION/ \
			| sed -e s/@VER@/$(VER)/ \
			| sed -e s/@BASIS_VERSION@/$(BASIS_VERSION)/ \
			> debian/openoffice.org$(VER)-$$i.lintian-overrides; \
	done

ifeq "$(BUILD_PYUNO)" "y"
	# PyUNO packaging
	for v in `pyversions -sv`; do \
		PYTHON_SITE=`python$$v -c 'from distutils import sysconfig; print(sysconfig.get_python_lib())'`; \
		install -d debian/python-uno/$$PYTHON_SITE; \
		install -m644 debian/python-uno/$(OODIR)/program/uno.py debian/python-uno/$$PYTHON_SITE; \
		install -m464 debian/python-uno/$(OODIR)/program/unohelper.py debian/python-uno/$$PYTHON_SITE; \
	done
	rm debian/python-uno/$(OODIR)/program/uno*py
	touch debian/python-uno/$(OODIR)/program/pythonloader.unorc
	chmod u+w debian/python-uno/$(OODIR)/program/pythonloader.unorc
	( echo '[Bootstrap]'; \
	  echo 'PYTHONHOME=file:///usr/lib/$(shell pyversions -ds)'; \
	  echo 'PYTHONPATH=$$PYTHONHOME $$PYTHONHOME/site-packages $$PYTHONHOME/lib-dynload $$PYTHONHOME/lib-tk $$ORIGIN' \
	) > debian/python-uno/$(OODIR)/program/pythonloader.unorc
	chmod u-w debian/python-uno/$(OODIR)/program/pythonloader.unorc

	mkdir -p debian/python-uno/usr/share/doc/python-uno
	for i in doc demo; do \
		cp -r $(SOURCE_TREE)/pyuno/$$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

ifeq "$(ENABLE_MONO)" "y"
	# Mono bindings
	mkdir -p -m755 debian/cli-uno-bridge/$(OOUREDIR)/lib
	mv $(PKGDIR)-core/$(OOBRANDDIR)/ure/lib/cli_uno_bridge.dll \
		debian/cli-uno-bridge/$(OOUREDIR)/lib
	mv $(PKGDIR)-core/$(OOBRANDDIR)/ure/lib/cli_uno_bridge.dll.config \
		debian/cli-uno-bridge/$(OOUREDIR)/lib
	mv debian/ure/$(OOUREDIR)/lib/libcli* \
		debian/cli-uno-bridge/$(OOUREDIR)/lib
	mkdir -p debian/cli-uno-bridge/usr/lib/pkgconfig
	cat debian/tmp/usr/lib/pkgconfig/mono-$(OODIRNAME).pc \
		| sed -e s,/usr/lib/mono/openoffice,/usr/lib/cli/uno-1.0,g \
		| sed -e s,/usr/lib/cli/uno-1.0/cli_uno_bridge.dll,/$(OOUREDIR)/lib/cli_uno_bridge.dll, \
		> debian/cli-uno-bridge/usr/lib/pkgconfig/mono-$(OODIRNAME).pc
endif

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

ifeq "$(PACKAGE_SDK)" "y"
  ifeq "$(USE_SYSTEM_STLPORT)" "y"
	# when we use external stlport, we just can and should do a symlink
	# for the SDK includes
	cd $(PKGDIR)-dev/usr/include/$(OODIRNAME) && \
		rm -rf stl && ln -s /usr/include/stlport stl
  endif
  ifeq "$(ENABLE_JAVA)" "y"
	# move SDK Java stuff into /usr/share/java/openoffice
	rm -f $(PKGDIR)-dev/$(OOSDKDIR)/classes
	mkdir -p $(PKGDIR)-dev/usr/share/java/$(OODIRNAME)/win
	mkdir -p $(PKGDIR)-dev/usr/share/java/$(OODIRNAME)/com/sun/star/lib/loader
	mkdir -p $(PKGDIR)-dev/$(OOSDKDIR)/classes/com/sun/star/lib/loader
	mv $(PKGDIR)-dev/usr/share/openoffice$(VER)/sdk/classes/com/sun/star/lib/loader/* \
		$(PKGDIR)-dev/usr/share/java/$(OODIRNAME)/com/sun/star/lib/loader && \
	mv $(PKGDIR)-dev/usr/share/openoffice$(VER)/sdk/classes/win \
		$(PKGDIR)-dev/$(OOSDKDIR)/classes
	chmod 644 $(PKGDIR)-dev/$(OOSDKDIR)/classes/win/unowinreg.dll
	cd $(PKGDIR)-dev/$(OOSDKDIR)/classes/com/sun/star/lib/loader && \
		for i in $(CURDIR)/$(PKGDIR)-dev/usr/share/java/$(OODIRNAME)/com/sun/star/lib/loader/*.class; do \
			ln -s `echo $$i | sed -e 's,$(CURDIR)/$(PKGDIR)-dev,,'` `basename $$i`; \
		done
	rm -rf $(PKGDIR)-dev/usr/share/openoffice$(VER)/sdk
  endif
	chmod 644 $(PKGDIR)-dev/$(OOSDKDIR)/configure.pl
	for i in csh csh.in; do \
		perl -pi -e 's,/usr/bin/csh,/bin/csh,'\
			$(PKGDIR)-dev/$(OOSDKDIR)/setsdkenv_unix.$$i; \
	done
	# 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

	# install gsicheck into -dev
	install -m755 $(SOURCE_TREE)/solver/$(shell . $(SOURCE_TREE)/*.sh; echo $$UPD/$$OUTPATH$$PROEXT)/bin/gsicheck \
		$(PKGDIR)-dev/$(OODIR)/program/gsicheck.bin
	( \
	  echo '#! /bin/sh'; \
	  echo 'LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}/$(OODIR)/program'; \
	  echo 'export LD_LIBRARY_PATH'; \
	  echo 'exec /$(OODIR)/program/gsicheck.bin "$$@"'; \
	) > $(PKGDIR)-dev/$(OODIR)/program/gsicheck
	chmod 755 $(PKGDIR)-dev/$(OODIR)/program/gsicheck
endif

ifeq "$(INTERNAL_STDLIBS)" "y"
	# we have to do this manually; specifying --without-system-stdlibs
	# won't work because the odering of the configure arguments...
	LIBSTDCPP=`readlink `PATH=$(BUILD_PATH) g++ --print-file-name=libstdc++.so``; \
	LIBGCC=`readlink `PATH=$(BUILD_PATH) gcc --print-file-name=libgcc_s.so``; \
	LIBSTDCPP_SOVER=`echo $$LIBSTDCPP | sed -e 's/.*\.//'`; \
	LIBGCC_SOVER=`echo $$LIBGCC | sed -e 's/.*\.//'`; \
	cp $$LIBSTDCPP debian/ure/$(OOUREDIR)/lib; \
	cp $$LIBGCC debian/ure/$(OOUREDIR)/lib; \
	echo "libstdc++	$$LIBSTDCPP_SOVER" > debian/shlibs.override.stdlibs; \
	echo "libgcc_s	$$LIBGCC_SOVER" >> debian/shlibs.override.stdlibs
endif
ifeq "$(USE_STLPORT)" "y"
  ifeq "$(USE_SYSTEM_STLPORT)" "y"
	rm -f debian/ure/$(OOUREDIR)/lib/libstlport*
	ln -s `readlink -f /usr/lib/libstlport_gcc.so` \
		debian/ure/$(OOUREDIR)/lib/libstlport_gcc.so
  endif
endif

ifeq "$(ENABLE_JAVA)" "y"
  ifeq "$(BUILD_JARS_NATIVE)" "y"
    ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	rm -rf $(PKGDIR)-gcj/usr/lib/gcj
	mkdir -p $(PKGDIR)-gcj/usr/lib/gcj/openoffice
	cp -p debian/tmp/native-jars/gcj/* $(PKGDIR)-gcj/usr/lib/gcj/openoffice
	mkdir -p $(PKGDIR)-gcj/usr/share/gcj/classmap.d
	cp -p debian/tmp/native-jars/tmp.db \
		$(PKGDIR)-gcj/usr/share/gcj/classmap.d/openoffice.org.db
    endif
  endif
endif

ifneq "$(USE_COMMON_DOCDIR)" "y"
	# install some docs.
	mkdir -p $(PKGDIR)-base/usr/share/doc/openoffice.org$(VER)-base
	cp $(OOO_BUILD_TREE)/doc/using-mysql-databases.txt \
		$(PKGDIR)-base/usr/share/doc/openoffice.org$(VER)-base
	cp $(OOO_BUILD_TREE)/doc/data-from-remote-mysql-server.txt \
		$(PKGDIR)-base/usr/share/doc/openoffice.org$(VER)-base
else
	# install some docs (docdir of the uno-libs3 package). 
	mkdir -p $(PKGDIR)-base/usr/share/doc/uno-libs3
	cp $(OOO_BUILD_TREE)/doc/using-mysql-databases.txt \
		$(PKGDIR)-base/usr/share/doc/uno-libs3
	cp $(OOO_BUILD_TREE)/doc/data-from-remote-mysql-server.txt \
		$(PKGDIR)-base/usr/share/doc/uno-libs3
endif

ifneq "$(USE_EXTERNAL_MYTHES)" "y"
	# install libmythes and th_gen_idx.pl (on archs where we build OOo)
	rm -rf debian/libmythes-dev
	mkdir -p debian/libmythes-dev/usr/lib
	mkdir -p debian/libmythes-dev/usr/include
	mkdir -p debian/libmythes-dev/usr/share/mythes
	install -m644 \
		$(SOURCE_TREE)/lingucomponent/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/libmythes.a \
		debian/libmythes-dev/usr/lib/libmythes_pic.a
	install -m644 \
		$(SOURCE_TREE)/libmythes_nopic.a \
		debian/libmythes-dev/usr/lib/libmythes.a
	install -m644 $(SOURCE_TREE)/lingucomponent/source/thesaurus/mythes/mythes.hxx \
		debian/libmythes-dev/usr/include
	install -m755 $(SOURCE_TREE)/dictionaries/util/th_gen_idx.pl \
		debian/libmythes-dev/usr/share/mythes/th_gen_idx.pl
endif

ifeq "$(PACKAGE_SDK)" "y"
  ifeq "$(ENABLE_JAVA)" "y"
	# install the UNO Java sources for e.g. eclipse
	mkdir -p $(CURDIR)/$(PKGDIR)-dev/usr/share/java/$(OODIRNAME)
	cd $(SOURCE_TREE)/solver/$(shell . $(SOURCE_TREE)/*.sh; echo $$UPD)/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin && \
		for i in juh jurt jut ridl unoloader; do \
			cp $${i}_src.zip \
			  $(CURDIR)/$(PKGDIR)-dev/usr/share/java/openoffice; \
		done
  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

	# move impressgraphics filter stuff into -impress
	mkdir -p $(PKGDIR)-draw/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types
	mkdir -p $(PKGDIR)-draw/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter
	mv $(PKGDIR)-draw/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types/fcfg_impressgraphics_types.xcu \
	  $(PKGDIR)-impress/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types
	mv $(PKGDIR)-draw/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter/fcfg_impressgraphics_filters.xcu \
	  $(PKGDIR)-impress/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter

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

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)
	rm -f $(PKGDIR)-base/$(OODIR)/program/librpt*
else
	# move rpt stuff into -report-builder-bin
	rm -rf $(PKGDIR)-report-builder
	rm -rf $(PKGDIR)-report-builder-bin
	mkdir -p $(PKGDIR)-report-builder-bin/$(OODIR)/program
	mv $(PKGDIR)-base/$(OODIR)/program/librpt* \
		$(PKGDIR)-report-builder-bin/$(OODIR)/program
  ifeq "$(ENABLE_JAVA)" "y"
	# install this; we need to register this ourselves later in
	# the maintainer scripts. This is intended upstream (*rpt* stuff
	# in OOo and the actual report builder as an extension, without which
	# the *rpt* stuff is a no-op.
	install -D -m644 $(SOURCE_TREE)/reportbuilder/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/sun-report-builder.oxt \
		$(PKGDIR)-report-builder/$(OOBRANDDIR)/share/extension/install/sun-report-builder.oxt
	# unneeded license files
	for i in THIRDPARTYREADMELICENSE.html readme_en-US.html readme_en-US.txt; do \
		zip -d $(CURDIR)/$(PKGDIR)-report-builder/$(OOBRANDDIR)/share/extension/install/sun-report-builder.oxt $$i; \
	done
  endif
endif

ifeq "$(ENABLE_MINIMIZER)" "y"
	rm -rf $(PKGDIR)-presentation-minimizer
	install -D -m644 $(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/sun-presentation-minimizer.oxt \
		$(PKGDIR)-presentation-minimizer/$(OOBRANDDIR)/share/extension/install/sun-presentation-minimizer.oxt
endif

ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	rm -rf $(PKGDIR)-presenter-console
	install -D -m644 $(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/presenter-screen.oxt \
		 $(PKGDIR)-presenter-console/$(OOBRANDDIR)/share/extension/install/presenter-screen.oxt
endif

ifeq "$(ENABLE_SDBC_POSTGRESQL)" "y"
	rm -rf $(PKGDIR)-sdbc-postgresql
	install -D -m644 $(SOURCE_TREE)/connectivity/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/postgresql-sdbc-$(shell grep ^PQ_SDBC_M $(SOURCE_TREE)/connectivity/source/drivers/postgresql/makefile.mk | cut -d"=" -f2 | xargs | sed -e s/\ /\./g).zip \
		$(PKGDIR)-sdbc-postgresql/$(OOBRANDDIR)/share/extension/install/postgresql-sdbc-$(shell grep ^PQ_SDBC_M $(SOURCE_TREE)/connectivity/source/drivers/postgresql/makefile.mk | cut -d"=" -f2 | xargs | sed -e s/\ /\./g).zip
endif

ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	rm -rf $(PKGDIR)-mysql-connector
	install -D -m644 $(SOURCE_TREE)/mysqlc/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/mysql-connector-ooo.oxt \
		$(PKGDIR)-mysql-connector/$(OOBRANDDIR)/share/extension/install/mysql-connector-ooo.oxt
endif

ifeq "$(ENABLE_PDFIMPORT)" "y"
	rm -rf $(PKGDIR)-pdfimport
	install -D -m644 $(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/pdfimport.oxt \
		$(PKGDIR)-pdfimport/$(OOBRANDDIR)/share/extension/install/pdfimport.oxt
endif

	# move services.rdb to /var/lib/openoffice
	mkdir -p $(PKGDIR)-core/var/lib/$(OODIRNAME)/basis$(OOVER)/program
	mv $(PKGDIR)-core/usr/lib/$(OODIRNAME)/basis$(OOVER)/program/services.rdb \
		$(PKGDIR)-core/var/lib/$(OODIRNAME)/basis$(OOVER)/program/services.rdb
	ln -s /var/lib/$(OODIRNAME)/basis$(OOVER)/program/services.rdb \
		$(PKGDIR)-core/usr/lib/$(OODIRNAME)/basis$(OOVER)/program/services.rdb

		
	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)/" \
				> debian/$$i.bug-script; \
		fi ;\
	done
endif # ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	touch $@

broffice: $(STAMP_DIR)/broffice
$(STAMP_DIR)/broffice: $(STAMP_DIR)/install $(STAMP_DIR)/install-arch $(STAMP_DIR)/install-indep $(STAMP_DIR)/langpacks
	dh_testdir
	dh_testroot
	
	# BrOffice.org
	rm -rf debian/broffice.org
	mkdir -p debian/broffice.org$(VER)/usr/bin
	mkdir -p debian/broffice.org$(VER)/usr/share/applications
	mkdir -p debian/broffice.org$(VER)/usr/share/application-registry
	mkdir -p debian/broffice.org$(VER)/usr/share/mimelnk/application
	mkdir -p debian/broffice.org$(VER)/$(OOBRANDDIR)/program/resource
	mkdir -p debian/broffice.org$(VER)/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Setup
	mkdir -p debian/broffice.org$(VER)/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Office/UI
ifeq "$(BUILD_KDE)" "y"
	mkdir -p debian/broffice.org$(VER)/usr/share/templates
endif
	cat $(PKGDIR)-common/$(OOBRANDDIR)/program/bootstraprc \
		| sed -e "s/OpenO/BrO/" | sed -e "s/openo/bro/" \
		> debian/broffice.org$(VER)/$(OOBRANDDIR)/program/bootstraprc
	cat $(PKGDIR)-common/$(OOBRANDDIR)/program/versionrc \
		| sed -e "s/en-US/pt-BR/" | sed -e "s/OpenO/BrO/" \
		> debian/broffice.org$(VER)/$(OOBRANDDIR)/program/versionrc
	cat $(PKGDIR)-common/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Setup/Setup-brand.xcu \
		| sed -e "s/OpenO/BrO/" \
		> debian/broffice.org$(VER)/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Setup/Setup-brand.xcu
	cat $(PKGDIR)-common/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Office/UI/UI-brand.xcu \
		| sed -e "s/OpenO/BrO/" \
		> debian/broffice.org$(VER)/$(OOBRANDDIR)/share/registry/modules/org/openoffice/Office/UI/UI-brand.xcu
ifeq "$(BUILD_KDE)" "y"
	for i in odt ods odp odg; do \
		cat $(PKGDIR)-kde/usr/share/templates/soffice.$${i}.desktop \
			| sed -e "s/OpenO/BrO/" \
			> debian/broffice.org$(VER)/usr/share/templates/soffice.$${i}.desktop; \
	done
endif
	for iso in $(LANGPACKISOS); do \
		if [ "$$iso" = "en-US" ]; then p=common; else p=l10n-`echo $$iso | tr A-Z a-z`; fi; \
		if [ -f $(PKGDIR)-$$p/$(OOBRANDDIR)/program/resource/ooo$$iso.res ]; then \
			cat $(PKGDIR)-$$p/$(OOBRANDDIR)/program/resource/ooo$$iso.res \
			| sed -e "s/OpenO/BrO/" \
			> debian/broffice.org$(VER)/$(OOBRANDDIR)/program/resource/ooo$$iso.res; \
		fi; \
	done
	for i in writer calc draw impress math base startcenter; do \
		if [ "$$i" = "startcenter" ]; then d=common; else d=$$i; fi; \
		cat $(PKGDIR)-$$d/usr/share/applications/openoffice.org$(VER)-$$i.desktop \
			| sed -e "s/ooff/broff/" | sed -e "s/OpenO/BrO/" \
			> debian/broffice.org$(VER)/usr/share/applications/openoffice.org$(VER)-$$i.desktop; \
	done
	dirname="`cd $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/broffice.org >/dev/null; pwd`" ;\
	mkdir -p -m755 debian/broffice.org/usr/share/mimelnk/application ;\
	sed -e 's,Comment=Extension,Comment=BrOffice.org $(VER) Extension,' \
	    -e 's,Icon=brofficeorg[0123456789]-extension,Icon=application-vnd.openofficeorg.extension.png,' \
	    -e 's/  / /' \
	    < $$dirname/extension.desktop \
	    > debian/broffice.org/usr/share/mimelnk/application/vnd.openofficeorg.extension.desktop || exit 1
	mkdir -p debian/broffice.org/usr/share/application-registry && \
	cat $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/broffice.org/openoffice.applications \
		| sed -e s/OFFICENAME/broffice/g \
		| sed -e s/\%PRODUCTNAME/BrOffice.org/g \
		> debian/broffice.org/usr/share/application-registry/openoffice.applications
	rm -f debian/broffice.org/usr/share/mime-info/openoffice.keys; \
	mkdir -p debian/broffice.org/usr/share/mime-info/
	for i in $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/broffice.org/*.keys; do \
		cat $$i >> debian/broffice.org/usr/share/mime-info/openoffice.keys; \
	done
	if dpkg-parsechangelog | grep urgency | egrep -q "\~.*m[0123456789]+"; then \
		 debian/scripts/fix_image_rgb \
			 $(SOURCE_TREE)/ooo_custom_images/dev_nologo_broffice/introabout/intro.bmp \
			 debian/broffice.org$(VER)/$(OOBRANDDIR)/program/intro.bmp; \
	else \
		debian/scripts/fix_image_rgb \
			$(SOURCE_TREE)/ooo_custom_images/nologo_broffice/introabout/intro.bmp \
			debian/broffice.org$(VER)/$(OOBRANDDIR)/program/intro.bmp; \
	fi
	install -m644 $(SOURCE_TREE)/ooo_custom_images/broffice/introabout/about.bmp \
		debian/broffice.org$(VER)/$(OOBRANDDIR)/program/about.bmp
ifeq "$(DIST)" "Ubuntu"
	mv debian/broffice.org$(VER)/$(OOBRANDDIR)/program/intro.bmp debian/broffice.org$(VER)/$(OOBRANDDIR)/program/openintro_ubuntu_oracle.bmp
	mv debian/broffice.org$(VER)/$(OOBRANDDIR)/program/about.bmp debian/broffice.org$(VER)/$(OOBRANDDIR)/program/openabout_ubuntu_oracle.bmp
endif
	cd debian/broffice.org$(VER)/usr/bin && ln -s ooffice$(VER) broffice$(VER)

	# this is referenced in .keys/.applications
	for i in `find $(PKGDIR)-common/usr/share/icons -name "openofficeorg*png"`; do \
		mkdir -p `dirname $$i | sed -e s,openoffice.org-common,broffice.org,`; \
		ln -s `basename $$i` `echo $$i | sed -e s,openoffice.org-common,broffice.org, | sed -e s/openofficeorg/brofficeorg/`; \
	done
 
	touch $@

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

ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
	perl -pi -e 's,/bin,/usr/bin,' \
		 debian/openoffice.org$(VER)-emailmerge/$(OODIR)/program/mailmerge.py

ifneq "$(USE_GSTREAMER)" "y"
	# 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

	# Extract and install icons
	cd $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/desktop-integration && dpkg --extract openoffice.org$(OOVER)-debian-menus_*_all.deb . && cd usr/share/icons && \
	rm -rf gnome locolor && \
	for d in `find -type d`; do \
	  install -d -m755 $(CURDIR)/$(PKGDIR)-common/usr/share/icons/$$d || exit 1 ;\
	done &&\
	for f in `find -type f`; do \
	  install -m644 $$f $(CURDIR)/$(PKGDIR)-common/usr/share/icons/$$f || exit 1 ;\
	done && cd ../../.. && rm -rf usr etc

ifeq "$(USE_OOO_BUILD_DESKTOPS)" "n"
	# menu files from sysui
	dirname="`cd $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/desktopshare >/dev/null; pwd`" ;\
	mkdir -p -m755 $(PKGDIR)-common/usr/share/applications ;\
	sed -e 's,Exec=$${UNIXPRODUCTNAME}$${PRODUCTVERSION} \(.*\) %U,Exec=ooffice$(VER) \1 %U,' \
	    -e 's,Icon=$${WITHOUTDOTUNIXPRODUCTNAME}[0123456789]\+-startcenter,Icon=ooo-gulls,' \
	    -e 's,Name=$${PRODUCTNAME} $${PRODUCTVERSION},Name=OpenOffice.org $(VER),' \
	    -e 's/  / /' \
	   < $$dirname/startcenter.desktop \
	   > $(PKGDIR)-common/usr/share/applications/openoffice.org$(VER)-startcenter.desktop || exit 1
	# remove Sun reference 
	perl -pi -e 's/ Supported by Sun Microsystems.//' $(PKGDIR)-common//usr/share/applications/openoffice.org$(VER)-startcenter.desktop
	# invalid, according to lintian. make it shut up.
	perl -pi -e 's/Application;//; s/X-Red-Hat-Base;//; s/X-SuSE-Core-Office;//; s/X-MandrivaLinux-.*;//;' $(PKGDIR)-common/usr/share/applications/openoffice.org$(VER)-startcenter.desktop
endif

	# install .applications, .keys, .mime and openoffice.org.xml for
	# shared-mime-info
	mkdir -p $(PKGDIR)-common/usr/share/application-registry && \
	cat $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/openoffice.org/openoffice.applications \
		| sed -e s/OFFICENAME/ooffice/g \
		| sed -e s/\%PRODUCTNAME/OpenOffice.org/g \
		> $(PKGDIR)-common/usr/share/application-registry/openoffice.applications
	mkdir -p $(PKGDIR)-common/usr/share/mime/packages && \
	mkdir -p $(PKGDIR)-common/usr/share/mime-info && \
	install -m644 $(SOURCE_TREE)/sysui/desktop/mimetypes/openoffice.mime \
		$(PKGDIR)-common/usr/share/mime-info && \
	rm -f $(PKGDIR)-common/usr/share/mime-info/openoffice.keys; \
	for i in $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/openoffice.org/*.keys; do \
		cat $$i >> $(PKGDIR)-common/usr/share/mime-info/openoffice.keys; \
	done
	install -m644 $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/openoffice.org/openoffice.org.xml \
		$(PKGDIR)-common/usr/share/mime/packages

	mkdir -p $(PKGDIR)-common/usr/share/applications

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

ifeq "$(HELPISOS)" ""
	# 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)/helpcontent2/source/auxiliary/main_transform.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	cp $(SOURCE_TREE)/helpcontent2/source/auxiliary/idxcaption.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	cp $(SOURCE_TREE)/helpcontent2/source/auxiliary/idxcontent.xsl \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
endif

ifeq "$(PACKAGE_SDK)" "y"
	chmod 644 $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/docs/images/bg_table2.gif
	chmod 644 $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/docs/images/bg_table3.gif
	chmod 644 $(PKGDIR)-dev-doc/$(OOSDKDIR)/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/build.xml
	chmod 644 $(PKGDIR)-dev-doc/$(OOSDKDIR)/examples/DevelopersGuide/ScriptingFramework/SayHello/build.xml
	chmod 644 `find $(PKGDIR)-dev-doc/$(OOSDKDIR)/examples/java/EmbedDocument -type f | xargs`
	rm -f $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev-doc/LICENSE
	perl -pi -e 's,license.html,http://www.gnu.org/licenses/lgpl.html,' \
		$(PKGDIR)-dev-doc/$(OOSDKDIR)/index.html

  ifeq "$(ENABLE_JAVA)" "y"
        # fix links
	cd $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev/docs/java/ref && \
	for i in `find . -type f | xargs`; do \
		perl -pi -e 's,file:$(CURDIR)/$(OOO_BUILD_TREE)/build/$(TAG)/odk/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/odkcommon/docs/common/ref/,,g' $$i; \
	done
  endif
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/usr/share/java/$(OODIRNAME)
	mv $(PKGDIR)-common/$(OODIR)/share/Scripts/java \
		$(PKGDIR)-java-common/$(OODIR)/share/Scripts
	mv $(PKGDIR)-common/$(OODIR)/program/classes/* \
		$(PKGDIR)-java-common/usr/share/java/$(OODIRNAME)
	cd $(PKGDIR)-java-common/$(OODIR)/program/classes && \
		for i in $(CURDIR)/$(PKGDIR)-java-common/usr/share/java/$(OODIRNAME)/*; 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

	# move into extra package
	rm -rf $(PKGDIR)-filter-mobiledev
	mkdir -p $(PKGDIR)-filter-mobiledev/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter
	mkdir -p $(PKGDIR)-filter-mobiledev/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types
	mkdir -p $(PKGDIR)-filter-mobiledev/usr/share/java/$(OODIRNAME)
	mkdir -p $(PKGDIR)-filter-mobiledev/$(OODIR)/program/classes
	for i in palm pocketexcel pocketword; do \
	  mv $(PKGDIR)-common/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter/fcfg_$${i}_filters.xcu \
	    $(PKGDIR)-filter-mobiledev/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Filter; \
	  mv $(PKGDIR)-common/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types/fcfg_$${i}_types.xcu \
	    $(PKGDIR)-filter-mobiledev/$(OODIR)/share/registry/modules/org/openoffice/TypeDetection/Types; \
	done
	for i in aportisdoc pexcel pocketword; do \
	  mv $(PKGDIR)-java-common/usr/share/java/$(OODIRNAME)/$$i.jar \
		$(PKGDIR)-filter-mobiledev/usr/share/java/$(OODIRNAME); \
	  ln -s /usr/share/java/$(OODIRNAME)/$$i.jar \
		$(PKGDIR)-filter-mobiledev/$(OODIR)/program/classes; \
	done
endif

	# fix permissions
	for i in editpic poll savepic show webcast; do \
		chmod 755 $(PKGDIR)-common/$(OODIR)/share/config/webcast/$$i.pl; \
	done

	rm -rf $(PKGDIR)-common/$(OOBRANDDIR)/LICENSE

	# move uno_packages/cache to /var and create symlink for for
	# documentation referencing it...
	rm -rf $(PKGDIR)-common/$(OOBRANDDIR)/share/uno_packages/cache
	mkdir -p $(PKGDIR)-common/var/spool/$(OODIRNAME)/uno_packages/cache
	ln -s /var/spool/$(OODIRNAME)/uno_packages/cache \
		$(PKGDIR)-common/$(OOBRANDDIR)/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

	# move javasettingsunopkginstall.xml to /var/lib
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/usr/var/)/share/config
	mv $(PKGDIR)-common/$(OODIR)/share/config/javasettingsunopkginstall.xml \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/usr/var/)/share/config/javasettingsunopkginstall.xml
	ln -s /$(shell echo $(OODIR) | sed -e s/usr/var/)/share/config/javasettingsunopkginstall.xml \
		$(PKGDIR)-common/$(OODIR)/share/config/javasettingsunopkginstall.xml
	# set PYTHONPATH in unopkg
	perl -pi -e 's,export PATH,export PATH\n\nexport PYTHONPATH=\"/$(OOBASISDIR)/program\"\n\n,' \
		$(PKGDIR)-common/$(OOBRANDDIR)/program/unopkg

	# install DicOOo; we need to do this manually; the
	# dictionaries/ module isn't built with --without-myspell-dicts
	# and those two somehow (why?) are in there...
	mkdir -p $(PKGDIR)-common/usr/share/myspell/dicts
	install -m644 $(SOURCE_TREE)/dictionaries/diclst/DicOOo.sxw \
		$(PKGDIR)-common/usr/share/myspell/dicts
	# issue 79153
	perl -pi -e 's,\s<library:element library:name="FontOOo"/>\n,,' \
		$(PKGDIR)-common/$(OODIR)/share/basic/launcher/script.xlb

ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	mkdir -p debian/ttf-opensymbol/usr/share/fonts/truetype/openoffice
	mv $(PKGDIR)-common/$(OODIR)/share/fonts/truetype/opens___.ttf \
		debian/ttf-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

ifeq "$(ENABLE_JAVA)" "y"
	# symlink jars we use externally
  ifeq "$(USE_SYSTEM_SAXON)" "y"
	ln -sf /usr/share/java/saxonb.jar \
		$(PKGDIR)-java-common/$(OODIR)/program/classes/saxon9.jar
  endif
  ifeq "$(USE_SYSTEM_BSH)" "y"
	ln -sf /usr/share/java/bsh.jar \
	        $(PKGDIR)-java-common/$(OODIR)/program/classes/bsh.jar
  endif
endif
	# remove extra license files
	rm -rf $(PKGDIR)-common/$(OOBRANDDIR)/licenses
	rm -f $(PKGDIR)-common/$(OOBRANDDIR)/share/readme/LICENSE*
	rm -f $(PKGDIR)-common/$(OOBRANDDIR)/THIRDPARTYLICENSEREADME.html
	rm -f $(PKGDIR)-common/$(OOBRANDDIR)/LICENSE.html

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

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

	# install ooo-build desktop icons
	for r in 16x16 22x22 24x24 32x32 48x48; do \
		mkdir -p $(PKGDIR)-common/usr/share/icons/hicolor/$$r/apps; \
		cp $(OOO_BUILD_TREE)/desktop/$$r/*.png \
			$(PKGDIR)-common/usr/share/icons/hicolor/$$r/apps; \
	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/$(OOBRANDDIR)/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/$(OOBRANDDIR)/program/sofficerc; \
	) > $(PKGDIR)-common/$(OOBRANDDIR)/program/sofficerc
	cat $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc \
		| perl -p -e 's/(.*)=(.*)/$$1=\$${\$$FHS_CONFIG_FILE:Bootstrap:$$1}/' \
		>> $(PKGDIR)-common/$(OOBRANDDIR)/program/sofficerc
	# except for URE_BOOTSTRAP...
	TMP=`mktemp -q`; \
		grep -v URE_BOOTSTRAP $(PKGDIR)-common/$(OOBRANDDIR)/program/sofficerc > $$TMP && mv $$TMP $(PKGDIR)-common/$(OOBRANDDIR)/program/sofficerc && \
		grep URE_BOOTSTRAP $(PKGDIR)-common/etc/$(OODIRNAME)/sofficerc >> $(PKGDIR)-common/$(OOBRANDDIR)/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 "$(DIST)" "Ubuntu" 
	cp -a $(CURDIR)/$(PKGDIR)-common/$(OODIR)/share/config/images_tango.zip \
	  $(CURDIR)/$(PKGDIR)-common/$(OODIR)/share/config/images_$(HUMAN).zip
endif

ifeq "$(HELPISOS)" ""
	# the helpimgs are not included when we don't build with help here.
	# Add them now because openoffice.org-help-* packaged in contrib or so
	# will need them
	set -e; \
	for i in $(IMAGES); do \
		s=_$$i.zip; \
		case "$$i" in $(DEFAULT_IMAGE)) 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; \
	for i in $(IMAGES); do \
		z=images_$$i.zip; p=$$i; \
		case "$$i" in $(DEFAULT_IMAGE)) z=images.zip; esac; \
		case "$$i" in classic) p=andromeda; esac; \
		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/; \
	done

ifeq "$(DIST)" "Ubuntu" 
	rm -rf images
	mkdir -p images
	cd images; \
	  unzip -q $(CURDIR)/$(PKGDIR)-style-human/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config/images_$(HUMAN).zip; \
	  tar xf ../debian/ubuntu/images_new.tar.bz2; \
	  zip -q -r $(CURDIR)/$(PKGDIR)-style-human/$(shell echo $(OODIR) | sed -e s/lib/share/)/share/config/images_$(HUMAN).zip *
	rm -rf images
endif

	rm -rf $(PKGDIR)-dtd-officedocument1.0
	mkdir -p $(PKGDIR)-dtd-officedocument1.0/$(OODIR)/share/dtd
	mv $(PKGDIR)-common/$(OODIR)/share/dtd/officedocument \
		$(PKGDIR)-dtd-officedocument1.0/$(OODIR)/share/dtd
	cp debian/catalog.xml $(PKGDIR)-dtd-officedocument1.0/$(OODIR)/share/dtd/officedocument/1_0
	cat $(PKGDIR)-dtd-officedocument1.0.xmlcatalogs.in \
		| sed -e "s,\@OOBASISDIR\@,$(OOBASISDIR)," \
		> $(PKGDIR)-dtd-officedocument1.0.xmlcatalogs

ifeq "$(USE_COMMON_DOCDIR)" "y"
#	cp -p debian/ubuntu/OracleOpenOfficeLogoTM.pdf \
#	  $(PKGDIR)-common/usr/share/doc/openoffice.org$(VER)-common/
endif

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

	# add "openoffice.org" symlink
	cd $(PKGDIR)-common/usr/bin && ln -s ooffice openoffice.org$(VER)

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

ifneq "$(DIST)" "Ubuntu"
	# ooo-build has a patch with this hardcoded.
	perl -pi -e "s/Ubuntu helper/helper/" $(PKGDIR)-common/$(OOBRANDDIR)/program/soffice
	perl -pi -e "s/Ubuntu config/config/" $(PKGDIR)-common/$(OOBRANDDIR)/program/soffice
	perl -pi -e "s/Ubuntu stuff/stuff/" $(PKGDIR)-common/$(OOBRANDDIR)/program/soffice
endif

ifeq "$(ENABLE_MEDIAWIKI)" "y"
	rm -rf $(PKGDIR)-wiki-publisher
	install -D -m644 $(SOURCE_TREE)/swext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/wiki-publisher.oxt \
	$(PKGDIR)-wiki-publisher/$(OOBRANDDIR)/share/extension/install/wiki-publisher.oxt
	# unneeded license file
	zip -d $(CURDIR)/$(PKGDIR)-wiki-publisher/$(OOBRANDDIR)/share/extension/install/wiki-publisher.oxt license/THIRDPARTYLICENSEREADME.html
endif

	# add version to  .lintian-overrides
	for i in common; do \
		cat debian/openoffice.org$(VER)-$$i.lintian-overrides.in \
			| sed -e s/@BASIS_VERSION@/$(BASIS_VERSION)/ \
			> debian/openoffice.org$(VER)-$$i.lintian-overrides; \
	done

	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

ifeq "$(DIST)" "Debian"
	# fix intro
	if dpkg-parsechangelog | grep urgency | egrep -q "\~.*m[0123456789]+"; then \
		debian/scripts/fix_image_rgb \
			$(SOURCE_TREE)/ooo_custom_images/dev_nologo/introabout/intro.bmp \
			$(PKGDIR)-common/$(OOBRANDDIR)/program/intro.bmp; \
	else \
		debian/scripts/fix_image_rgb \
			$(SOURCE_TREE)/ooo_custom_images/nologo/introabout/intro.bmp \
			$(PKGDIR)-common/$(OOBRANDDIR)/program/intro.bmp; \
	fi
endif

ifeq "$(USE_OOO_BUILD_DESKTOPS)" "n"
	# menu files from sysui
	dirname="`cd $(SOURCE_TREE)/sysui/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/openoffice.org >/dev/null; pwd`" ;\
	mkdir -p -m755 $(PKGDIR)-common/usr/share/mimelnk/application ;\
	sed -e 's,Comment=Extension,Comment=OpenOffice.org $(VER) Extension,' \
	    -e 's,Icon=openofficeorg[0123456789]-extension,Icon=application-vnd.openofficeorg.extension.png,' \
	    -e 's/  / /' \
	    < $$dirname/extension.desktop \
	    > $(PKGDIR)-common/usr/share/mimelnk/application/vnd.openofficeorg.extension.desktop || exit 1
	# install ooo-build mimetype icon
	for i in 16x16 22x22 24x24 32x32 48x48; do \
		install -D -m644 $(CURDIR)/$(OOO_BUILD_TREE)/desktop/mimetypes/$$i/application-vnd.openofficeorg.extension.png \
			$(PKGDIR)-common/usr/share/icons/hicolor/$$i/mimetypes/application-vnd.openofficeorg.extension.png; \
	done
	perl -pi -e "s/Icon=openofficeorg.*-extension/Icon=application-vnd.openofficeorg.extension.png/" $(PKGDIR)-common/usr/share/mimelnk/application/vnd.openofficeorg.extension.desktop
	# add proper MimeType
	perl -pi -e 's,MimeType=,MimeType=application/vnd.openofficeorg.extension,' $(PKGDIR)-common/usr/share/applications/openoffice.org$(VER)-startcenter.desktop
endif

	# fix permission
	chmod 644 $(PKGDIR)-common/$(OODIR)/program/gengalrc

	# 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

	# those are needed in /usr/share, too
	mkdir -p $(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help
	mv $(PKGDIR)-common/$(OODIR)/help/* \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/help/
	# help is in /usr/share
	sed -i 's,$$(instpath)/help,/$(shell echo $(OODIR) | sed -e s/lib/share/)/help,' \
		$(PKGDIR)-common/$(OOBASISDIR)/share/registry/schema/org/openoffice/Office/Common.xcs
	sed -i 's,$$(instpath)/help,/$(shell echo $(OODIR) | sed -e s/lib/share/)/help,' \
		$(PKGDIR)-common/$(OOBASISDIR)/share/registry/data/org/openoffice/Office/Paths.xcu

	# compat dirs, the split icons thing need it
	mkdir -p $(PKGDIR)-common/$(shell echo $(OOBRANDDIR) | 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 basis$(OOVER) \
		$(PKGDIR)-common/$(shell echo $(OOBRANDDIR) | sed -e s/lib/share/)/basis-link
	ln -s /usr/lib/ure \
		$(PKGDIR)-common/$(shell echo $(OODIR) | sed -e s/lib/share/)/ure-link

endif # ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"

	touch $@

gsi-import:
ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
  ifneq "$(OOO_L10N_DIR)" ""
	set -e; \
	for i in $(OOO_L10N_DIR)/import/GSI*; do \
	  [ -r $$i ] || continue; \
	  lang=`basename $$i | sed 's,GSI_\(.*\)\.sdf.*,\1,'`; \
	  case "$$lang" in en-US|de) continue; esac; \
	  echo "updating GSI file for language $$lang ..."; \
	  case "$$i" in \
	    *.bz2) bzcat $$i > ooo-build/src/GSI_$$lang.sdf;; \
	    *.gz) zcat $$i > ooo-build/src/GSI_$$lang.sdf;; \
	    *.sdf) cp -p $$i ooo-build/src/GSI_$$lang.sdf;; \
	    *) echo "    unknown file: $$i"; \
	  esac; \
	  rm -f ooo-build/src/GSI_$$lang.sdf.bz2; \
	  bzip2 -9v ooo-build/src/GSI_$$lang.sdf; \
	  uuencode -m ooo-build/src/GSI_$$lang.sdf.bz2 GSI_$$lang.sdf.bz2 > ooo-build/src/GSI_$$lang.sdf.bz2.uu; \
	  rm ooo-build/src/GSI_$$lang.sdf.bz2; \
	done
  endif
else
	@echo "nothing to import, OOO_L10N_DIR is not set"
endif

GSI_LANGUAGES = $(LANGUAGES)
gsi-export: $(GSI_EXPORT_STAMP)
$(GSI_EXPORT_STAMP):
	$(MAKE) -f debian/rules -j$(shell expr $(AVAIL_CPUS) + 1) $(STAMP_DIR)/gsi-export-parallel
	: # tell pkgstriptranslations that the translations are built
	-ls -l ../$(PKGSOURCE)_*_translations.tar.gz
	rm -f ../$(PKGSOURCE)_*_translations.tar.gz
	: # remove 0 byte translations to keep pkgstriptranslations from dying
	find $(OOO_L10N_DIR)/po -size 0c -name *.po -exec rm -f -v \{\} \;
	touch $@
$(STAMP_DIR)/gsi-export-parallel: $(STAMP_DIR)/build $(foreach lang,$(GSI_LANGUAGES),$(STAMP_DIR)/gsi-export-$(lang))
	touch $@
$(STAMP_DIR)/gsi-export-en-US:
	cd $(SOURCE_TREE); \
	  . Linux*Env.Set.sh; \
	  mkdir -p $(OOO_L10N_DIR)/export; \
	  echo exporting GSI file for pot file generation; \
	  echo localize -e -l en-US -f $(OOO_L10N_DIR)/export/GSI_en-US.sdf; \
	  localize -e -l en-US -f $(OOO_L10N_DIR)/export/GSI_en-US.sdf

	if [ -x /usr/bin/oo2po ]; then \
	  chmod +x debian/scripts/splitgsi; \
	  sh debian/scripts/convert2po en-US; \
	fi
	touch $@

$(STAMP_DIR)/gsi-export-%:
	cd $(SOURCE_TREE); \
	  . Linux*Env.Set.sh; \
	  mkdir -p $(OOO_L10N_DIR)/export; \
	  i=$*; \
	  if [ -f $(CURDIR)/ooo-build/src/GSI_$$i.sdf.bz2.uu ]; then \
	    echo using existing GSI file for language $$i; \
	    uudecode -o /dev/stdout $(CURDIR)/ooo-build/src/GSI_$$i.sdf.bz2.uu \
	      | bzcat - > $(OOO_L10N_DIR)/export/GSI_$$i.sdf; \
	  elif [ -f $(CURDIR)/ooo-build/src/GSI_$$i.sdf.gz.uu ]; then \
	    echo using existing GSI file for language $$i; \
	    uudecode -o /dev/stdout $(CURDIR)/ooo-build/src/GSI_$$i.sdf.gz.uu \
	      | zcat - > $(OOO_L10N_DIR)/export/GSI_$$i.sdf; \
	  else \
	    echo exporting GSI file for language $$i; \
	    echo localize -e -l en-US,$$i -f $(OOO_L10N_DIR)/export/GSI_$$i.sdf; \
	    localize -e -l en-US,$$i -f $(OOO_L10N_DIR)/export/GSI_$$i.sdf >$(OOO_L10N_DIR)/localize-$$i.log; \
	    echo "log summary for localize -e -l en-US,$$i"; \
	    grep '^\.*ERROR:' $(OOO_L10N_DIR)/localize-$$i.log | sed 's/^[.]*//' | sort | uniq -c; \
	  fi

	case " $(REMOVE_HELP) " in *\ $*\ *) \
	  echo "Removing help ($*)"; \
	  grep -v '^helpcontent2' $(OOO_L10N_DIR)/export/GSI_$*.sdf \
	    > $(OOO_L10N_DIR)/export/GSI_$*.sdf.tmp; \
	  debian/scripts/move-if-change $(OOO_L10N_DIR)/export/GSI_$*.sdf.tmp \
	    $(OOO_L10N_DIR)/export/GSI_$*.sdf; \
	esac

	case " $(FILTER_HELP) " in *\ $*\ *) \
	  echo "Filtering untranslated messages from help ($*)"; \
	  python debian/scripts/gsifilter.py $(OOO_L10N_DIR)/export/GSI_$*.sdf; \
	  debian/scripts/move-if-change $(OOO_L10N_DIR)/export/GSI_$*.sdf.tmp \
	    $(OOO_L10N_DIR)/export/GSI_$*.sdf; \
	esac

	if [ -x /usr/bin/oo2po ]; then \
	  chmod +x debian/scripts/splitgsi; \
	  sh debian/scripts/convert2po $*; \
	fi
	touch $@

rosetta2oo:
	mkdir -p debian/l10n
	ln -sf convert2po debian/scripts/convert2oo
	sh debian/scripts/convert2oo $(GSI_LANGUAGES)

ifeq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
# Simplified packaging, langpacks only

binary-arch: $(STAMP_DIR)/binary-arch
$(STAMP_DIR)/binary-arch:
	: # nothing to do
	touch $(STAMP_DIR)/install-arch
	touch $@

else

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 -Nlibmythes-dev debian/README.Debian \
		$(SOURCE_TREE)/instsetoo_native/util/OpenOffice/replace_file/*/00/README \
		$(OOO_BUILD_TREE)/NEWS
	dh_installdocs -plibmythes-dev debian/copyright
	for p in pdfimport presenter-console mysql-connector filter-binfilter \
		evolution kab sdbc-postgresql presentation-minimizer; do \
		cat debian/openoffice.org-common.templates.in > debian/openoffice.org-$$p.templates; \
	done
	cp debian/ure.templates.in debian/ure.templates
	dh_installdebconf -s
	dh_installman -s
	# fix manpage symlinks
	for i in writer calc draw base math impress; do \
		for i in `find $(PKGDIR)-$$i -type l -name "o*.1"`; do \
			mv $$i $$i.gz; \
			if [ "`readlink $$i`" != "openoffice.1.gz" ]; then \
				ln -sf openoffice.1.gz $$i.gz; \
			fi; \
		done; \
	done
	if [ -s $(OOO_BUILD_TREE)/ChangeLog ]; then \
		dh_installchangelogs -s -k -Nlibmythes-dev $(OOO_BUILD_TREE)/ChangeLog; \
	else \
		dh_installchangelogs -s -k -Nlibmythes-dev; \
	fi
ifneq "$(USE_EXTERNAL_MYTHES)" "y"
	dh_installchangelogs -plibmythes-dev
endif
ifeq "$(USE_COMMON_DOCDIR)" "y"
  ifneq "" "$(findstring openoffice.org$(VER)-core, $(PACKAGES))"
#	ln -sf ../openoffice.org$(VER)-common/OracleOpenOfficeLogoTM.pdf \
#	  $(PKGDIR)-core/usr/share/doc/openoffice.org$(VER)-core/OracleOpenOfficeLogoTM.pdf
  endif
	# arch dependent packages (with docdir symlinks)
	for s in \
	  '' -base -base-core -calc -core -dev -draw -evolution \
	  -filter-binfilter -gcj -gnome -gtk -headless -impress -kab -kde \
	  -math -mysql-connector -officebean -ogltrans -pdfimport \
	  -presentation-minimizer -presenter-console -report-builder-bin \
	  -qa-tools -sdbc-postgresql -writer; \
	do \
	  PKG=openoffice.org$(VER)$$s; \
	  echo " $(PACKAGES) " | fgrep -q " $$PKG " || continue; \
	  target=uno-libs3; \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in >> debian/$$PKG.postinst; \
	done
	for PKG in \
	  cli-uno-bridge mozilla-openoffice.org python-uno uno-libs3-dbg ure \
	  ure-dbg; \
	do \
	  echo " $(PACKAGES) " | fgrep -q " $$PKG " || exit 0; \
	  target=uno-libs3; \
	  if [ "$$PKG" = python-uno ]; then \
	    mkdir -p debian/$$PKG/usr/share/doc/$$target; \
	    mv debian/$$PKG/usr/share/doc/python-uno/demo \
	      debian/$$PKG/usr/share/doc/$$target/python-uno-demo; \
	  fi; \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in >> debian/$$PKG.postinst; \
	done
endif
	dh_installmime -s
	dh_installmenu -s
ifeq "$(BUILD_JARS_NATIVE)" "y"
	dh_nativejava -popenoffice.org$(VER)-gcj -o
endif
ifeq "$(USE_PYCENTRAL)" "y"
	dh_pycentral -ppython-uno
else
  ifeq "$(USE_PYSUPPORT)" "y"
	dh_pysupport -ppython-uno -V $(PYMAJOR).$(PYMINOR)
  else
	dh_python
  endif
endif
	dh_lintian -s
	dh_bugfiles -s -A
	dh_link -s
	dh_fixperms -s
ifeq "$(BUILD_DBG_PACKAGE)" "y"
	dh_strip -s -Nure -Nuno-libs3 --dbg-package=openoffice.org$(VER)-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
else
	dh_strip -s
endif
ifeq "$(LENNY_BACKPORT)" "y"
	dh_desktop -s
endif
	dh_icons -s
ifeq "$(ENABLE_MONO)" "y"
	dh_installcligac -s
endif
	dh_compress -s -X.py -X.mk -X.sxd
	dh_makeshlibs -puno-libs3 -V"ure (>= $(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }'))" -- -c0 
	dh_makeshlibs -n -pure -V"ure (>= $(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }'))"
	# 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
ifeq "$(USE_SYSTEM_ICU)" "n"
	cat debian/shlibs.override.icu >> debian/shlibs.local
endif
ifeq "$(BUILD_KDE)" "y"
  ifeq "$(KDE_VER)" "4"
	if dpkg --compare-versions `dpkg -l kdelibs5-dev | grep ^ii | awk '{ print $$3 }'` le 4:4.4; then \
		cat debian/shlibs.override.kde >> debian/shlibs.local; \
	fi
  endif
endif
ifeq "$(INTERNAL_STDLIBS)" "y"
	cat debian/shlibs.override.stdlibs >> 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="/usr/lib/libfakeroot: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 -Nopenoffice.org$(VER)-officebean \
			-Lure -Luno-libs3 \
			-ldebian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program:$(PKGDIR)-base/$(OODIR)/program \
			$(SHLIBS_OVERRIDE)
ifeq "$(USE_SYSTEM_REDLAND)" "y"
	# 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/`objdump -p $(PKGDIR)-core/$(OOBASISDIR)/program/libunordf*.so | grep NEEDED | grep librdf | awk '{ print $$2 }'` | cut -d: -f1).shlibs | awk '{ print $$3,$$4,$$5 }')/' $(PKGDIR)-core.substvars
endif
	# don't make uno-libs3 depend on ure...
	perl -pi -e 's/, ure \(.*\)$$//' debian/uno-libs3.substvars
ifeq "$(ENABLE_JAVA)" "y"
	LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
		dh_shlibdeps -popenoffice.org$(VER)-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_SDBC_POSTGRESQL)" "y"
	# this is in an extension (.zip), so dh_shlibdeps doesn't get it. We need to do
	# it manually.
	LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
		dpkg-shlibdeps -O \
			-Sdebian/uno-libs3/$(OOUREDIR)/lib \
			-Sdebian/ure/$(OOUREDIR)/lib \
			$(SOURCE_TREE)/connectivity/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/postgresql-sdbc*.so \
			> debian/openoffice.org$(VER)-sdbc-postgresql.substvars
endif
ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
		dpkg-shlibdeps -O \
			-Sdebian/uno-libs3/$(OOUREDIR)/lib \
			-Sdebian/ure/$(OOUREDIR)/lib \
			$(SOURCE_TREE)/mysqlc/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/mysqlc.uno.so \
			$(SOURCE_TREE)/mysqlcppconn/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/libmysqlcppconn.so \
			> debian/openoffice.org$(VER)-mysql-connector.substvars
  ifeq "$(USE_SYSTEM_MYSQLCPPCONN)" "n"
	# add mysqlclient dependency; it apparently is only dlopen()ed in
	# the internal case.. (And in the external case we have a dep on
	# libmysqlcppconn4 which deps on libmysqlclient16 already)
	perl -pi -e 's/(shlibs:Depends=.*$$)/$$1, $(shell cat /var/lib/dpkg/info/libmysqlclient16.shlibs | grep _r | cut -d" " -f3,4,5)/' \
		debian/openoffice.org$(VER)-mysql-connector.substvars
  endif
endif
ifeq "$(ENABLE_MINIMIZER)" "y"
	 LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
	 	dpkg-shlibdeps -O \
			-Sdebian/uno-libs3/$(OOUREDIR)/lib \
			-Sdebian/ure/$(OOUREDIR)/lib \
			$(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/SunPresentationMinimizer.uno.so \
			> debian/openoffice.org$(VER)-presentation-minimizer.substvars
endif
ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	 LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
	 	dpkg-shlibdeps -O \
			-Sdebian/uno-libs3/$(OOUREDIR)/lib \
			-Sdebian/ure/$(OOUREDIR)/lib \
			$(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/PresenterScreen.uno.so \
			> debian/openoffice.org$(VER)-presenter-console.substvars
endif
ifeq "$(ENABLE_PDFIMPORT)" "y"
	 LD_LIBRARY_PATH="/usr/lib/libfakeroot:debian/uno-libs3/$(OOUREDIR)/lib:debian/ure/$(OOUREDIR)/lib:$(PKGDIR)-core/$(OODIR)/program" \
	 	dpkg-shlibdeps -O \
			-Sdebian/uno-libs3/$(OOUREDIR)/lib \
			-Sdebian/ure/$(OOUREDIR)/lib \
			$(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/bin/xpdfimport \
			$(SOURCE_TREE)/sdext/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/lib/pdfimport.uno.so \
			> debian/openoffice.org$(VER)-pdfimport.substvars
endif
	# no idea why this happens, hack around
	perl -pi -e "s#, ure \(>= .*\), ure \(>= $(BINARY_VERSION)\)##" debian/ure.substvars
	perl -pi -e "s#, ure \(>= $(BINARY_VERSION)\)##" debian/openoffice.org-core.substvars
	perl -pi -e "s#, ure \(>= $(BINARY_VERSION)\)##" debian/openoffice.org-dev.substvars
	perl -pi -e "s#, ure \(>= $(BINARY_VERSION)\)##" debian/mozilla-openoffice.org.substvars
ifeq "$(ENABLE_MONO)" "y"
	dh_makeclilibs -s
	dh_clideps -s
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 \
		-Nopenoffice.org$(VER)-presentation-minimizer \
		-Nopenoffice.org$(VER)-presenter-console \
		-Nopenoffice.org$(VER)-pdfimport \
		-Nopenoffice.org$(VER)-sdbc-postgresql \
		-Nopenoffice.org$(VER)-mysql-connector -- \
		-V"ure:Version=$(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`" \
		-V'base-version=$(BASE_VERSION)' \
		-V'help-l10n-virtual-version=$(HELP_L10N_VIRTUAL_VERSION)' \
		-V'dev-stl-depends=$(DEV_STL_DEPENDS)' \
		-V'base-hsqldb-depends=$(BASE_HSQLDB_DEPENDS)' \
		-V'java-common-depends=$(JAVA_COMMON_DEPENDS) (>= $(BASE_VERSION)~)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-V'java-gcj-depends=$(JAVA_GCJ_DEPENDS)' \
		-V'mozilla-nss-depends=$(MOZILLA_NSS_DEPENDS)' \
		-V'lucene-depends=$(LUCENE_DEPENDS)' \
		-V'Binary-Version=$(BINARY_VERSION)' \
		-V'ooo-binfilter-dep=$(OOO_BINFILTER_DEP)' \
		-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'libldap-suggests=$(LDAP_LIB)' \
		-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/openoffice.org$(VER)-officebean/DEBIAN/control
endif
ifeq "$(ENABLE_PDFIMPORT)" "y"
	dh_gencontrol -popenoffice.org$(VER)-pdfimport -- \
		-v$(shell grep "<version" $(SOURCE_TREE)/sdext/source/pdfimport/config/description.xml | perl -pi -e 's,<version.*value=\"(.*)\" />,\1,; s/^\s+//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_MINIMIZER)" "y"
	dh_gencontrol -popenoffice.org$(VER)-presentation-minimizer -- \
		-v$(shell grep "<version" $(SOURCE_TREE)/sdext/source/minimizer/description.xml | perl -pi -e 's,<version value=\"(.*)\"/>,\1,; s/^\s+//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_PRESENTER_CONSOLE)" "y"
	dh_gencontrol -popenoffice.org$(VER)-presenter-console -- \
		-v$(shell grep "<version" $(SOURCE_TREE)/sdext/source/presenter/description.xml | perl -pi -e 's,<version value=\"(.*)\" />,\1,; s/^\s+//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_SDBC_POSTGRESQL)" "y"
	dh_gencontrol -popenoffice.org$(VER)-sdbc-postgresql -- \
		-v`echo $(BINARY_VERSION) | cut -d: -f1`:$(shell grep ^PQ_SDBC_M $(SOURCE_TREE)/connectivity/source/drivers/postgresql/makefile.mk | cut -d"=" -f2 | xargs | sed -e s/\ /\./g | sed -e s/a$$//)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_MYSQLNATIVE)" "y"
	dh_gencontrol -popenoffice.org$(VER)-mysql-connector -- \
		-v$(shell grep "<version" $(SOURCE_TREE)/mysqlc/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/description.xml | perl -pi -e 's,<version value=\"(.*)\" />,\1,; s/^\s+//; s/\s+$$//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
	dh_gencontrol -pure -pure-dbg -puno-libs3 -puno-libs3-dbg -- \
		-V"ure:Version=$(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`" \
		-v$(shell grep UREPACKAGEVERSION $(SOURCE_TREE)/instsetoo_native/util/openoffice.lst | awk '{ print $$2 }')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_md5sums -s -X$(shell echo $(OOBASISDIR) | sed -e s/usr/var/)/program/services.rdb
	dh_builddeb -s $(DEBHELPER_OPTIONS) $(BUILDDEB_OPTIONS)

	touch $@
endif # binary-arch for openoffice.org source

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 $(STAMP_DIR)/broffice
ifneq ($(ARCH),$(findstring $(ARCH),$(OOO_JAVA_ARCHS)))
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "For uploads with binary-all packages, please use arches where Java is enabled!!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
endif
ifneq ($(ARCH),$(findstring $(ARCH),$(OOO_MONO_ARCHS)))
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "For uploads with binary-all packages, please use arches where Mono is 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

ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
ifeq "$(PACKAGE_SDK)" "y"
	. $(SOURCE_TREE)/solenv/inc/udkversion.mk && \
	for i in common cpp java; do \
		cat debian/udk-$$i-ref.in \
			| sed -e "s/@UDK_MAJOR@/$$UDK_MAJOR/" \
		      	      -e "s/@UDK_MINOR@/$$UDK_MINOR/" \
		      	      -e "s/@UDK_MICRO@/$$UDK_MICRO/" \
		      	      -e "s/@VER@/$(VER)/" \
			> debian/openoffice.org-dev-doc.doc-base.udk-$$i-ref; \
	done
	# remove Autodoc_DiagnosticMessages.txt
	find $(PKGDIR)-dev-doc/usr/share/doc/openoffice.org-dev \
		-name "Autodoc_DiagnosticMessages.txt" -exec rm {} \;
	UDK_CPP_FILES=`find $(CURDIR)/debian/openoffice.org-dev-doc/usr/share/doc/openoffice.org-dev/docs/cpp/ref | sed -e 's,$(CURDIR)/debian/openoffice.org-dev-doc,,g' | xargs`; \
	echo "Files: $$UDK_CPP_FILES" >> debian/openoffice.org-dev-doc.doc-base.udk-cpp-ref
  ifeq "$(ENABLE_JAVA)" "y"
	UDK_JAVA_FILES=`find $(CURDIR)/debian/openoffice.org-dev-doc/usr/share/doc/openoffice.org-dev/docs/java/ref | sed -e 's,$(CURDIR)/debian/openoffice.org-dev-doc,,g' | xargs`; \
	echo "Files: $$UDK_JAVA_FILES" >> debian/openoffice.org-dev-doc.doc-base.udk-java-ref
  endif
	# xargs strips the many files here so we need to post-process it.
	UDK_COMMON_FILES=`find $(CURDIR)/debian/openoffice.org-dev-doc/usr/share/doc/openoffice.org-dev/docs/common/ref | sed -e 's,$(CURDIR)/debian/openoffice.org-dev-doc,,g' | xargs`; \
	TMP=`mktemp -q`; \
	cp debian/openoffice.org-dev-doc.doc-base.udk-common-ref $$TMP; \
	echo "Files: $$UDK_COMMON_FILES" >> $$TMP; \
	cat $$TMP | perl -e 'while(<>) { if (/^Files/) {$$f=1;} if ($$f eq "1") { chomp(); } print $$_; }' > debian/openoffice.org-dev-doc.doc-base.udk-common-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/openoffice.org-dev-doc.doc-base.udk-common-ref
endif
endif
	dh_installdocs -i -A debian/README.Debian \
		$(SOURCE_TREE)/instsetoo_native/util/OpenOffice/replace_file/*/00/README \
		$(OOO_BUILD_TREE)/NEWS
	for p in common emailmerge wiki-publisher report-builder; do \
		cat debian/openoffice.org-common.templates.in > debian/openoffice.org-$$p.templates; \
	done
	dh_installdebconf -i
	dh_installman -i
	for i in `find $(PKGDIR)-common -type l -name "o*.1"`; do \
		mv $$i $$i.gz; \
		if [ "`readlink $$i`" != "openoffice.1.gz" ]; then \
			ln -sf openoffice.1.gz $$i.gz; \
		fi; \
	done
	if [ -s $(OOO_BUILD_TREE)/ChangeLog ]; then \
		dh_installchangelogs -i -k $(OOO_BUILD_TREE)/ChangeLog; \
	else \
		dh_installchangelogs -i -k; \
	fi
ifeq "$(USE_COMMON_DOCDIR)" "y"
  ifneq "" "$(findstring openoffice.org$(VER)-common, $(PACKAGES))"
	mkdir -p $(PKGDIR)-common/usr/share/doc/openoffice.org$(VER)-common
	install -m644 debian/README.Debian debian/copyright \
	  $(PKGDIR)-common/usr/share/doc/openoffice.org$(VER)-common/
    ifeq "$(PACKAGE_TTF_OPENSYMBOL)" "y"
	dh_installdocs -pttf-opensymbol
	dh_installchangelogs -pttf-opensymbol
    endif
  endif

	# l10 & help packages (with docdir symlinks)
	for PKG in \
	  $(HELP_PACKAGES) $(LANG_PACKAGES); \
	do \
	  case $$PKG in \
	    *l10n-en-us) target=openoffice.org$(VER)-common;; \
	    *) target=openoffice.org$(VER)-l10n-common; \
	  esac; \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG.p*; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in > debian/$$PKG.postinst; \
	done

	# indep packages (with docdir symlinks)
	for s in \
	  -dev-doc -dtd-officedocument1.0 -emailmerge -filter-mobiledev \
	  -java-common -qa-api-tests -report-builder -style-andromeda \
	  -style-crystal -style-galaxy -style-hicontrast -style-human \
	  -style-industrial -style-oxygen -style-tango -wiki-publisher; \
	do \
	  PKG=openoffice.org$(VER)$$s; \
	  echo " $(PACKAGES) " | fgrep -q " $$PKG " || continue; \
	  target=openoffice.org$(VER)-common; \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  case "$$s" in -style-*) continue; esac; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in >> debian/$$PKG.postinst; \
	done
	for PKG in \
	  libuno-cli-cppuhelper1.0-cil libuno-cli-oootypes1.0-cil \
	  libuno-cli-ure1.0-cil libuno-cli-uretypes1.0-cil; \
	do \
	  echo " $(PACKAGES) " | fgrep -q " $$PKG " || exit 0; \
	  target=libuno-cli-basetypes1.0-cil; \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in >> debian/$$PKG.postinst; \
	done
	for PKG in \
	  broffice.org ; \
	do \
	  echo " $(PACKAGES) " | fgrep -q " $$PKG " || exit 0; \
	  target=openoffice.org$(VER); \
	  rm -rf debian/$$PKG/usr/share/doc/$$PKG; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/copyright; \
	  rm -f debian/$$PKG/usr/share/doc/$$target/changelog.Debian*; \
	  mkdir -p debian/$$PKG/usr/share/doc; \
	  ln -sf $$target debian/$$PKG/usr/share/doc/$$PKG; \
	  sed "s/@PKGNAME@/$$PKG/g;s/@PKGTARGET@/$$target/g" \
	    debian/deppackage.postinst.in >> debian/$$PKG.postinst; \
	done

endif
	dh_installmime -i
	dh_lintian -i
	dh_bugfiles -i -A
	dh_link -i
	dh_fixperms -i
ifeq "$(LENNY_BACKPORT)" "y"
	dh_desktop -i
endif
	dh_icons -i
	dh_installxmlcatalogs -i
ifeq "$(ENABLE_MONO)" "y"
	dh_installcligac -i
endif
	dh_compress -X.py -X.mk -X.sxd
	dh_installdeb -i
ifeq "$(ENABLE_MONO)" "y"
	dh_makeclilibs -i
	dh_clideps -i
endif
	dh_gencontrol -i $(DEBHELPER_OPTIONS) \
		-Nopenoffice.org$(VER)-report-builder \
		-Nopenoffice.org$(VER)-wiki-publisher \
		-Nlibuno-cli-basetypes1.0-cil \
		-Nlibuno-cli-uretypes1.0-cil \
		-Nlibuno-cli-oootypes1.0-cil \
		-Nlibuno-cli-cppuhelper1.0-cil \
		-Nlibuno-cli-ure1.0-cil -- \
		-V'base-version=$(BASE_VERSION)' \
		-V'basis-version=$(BASIS_VERSION)' \
		-V'help-l10n-virtual-version=$(HELP_L10N_VIRTUAL_VERSION)' \
		-V'common-bsh-depends=$(COMMON_BSH_DEPENDS)' \
		-V'java-common-depends=$(JAVA_COMMON_DEPENDS)' \
		-V'java-common-java-depends=$(JAVA_COMMON_JAVA_DEPENDS)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-V'lucene-depends=$(LUCENE_DEPENDS)' \
		-V'lucene-conflicts=$(LUCENE_CONFLICTS)' \
		-V'Binary-Version=$(BINARY_VERSION)' \
		-V'ooo-binfilter-dep=$(OOO_BINFILTER_DEP)' \
		-V'dbg-dbg-suggests=$(DBG_DBG_SUGGESTS)' \
		-v$(BINARY_VERSION)
ifneq "$(PKGSOURCE)" "openoffice.org$(VER)-l10n"
ifeq "$(ENABLE_MONO)" "y"
	# although this version gets increased before every OOo release
	# we need the +OOo anyway when we build milestones..
	dh_gencontrol -plibuno-cli-basetypes1.0-cil -- \
		-v$(shell grep CLI_BASETYPES_NEW_VERSION $(SOURCE_TREE)/cli_ure/version/version.txt | cut -d"=" -f2)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_gencontrol -plibuno-cli-uretypes1.0-cil -- \
		-v$(shell grep CLI_URETYPES_NEW_VERSION $(SOURCE_TREE)/cli_ure/version/version.txt | cut -d"=" -f2)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_gencontrol -plibuno-cli-oootypes1.0-cil -- \
		-v$(shell grep CLI_OOOTYPES_NEW_VERSION $(SOURCE_TREE)/unoil/climaker/version.txt | cut -d"=" -f2)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_gencontrol -plibuno-cli-cppuhelper1.0-cil -- \
		-v$(shell grep CLI_CPPUHELPER_NEW_VERSION $(SOURCE_TREE)/cli_ure/version/version.txt | cut -d"=" -f2)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
	dh_gencontrol -plibuno-cli-ure1.0-cil -- \
		-v$(shell grep CLI_URE_NEW_VERSION $(SOURCE_TREE)/cli_ure/version/version.txt | cut -d"=" -f2)+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_MEDIAWIKI)" "y"
	dh_gencontrol -popenoffice.org$(VER)-wiki-publisher -- \
		-V'mediawiki-jar-depends=$(MEDIAWIKI_JAR_DEPENDS)' \
		-V'lucene-depends=$(LUCENE_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+//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
ifeq "$(ENABLE_REPORTDESIGN)" "y"
	dh_gencontrol -popenoffice.org$(VER)-report-builder -- \
		-V'base-version=$(BASE_VERSION)' \
		-V'report-builder-jar-depends=$(REPORT_BUILDER_JAR_DEPENDS)' \
		-V'java-runtime-depends=$(JAVA_RUNTIME_DEPENDS)' \
		-v`echo $(BINARY_VERSION) | cut -d: -f1`:$(shell grep "<version" $(SOURCE_TREE)/reportbuilder/$(shell . $(SOURCE_TREE)/*.sh; echo $$OUTPATH$$PROEXT)/misc/description.xml | perl -pi -e 's,<version value=\"(.*)\"/>,\1,; s/^\s+//')+OOo`echo $(BINARY_VERSION) | cut -d: -f2`
endif
endif
	dh_md5sums -i -Xjavasettingsunopkginstall.xml
	dh_builddeb -i $(DEBHELPER_OPTIONS) $(BUILDDEB_OPTIONS)

	touch $@

binary: binary-arch binary-indep

# Get ooo-build
get-ooo-build:
	rm -rf $(OOO_BUILD_TREE)
	wget http://download.go-oo.org/$(MWS)/ooo-build-$(OOO_BUILD_VERSION).tar.gz && \
	tar xfvz ooo-build-$(OOO_BUILD_VERSION).tar.gz && \
	mv ooo-build-$(OOO_BUILD_VERSION) $(OOO_BUILD_TREE) && \
	rm ooo-build-$(OOO_BUILD_VERSION).tar.gz

get-orig-source:
ifneq "$(WITH_SPLIT)" "y"
	if test -n "$$TMP"; then \
		TMPD=`mktemp -d -p $$TMP`; \
	else \
		TMPD=`mktemp -d`; \
	fi && \
	cd $$TMPD && \
	mkdir -p openoffice.org-$(UPSTREAM_VERSION)/ooo-build/src && \
	cd openoffice.org-$(UPSTREAM_VERSION)/ooo-build/src && \
		wget http://download.services.openoffice.org/files/stable/$(UPSTREAM_VERSION)/OOo_$(UPSTREAM_VERSION)_src_binfilter.tar.bz2 && \
		wget http://download.services.openoffice.org/files/stable/$(UPSTREAM_VERSION)/OOo_$(UPSTREAM_VERSION)_src_core.tar.bz2 && \
		wget http://download.services.openoffice.org/files/stable/$(UPSTREAM_VERSION)/OOo_$(UPSTREAM_VERSION)_src_extensions.tar.bz2 && \
		wget http://download.services.openoffice.org/files/stable/$(UPSTREAM_VERSION)/OOo_$(UPSTREAM_VERSION)_src_l10n.tar.bz2 && \
		wget http://download.services.openoffice.org/files/stable/$(UPSTREAM_VERSION)/OOo_$(UPSTREAM_VERSION)_src_system.tar.bz2 && \
		tar xfvj OOo_$(UPSTREAM_VERSION)_src_core.tar.bz2 && \
		for i in `find $(TAG)/psprint_config/configuration/ppds ! -name "SGEN*" -name "*.PS"`; do \
			rm $$i; \
		done && \
		tar cfvj OOo_$(UPSTREAM_VERSION)_src_core.tar.bz2.dfsg $(TAG) && \
		rm -rf $(TAG) && \
		ln -sf OOo_$(UPSTREAM_VERSION)_src_core.tar.bz2.dfsg OOo_$(UPSTREAM_VERSION)_src_core.tar.bz2 && \
		tar xfvj OOo_$(UPSTREAM_VERSION)_src_system.tar.bz2 && \
		for i in da_DK en_GB nl_NL ru_RU; do \
			rm $(TAG)/dictionaries/$$i/hyph_$${i}.dic; \
		done && \
		tar cfvj OOo_$(UPSTREAM_VERSION)_src_system.tar.bz2.dfsg $(TAG) && \
		rm -rf $(TAG) && \
		ln -sf OOo_$(UPSTREAM_VERSION)_src_system.tar.bz2.dfsg OOo_$(UPSTREAM_VERSION)_src_system.tar.bz2 && \
		tar xfvj OOo_$(UPSTREAM_VERSION)_src_extensions.tar.bz2 && \
			zip -d $(TAG)/jfreereport/download/liblayout.zip \
				liblayout/resource/rfc1345.txt && \
		tar cfvj OOo_$(UPSTREAM_VERSION)_src_extensions.tar.bz2.dfsg $(TAG) && \
		rm -rf $(TAG) && \
		ln -sf OOo_$(UPSTREAM_VERSION)_src_extensions.tar.bz2.dfsg OOo_$(UPSTREAM_VERSION)_src_extensions.tar.bz2 && \
		cd $$TMPD && tar cfvz openoffice.org_$(UPSTREAM_VERSION).orig.tar.gz openoffice.org-$(UPSTREAM_VERSION) && \
		rm -rf openoffice.org-$(UPSTREAM_VERSION) && \
		mv  openoffice.org_$(UPSTREAM_VERSION).orig.tar.gz $(CURDIR)/.. && \
		rmdir $$TMPD
else
	if test -n "$$TMP"; then \
		TMPD=`mktemp -d -p $$TMP`; \
	else \
		TMPD=`mktemp -d`; \
	fi && \
	cd $$TMPD && \
        mkdir -p openoffice.org-$(UPSTREAM_VERSION) && \
        cd openoffice.org-$(UPSTREAM_VERSION) && \
                git clone $(CURDIR)/ooo-build ooo-build && cd ooo-build && \
                ./autogen.sh --with-tag=$(TAG) --with-distro=$(PATCHSET) \
			--without-git --with-lang="$(BUILD_ISOS)" && \
			./download || wait 60; ./download || wait 60; ./download && \
			rm -f src/$(TAG)-l10n.tar.bz2 && \
			./download || wait 60; ./download || wait 60; ./download && \
		cd src && \
		find . -mindepth 1 -maxdepth 1 ! -name "$(TAG)*" -exec rm -rf {} \; && \
		tar xfvj $(TAG)-libs-extern-sys.tar.bz2 && \
		for i in da_DK en_GB nl_NL ru_RU; do \
			rm ooo/$(MWS)_$(MILESTONE)/dictionaries/$$i/hyph_$${i}.dic; \
		done && \
		tar cfvj $(TAG)-libs-extern-sys.tar.bz2.dfsg ooo && \
		ln -sf $(TAG)-libs-extern-sys.tar.bz2.dfsg $(TAG)-libs-extern-sys.tar.bz2 && \
		rm -rf ooo && \
		tar xfvj $(TAG)-libs-gui.tar.bz2 && \
		for i in `find ooo/$(MWS)_$(MILESTONE)/psprint_config/configuration/ppds ! -name "SGEN*" -name "*.PS"`; do \
			rm $$i; \
		done && \
		tar cfvj $(TAG)-libs-gui.tar.bz2.dfsg ooo && \
		ln -sf $(TAG)-libs-gui.tar.bz2.dfsg $(TAG)-libs-gui.tar.bz2 && \
		rm -rf ooo && \
		tar xfvj $(TAG)-extensions.tar.bz2 && \
			zip -d ooo/$(MWS)_$(MILESTONE)/jfreereport/download/liblayout.zip \
				liblayout/resource/rfc1345.txt && \
		tar cfvj $(TAG)-extensions.tar.bz2.dfsg ooo && \
		ln -sf $(TAG)-extensions.tar.bz2.dfsg $(TAG)-extensions.tar.bz2 && \
		rm -rf ooo && \
		cd .. && find . -mindepth 1 -maxdepth 1 ! -name "src" -exec rm -rf {} \; && \
		cd $$TMPD && tar cfvz openoffice.org_$(UPSTREAM_VERSION).orig.tar.gz openoffice.org-$(UPSTREAM_VERSION) && \
		rm -rf openoffice.org-$(UPSTREAM_VERSION) && \
		mv  openoffice.org_$(UPSTREAM_VERSION).orig.tar.gz $(CURDIR)/.. && \
		rmdir $$TMPD
endif
ifeq "$(DEBSRC_VERSION)" "3.0"
	# get ooo-build
	if test -n "$$TMP"; then \
		TMPD=`mktemp -d -p $$TMP`; \
	else \
		TMPD=`mktemp -d`; \
	fi && \
	cd $$TMPD && \
		$(CURDIR)/debian/rules get-ooo-build && \
		tar cfvz openoffice.org_$(UPSTREAM_VERSION).orig-$(OOO_BUILD_TREE).tar.gz $(OOO_BUILD_TREE) && \
		mv openoffice.org_$(UPSTREAM_VERSION).orig-$(OOO_BUILD_TREE).tar.gz $(CURDIR)/..
endif

# Download the latest sources needed for ooo-build. Note that is
# might download more than actually needed here....
download: $(OOO_BUILD_TREE)/config.status
	$(OOO_BUILD_TREE)/download	

.PHONY: control
.PHONY: clean-debdir clean-instsetoo clean-objectdirs clean default configure
.PHONY: build build-indep build-arch install-arch install-indep
.PHONY: $(stampdir_targets)

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