#!/bin/bash

set -e
set -o pipefail

LOG_FILE="$PWD"/build

# Needs Vivado > 2019.1
. /opt/Xilinx/Vivado/2019.2/settings64.sh

echo "Build wr2rf"

# Copy wrpc
#cp wrc.bram repos/wr2rf-vme/dependencies/wrpc-sw-file/wrc.bram

cd hdl/syn/wr2rf_vme

# Temporary fixes on generated wrapper
for f in nonIQModInterp2FIR/Vivado/nonIQModInterp2FIR.v; do
    sed -i -e "s/_wrapper/_wrapper_unused/g" ../../../dependencies/$f
done

hdlmake         2>&1 | tee "${LOG_FILE}_hdlmake.log"
make files.tcl  2>&1 | tee "${LOG_FILE}_make_files.log"
vivado -mode tcl -source wr2rf_vme.tcl

git describe >> wr2rf_ver.txt
tar -cJf wr2rf.tar.xz *.rpt *.dcp *.bit wr2rf_ver.txt
cp wr2rf.tar.xz ../../..
cp wr2rf_ver.txt ../../..
