#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

custom_env="$OO_TOOLSDIR/piece/env-$piece"
if test -f $custom_env; then
   source $custom_env
   echo "merged custom environment: $custom_env"
fi

custom_unpack="$OO_TOOLSDIR/piece/unpack-$piece"
export GNUCP=cp
if test -f $custom_unpack; then
    echo "Invoke custom unpack: $custom_unpack"
    $custom_unpack $OO_TOOLSDIR/.. `pwd`
fi

$OO_TOOLSDIR/install-artwork $OO_TOOLSDIR/../src `pwd`

# drop --distro=Localize for now ...
$OO_TOOLSDIR/../patches/apply.pl $OO_TOOLSDIR/../patches/dev300 --pieces \
	--tag=$ooo_build_tag \
	--distro=$DISTRO --distro=Piece --distro=Binfilter \
	--distro=System --distro=Sdk --distro=Extensions \
	 `pwd` || exit 1;

dirs=`/bin/ls | grep -v -e 'applied_patches' -e 'solver'  | tr '\n' ':'`
perl $SOLARENV/bin/build.pl --subdirs:$dirs $EXTRA_BUILD_FLAGS $EXTRA_DMAKE_FLAGS || exit 1;
