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

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

# build a configurator
if [ ! -d cfg-1.8.0 ]; then
  if [ ! -f cfg-1.8.0.tar.gz ]; then
    wget http://www.toppers.jp/download.cgi/cfg-1.8.0.tar.gz
  fi
  mkdir cfg-1.8.0
  tar xvf cfg-1.8.0.tar.gz -C cfg-1.8.0 --strip-components=2
fi

cd cfg-1.8.0
./configure --with-libraries=/usr/lib/x86_64-linux-gnu/
make
cd ..

# get SSP kernel source files
if [ ! -f ssp-1.3.0.tar.gz ]; then
  wget http://www.toppers.jp/download.cgi/ssp-1.3.0.tar.gz
fi
tar xvf ssp-1.3.0.tar.gz -C ${SCRIPT_DIR}  --strip-components=2

# build a SSP kernel
cd ${SCRIPT_DIR}
ln -s ../cfg-1.8.0 cfg
mkdir build
cd build
perl ../configure -T at91skyeye_gcc
make depend
make

exit 0
