#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# install mono GAC, pkgconfig file, ...
rm -f files-mono.txt
$OO_TOOLSDIR/install-mono

# pyuno subpackages
$OO_TOOLSDIR/piece/merge-file-lists "files-pyuno.txt" $DESTDIR/gid_Module_Optional_Pyuno

# merge the rest already now, so we could extract the mono stuff
$OO_TOOLSDIR/piece/merge-file-lists "files-$piece.txt" $DESTDIR/gid_*

# finalize mono subpackage
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/basis$VERSION/program/cli_.*.dll
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/basis$VERSION/program/cli_.*.dll.config
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/basis$VERSION/program/policy.*.cli_.*.dll
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/ure/lib/cli_.*.dll
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/ure/lib/cli_.*.dll.config
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/ure/lib/policy.*.cli_.*.dll
mv_file_between_flists files-mono.txt files-$piece.txt $OO_INSTDIR/ure/lib/libcli_.*.so
add_used_directories files-mono.txt files-$piece.txt

# install the internal stlport if available; it might be included in the solver from bootstrap
if test -f $OO_INSTDIR/solver/lib/libstlport_gcc.so ; then
    cp $OO_INSTDIR/solver/lib/libstlport_gcc.so $DESTDIR$OO_INSTDIR/ure/lib
    echo "$OO_INSTDIR/ure/lib/libstlport_gcc.so" >>files-$piece.txt
fi

# install the hacky script to regenerate UNO cache with broken extensions
mkdir $DESTDIR/usr/sbin
install -m 755 $OO_TOOLSDIR/unopkg-regenerate-cache $DESTDIR/usr/sbin
echo /usr/sbin/unopkg-regenerate-cache >>files-$piece.txt

# FIXME: generate pythonloader.unorc to be ready for python components registration
#        it might be generated in postprocess togeter with other profiles but it is too late
#        might be fixed by the planed scp2-split
# IMPORTANT: the other variant generated in postprocess is explicitely removed in bin/piece/post-inst-postprocess
cat <<EOT  >$DESTDIR$OO_INSTDIR/basis$VERSION/program/pythonloader.unorc
[Bootstrap]
PYUNO_LOADER_PYTHONPATH=\$ORIGIN
EOT
echo "%config $OO_INSTDIR/basis$VERSION/program/pythonloader.unorc" >>files-pyuno.txt

exit 0
