#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# sort by lang
$OO_TOOLSDIR/piece/sort-l10n $piece $ooo_build_tag $DESTDIR

# put the rest into the common file list
$OO_TOOLSDIR/piece/merge-file-lists "files-$piece.txt" $DESTDIR/gid_*
# FIXME: remove files from the top dir; they are common for all localizations
#        and must be included in the main package (postprocess)
for file in main_transform.xsl idxcaption.xsl idxcontent.xsl ; do
    if test `du --block-size=1 --apparent-size $DESTDIR$OO_INSTDIR/basis$VERSION/help/$file | cut -f1` -eq \
            `du --block-size=1 --apparent-size $OO_TOOLSDIR/../src/helpcontent2/$file | cut -f1` ; then
	remove_file "files-$piece.txt" $OO_INSTDIR/basis$VERSION/help/$file
    else
	echo "Error: The file \"$file\" has changed in the sources"
	echo "       Please, update the prebuilt variant in $OO_TOOLSDIR/../src/helpcontent2"
	exit 1;
    fi
done
# FIXME: hid.lst will be in testtool package (built in ?)
remove_file "files-$piece.txt" $OO_INSTDIR/basis$VERSION/program/hid.lst
# non-wanted mess
remove_dir "files-$piece.txt" $OO_INSTDIR/ure

# FIXME: is a generic solution possible?
# remove the duplicated .zip archives
rm -rf $DESTDIR$OO_SOLVERDIR/pck/*.zip

# move the stuff to /usr/share when enabled
if test "$OOO_BUILD_NOARCH" = 'YES' ; then
    $OO_TOOLSDIR/piece/install-l10n-helper $piece $ooo_build_tag "$DESTDIR" files-$piece-*.txt
    $OO_TOOLSDIR/piece/install-devel-helper $piece $ooo_build_tag
fi
