#!/usr/bin/env bash

cross_log=cross_build_$$.log
enabled_log=${LOG}

# if the target architecture is different from the host,
# TARGET_ARCH must be set to one of ['ia32', 'x86_64', 'arm', 'mips']
# export TARGET_ARCH='arm'

export CROSS=${CROSS_COMPILE}
export CC=${CROSS}gcc
export AR=${CROSS}ar
export RANLIB=${CROSS}ranlib
export CFLAGS=${CROSS_CFLAGS}
export LDFLAGS=${CROSS_LDFLAGS}
gcc_version=$(${CC} --version)
log_filename="${cross_log%.*}"
echo Using $gcc_version
rm -rf build_*
if [ "x$enabled_log" == "x1" ]; then
  echo Compiler CC: $CC > $cross_log
  echo Compiler CFLAGS: $CFLAGS >> $cross_log
  echo Compiler LDFLAGS: $LDFLAGS >> $cross_log
  time ./do >> $cross_log 2>&1
  mv cjdroute ${log_filename}_cjdroute
else
  echo Compiler CC: $CC
  echo Compiler CFLAGS: $CFLAGS
  echo Compiler LDFLAGS: $LDFLAGS
  time ./do
fi
