#!/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 "--- PTP daemon (ppsi repository as a submodule)"

# checkout, in case the user didn't do that
cd ${WRS_BASE_DIR}/..
git submodule init -q
git submodule update -q
cd userspace/ppsi
make clean

# we need LINUX and CROSS_COMPILE. The latter is there for sure
if [ "x$LINUX" == "x" ]; then
    export LINUX="$WRS_OUTPUT_DIR/build/linux-$KVER"
fi


make clean
make wrs_defconfig
make CROSS_COMPILE=$CROSS_COMPILE || wrs_die "Failure building PPSi"
make -C tools  CROSS_COMPILE=$CROSS_COMPILE || \
    wrs_die "Failure building PPSi tools"
install -d "$WRS_OUTPUT_DIR/images/wr/bin"
install ppsi tools/ptpdump "$WRS_OUTPUT_DIR/images/wr/bin"

