#!/bin/bash

if [[ "`printenv |grep -w CRAY |wc -l`" -gt 1 ]]; then
   if [ -z "$CXX" ]; then
      export CXX=`which CC`
   fi
   if [ -z "$CC" ]; then
      export CC=`which cc`
   fi
   if [ -z "$FC" ]; then
      export FC=`which ftn`
   fi
else
   module -t list 2>&1 | grep -q "^rocm"
   if [ $? -eq 1 ]; then
     echo "rocm module is not loaded"
     echo "loading default rocm module"
     module load rocm
   fi
fi

module list
which amdflang
ftn --version
REPO_DIR="$(dirname "$(dirname "$(readlink -fm "$0")")")"
cd ${REPO_DIR}/HIPFort/roctx
rm -f roctx_hipfort roctx_standalone *.o *.mod
make
echo "=== Testing hipfort version ==="
./roctx_hipfort
echo "=== Testing standalone version ==="
./roctx_standalone
rm -f roctx_hipfort roctx_standalone *.o *.mod
