# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../ooo/ooo.conf
# Copyright (C) 2006 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if [ $prefix_auto = 1 ] ; then
	prefix=/opt/ooo
	set_confopt
fi

ooo_lang='en-US de es fr it' #ALL

############################################################################
# Ximian build system configuration options

var_append confopt ' ' "--with-installed-ooo-dirname=OpenOffice.org"
var_append confopt ' ' "--with-docdir=$docdir"

# src680-mXX
cvstag=$( match_source_file -core.tar )
var_append confopt ' ' "--with-tag=${cvstag%-core.tar*}"

# populate src/ with every [D] on our .desc
# (instead of --with-srcdir)
#
hook_add prepatch 5 'ooo_populate_src'
ooo_populate_src() {
	local file= filename=
	for file in `match_source_file -p .`; do
		filename=${file##*/}
		case "$filename" in
			lp_solve*)
				# some files must be converted back to .gz
				echo "repacking '$file' to 'src/${filename%.bz2}.gz'"
				bzcat $file | gzip -c - >  src/${filename%.bz2}.gz	;;
			*)
				ln -svf $file src/	;;
		esac
	done
}

# instead of --with-internal-gcc=no
var_append confopt ' ' "--with-system-gcc"

# yes, we are ourselves
dist=OpenSDE
[ $arch_sizeof_char_p = 8 ] && dist=${dist}64
var_append confopt ' ' "--with-distro=$dist"
# and we only have one OOo on the systems
var_append confopt ' ' '--with-binsuffix=no'

var_append confopt ' ' '--disable-post-install-scripts'
var_append confopt ' ' '--disable-binfilter'
var_append confopt ' ' '--disable-odk'

# UI language
var_append confopt ' ' "'--with-lang=\"\$ooo_lang\"'"
var_append confopt ' ' "'--with-dict=\"\$ooo_lang\"'"

# enable/disable the features dependent on which packages we have
# FIXME: mdbtool,silgraphite,hunspell have not been packaged yet
for x in gtk+ arts cairo mono mdbtool silgraphite \
	hunspell
	do
	# x is the leading package
	# y is the feature at OOo
	case "$x" in
		silgraphite)	y="graphite"	;;
		mdbtool)	y="access"	;;
		gtk+)	y="gtk" ;;
		arts)	y="kde" ;;
		*)	y="$x"	;;
	esac

	# leading package installed
	if pkginstalled $x; then
		var_append confopt ' ' "--enable-$y"
		# special tweakery
		case "$y" in
			#kde)
			#	export QTLIB=$QTDIR/lib
			#	;;
			cairo)
				# to not get ooo-build asking for the source
				var_append confopt ' ' "--with-system-$y"
				;;
		esac
	else
		var_append confopt ' ' "--disable-$y"
	fi
done

# disable java support
var_append confopt ' ' '--with-java=no'

#    --with-openclipart=/usr/share/openclipart

# Architecture (ppc,sparc,and the rest)
cpu="`echo $arch | arch2uname`"
var_append confopt ' ' "--with-arch=$cpu"

