#!/bin/bash

. ${HOME}/HARK-Board/cross_compile_buildroot.sh

BACKUP_DIR_NAME=`date +"build_%Y%m%d_%H%M%S_backuped"`
if [ -e "build" ]; then
  if [ -d "build" ]; then
    echo "Since the old build directory already existed,"
    echo "I moved the old directory to ${BACKUP_DIR_NAME}. (This was automatically backup)"
    mv build ${BACKUP_DIR_NAME}
  else
    echo "A conflict occurred between the existing file and the build directory name."
    echo "The file name existed as the 'build', but now it has been moved to ${BACKUP_DIR_NAME}."
    mv build ${BACKUP_DIR_NAME}
  fi
fi

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=Production -DCMAKE_INSTALL_PREFIX=/usr .. && make clean && make && make DESTDIR=${PKG_CONFIG_SYSROOT_DIR} install && make DESTDIR=${INSTALL_MOD_PATH} install

