#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# Now do magic stuff to register the services - fully hacky (sadly).
export OO_BUILD_SERVICES=1
# avoid infinite recursion ;-)
export OO_BUILD_POST_PROCESS_ENABLE='NO'
# do not remove the already created file lists
export OO_BUILD_FILE_LISTS_ENABLE='NO'

# FIXME: replace the below hack with the solution suggested at
#        http://www.openoffice.org/issues/show_bug.cgi?id=94759
#        It obsoletes also patches/dev300/piece-jvmfwk.diff
# crazy hack to produce working jvmfwk3rc
cat <<EOT  >jvmfwk3rc
[Bootstrap]
UNO_JAVA_JFW_ENV_JREHOME=true
UNO_JAVA_JFW_ENV_CLASSPATH=true
UNO_JAVA_JFW_VENDOR_SETTINGS=file://$OO_INSTDIR/ure/share/misc/javavendors.xml
EOT
export JVMFWK_CONFIGFILE=file://`pwd`/jvmfwk3rc

# needed to register python components
export PYTHONPATH=$OO_INSTDIR/basis$VERSION/program

$OO_TOOLSDIR/piece/install-generic $piece $ooo_build_tag
# urgh - unbelievably nasty:
cp -a OpenOffice/gid_Starregistry_Services_Rdb_rdb/*/services.rdb \
    $DESTDIR$OO_INSTDIR/basis$VERSION/program/services.rdb
cp -a OpenOffice/gid_Starregistry_Services_Rdb_Ure_servicesrdb/*/services.rdb \
    $DESTDIR$OO_INSTDIR/ure/share/misc/services.rdb
# udpate the file list
if test -f "files-$piece.txt" ; then
    echo "$OO_INSTDIR/basis$VERSION/program/services.rdb" >>"files-$piece.txt"
    echo "$OO_INSTDIR/ure/share/misc/services.rdb" >>"files-$piece.txt"
fi

# FIXME: remove pythonloader.unorc
#        it has been already generated by bin/piece/file-list-ure
remove_file "files-$piece.txt" "$OO_INSTDIR/basis$VERSION/program/pythonloader.unorc"

# prune redundant files the scp2 likes to make for us
remove_file "files-$piece.txt" "$OO_INSTDIR/basis-link"
remove_file "files-$piece.txt" "$OO_INSTDIR/basis$VERSION/ure-link"

# no need for solver bits at this late stage
rm -Rf "$DESTDIR/$OO_INSTDIR/solver"