hook_add preconf 5 'ooo_preconfigure'
ooo_preconfigure() {
	# i don't want this common config, at least for now -mnemoc
	cat /dev/null > distro-configs/Common.conf.in

	# fixed config
	cat <<-EOT > distro-configs/OpenSDE.conf
	--disable-qadevooo

	--enable-crashdump=no

	--with-db-version=$( pkgprefix ver bdb | cut -d'.' -f1-2 )
	--with-use-shell=bash

	--with-vendor=\\"OpenSDE, http://www.opensde.org/\"
	--with-build-version=\\"OpenSDE v.$sdever - OO.o $ver\\"

	--with-system-libs
	--with-system-stdlibs
	--with-system-python

	--with-system-xmlsec=no
	--without-gpc
	--without-agg

	--disable-mathmldtd
	--disable-directx

	--enable-fontconfig
	--disable-fontooo
	--without-afms

	--without-ppds

	--without-myspell-dicts
	EOT

	# Usage: --with-lang="es sw tu cs sk"
	# Usage: --with-dict=ENGB,ENUS,ITIT

	#  --disable-rpath:        Disable the use of relative paths in shared libraries
	#  --with-intro-bitmaps=/path/my_ooo_intro.bmp
	#  --with-about-bitmaps=/path/my_ooo_about.bmp
	#  --with-vendor="John the Builder"


	# conditional config
	#
	{

	# enable/disable the features dependent on which packages we have
	for x in gtk+ arts cairo mono openldap gconf cups dbus \
		libart_lgpl23 startup-notification gstreamer
		do
		# x is the leading package
		# y is the feature at OOo
		case "$x" in
			startup-notification)	y="libsn"	;;
			openldap)	y="ldap"	;;
			libart_lgpl23)	y="libart"	;;
			gconf)	y="lockdown"	;;
			gtk+)	y="gtk" ;;
			arts)	y="kde" ;;
			*)	y="$x"	;;
		esac

		# leading package installed
		if pkginstalled $x; then
			echo "--enable-$y"
			# special tweakery
			case "$x" in
			#	arts)
			#		export QTLIB=$QTDIR/lib
			#		;;
				openldap)
					echo "--with-openldap"
					;;
				gtk)
					echo "--enable-atkbridge"       # does it exist?
					;;
			esac
		else
			echo "--disable-$y"
			# special tweakery
			case "$x" in
				gconf)	echo "--disable-gnome-vfs"
					;;
				gtk)	echo "--disable-atkbridge"	# does it exist?
					;;
			esac
		fi
	done

	#pkginstalled mozilla &&
	#	echo "--with-system-mozilla" ||
	#  --with-firefox          Use Firefox instead of Mozilla Suite for building.
        #                  Only honoured with --with-system-mozilla
	#  --with-xulrunner        Use XULRunner instead of Mozilla Suite for building.
        #                  Only honoured with --with-system-mozilla
	#	--with-mozilla-version=1.7.5 (is our version supported? [REVIEW]
		echo "--disable-mozilla"
		echo "--with-system-mozilla=no"

	#  --with-stlport4
		echo "--without-stlport4"


	#--enable-evolution2
		echo "--disable-evolution2"

	#	echo "--with-system-mspack"

	# disable support for sound using portaudio/sndfile
		echo "--disable-pasf"

	# mdb support, TODO: get it consistent to what was given on $confopt
	#--with-system-mdbtools
		echo "--disable-access"

	# Use xsltproc at buildtime, even when java is available [REVIEW]
  		echo "--enable-xsltproc"

	# WebDAV support
		echo "--disable-neon"

	#if pkginstalled nas; then
	#       	echo "--with-system-nas"
	#	export LDFLAGS=-L`pkgprefix libdir libx11`
	#	export CFLAGS=-I/usr/X11/include
	#	export CPPFLAGS=-I/usr/X11/include
	#fi
		echo "--without-nas"


	#if [[ $libdir == *lib64 ]]; then
	#	echo "--enable-64bit-libs=yes"
	#fi

	# Java support
	#
	#if [ "$JAVA_HOME" ] && pkginstalled apache-ant; then
	#	echo "--with-java=java"
	#	echo "--with-jdk-home=$root$JAVA_HOME"
	#	echo "--with-ant-home=$root/$( pkgprefix apache-ant )"
	#	echo "--with-db-jar=$root$( pkgprefix libdir java-dirtree )/libdb_java-4.3.jar"
	#	# Only if using GCJ! [REVIEW]
	#	#echo "--enable-gcjaot"
	#	#--with-java-target-version
	#	#--with-java=gij
	#else
	# don't look for java things on the system if we don't have Java
	cat <<-EOT
	--with-system-hsqldb=no
	--with-system-beanshell=no
	--with-system-xml-apis=no
	--with-system-xerces=no
	--with-system-xalan=no
	EOT
	#fi

	#  --with-beanshell-jar=JARFILE   Specify path to jarfile manually
	#  --with-db-jar=JARFILE
	#  --with-xml-apis-jar=JARFILE   Specify path to jarfile manually
	#  --with-system-xalan     Use xalan already on system
	#  --with-xalan-jar=JARFILE   Specify path to jarfile manually
	#  --with-serializer-jar=JARFILE   Specify path to jarfile manually

	} >> distro-configs/OpenSDE.conf

	cp distro-configs/OpenSDE{,64}.conf
}