#!/bin/bash

piece=$1
ooo_build_tag=$2
gid_dir=$3

source $OO_TOOLSDIR/piece/sys-setup

echo "Sorting the lang stuff ..."

for lang in $OO_LANGS ; do
    echo -n "   processing $lang... "
    lang=`echo $lang | sed "s|-|_|g"`
    files_found=
    filelist=files-$piece-$lang.txt
    rm -f $filelist
    for list in  $gid_dir/gid_Module_Langpack*$lang ; do
	test -f $list || continue;
	files_found=1
	# add to the lang specific file-list
	cat $list >>$filelist.new
	# remove the old files from the $DESTDIR but not from the system solver (prebuilt l10n stuff)
	test "$gid_dir" = "$DESTDIR" && rm $list
    done
    # clean up the file list
    if test -f $filelist.new  ; then
	echo "%dir $OO_INSTDIR" >>$filelist.new
	sort -u $filelist.new >$filelist
	rm -f $filelist.new
    fi
    test -n "$files_found" && echo "done" || echo "nothing to do"
done
