#!/usr/bin/env bash
set -eu

SCRIPT_DIR=$(cd $(dirname $0);pwd)

if [ $# -lt 1 ]; then
  echo "usage: install.sh dest_ssp_dir"
  exit 1
else
  SSPDIR=$1
fi

install -p -m 0755 ${SCRIPT_DIR}/{prc_check.trb,prc_kernel.trb,prc_sym.def} ${SSPDIR}/arch/arm_m_gcc
install -p -m 0755 ${SCRIPT_DIR}/{alarm.trb,cyclic.trb,dataqueue.trb,eventflag.trb} ${SSPDIR}/extension
install -p -m 0755 ${SCRIPT_DIR}/{exception.trb,interrupt.trb,kernel.trb,kernel_api.def,kernel_check.trb,kernel_sym.def,task.trb} ${SSPDIR}/kernel
install -p -m 0755 ${SCRIPT_DIR}/{banner.trb,syssvc_sym.def} ${SSPDIR}/syssvc
install -p -m 0755 ${SCRIPT_DIR}/{target_check.trb,target_kernel.cfg,target_kernel.trb} ${SSPDIR}/target/cq_frk_fm3_gcc

(cd ${SSPDIR} && patch -p1 < ${SCRIPT_DIR}/ssp_ruby.patch)

exit 0
