#!/bin/bash

set -e

#PATH=/opt/gnu/lm32-gcc-4.5.3/bin:$PATH
PATH=/opt/gnu/riscv-11.2/bin:$PATH

CALL_DIR=$PWD

if [ -z "$1" ]; then
    echo "$0: Target not defined!"
    exit 1
fi
if [ $# -ne 2 ]; then
    echo "usage: $0 target"
    exit 1
fi

echo "build wrpc-sw"
cd "$1"

# Create .config (using defaults)
make "$2"_defconfig

# Build.
# Need access to vmebridge for vuart tool.
make DEFCONFIG_NAME="$2"_defconfig SUPPORT_CERN_VMEBRIDGE=y VMEBRIDGE=/opt/libvme SHELL=/bin/bash -j4

# Copy result
cd $CALL_DIR
cp "$1"/wrc.bram .
cp "$1"/wrc.mif .
cp "$1"/wrc.bin .
cp "$1"/wrc.elf .
