#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# do we need to do anything?
test "$OOO_BUILD_NOARCH" != 'YES' && exit 0

# ugly hack to move solver to /usr/share
mkdir -p $DESTDIR$OO_INSTDIR_SHARE
mv $DESTDIR$OO_INSTDIR/solver $DESTDIR$OO_INSTDIR_SHARE

# file list for the devel stuff
echo "%dir $OO_INSTDIR_SHARE" >files-$piece-devel.txt
for dir in `find $DESTDIR$OO_INSTDIR_SHARE/solver -type d | sed "s|$DESTDIR||" | grep -v "$OO_INSTDIR_SHARE/solver/noarch"|sort` ; do
    echo "%dir $dir" >>files-$piece-devel.txt
done
find $DESTDIR$OO_INSTDIR_SHARE/solver -type f | sed "s|$DESTDIR||" | grep -v "$OO_INSTDIR_SHARE/solver/noarch"|sort >>files-$piece-devel.txt
# install the list for link-to-ooo-home script if not empty; top dir is always mentioned
if test `cat files-$piece-devel.txt | wc -l` -gt 1 ; then
    cp files-$piece-devel.txt $DESTDIR$OO_INSTDIR_SHARE/
    echo "$OO_INSTDIR_SHARE/files-$piece-devel.txt" >>files-$piece-devel.txt
fi

# file list for the prebuilt stuff if any
rm -f files-$piece-prebuilt.txt
for dir in `find $DESTDIR$OO_INSTDIR_SHARE/solver -type d | sed "s|$DESTDIR||" | grep "$OO_INSTDIR_SHARE/solver/noarch"|sort` ; do
    echo "%dir $dir" >>files-$piece-prebuilt.txt
done
find $DESTDIR$OO_INSTDIR_SHARE/solver -type f | sed "s|$DESTDIR||" | grep "$OO_INSTDIR_SHARE/solver/noarch"|sort >>files-$piece-prebuilt.txt
# install the list for link-to-ooo-home script if not empty
if test `cat files-$piece-prebuilt.txt | wc -l` -gt 1 ; then
    cp files-$piece-prebuilt.txt $DESTDIR$OO_INSTDIR_SHARE/
    echo "$OO_INSTDIR_SHARE/files-$piece-prebuilt.txt" >>files-$piece-prebuilt.txt
fi
