#!/bin/bash

# check variables, like all scripts herein do
WRS_SCRIPT_NAME=$(basename $0)
if [ -z "$WRS_BASE_DIR" ]; then
    echo "$0: Plesae set WRS_BASE_DIR" >& 2
    exit 1
fi
. ${WRS_BASE_DIR}/scripts/wrs_functions

wrs_check_vars WRS_OUTPUT_DIR WRS_DOWNLOAD_DIR CROSS_COMPILE

wrs_echo "--- User space tools"

sourcedir="$WRS_BASE_DIR/../userspace"
installdir="$WRS_OUTPUT_DIR/images/wr"

# This time build is done in-place, but the output is a tree in images/wr.
# Some of the makefiles inside use 
export LINUX="$WRS_OUTPUT_DIR/build/linux-$KVER"

cd $sourcedir
make clean || wrs_die "Error cleaning user space"
make || wrs_die "Error building user space"

# mini-rpc is an external package, it has no wr-specific install
install -d $installdir/lib
install mini-rpc/*.a $installdir/lib

cd $sourcedir && make install WR_INSTALL_ROOT="$installdir"

