#!/bin/sh

# This is an automatically-generated cross-configuration setup script

################################################
# Usage Instructions: 
#  1. fill in the following values to point to the target and host compilers:

# NOTE: this relies on module-established PATH setting to automatically 
# select the GCC or PGI-based MPI compilers, based on which PrgEnv is currently loaded
# The same PrgEnv *must* be loaded when building and using the GASNet install
CC='cc'  # vanilla target C compiler
CXX='CC' # vanilla target C++ compiler

export CC
export CXX

XTPE_INFO_MESSAGE_OFF=1 ; export XTPE_INFO_MESSAGE_OFF  # magic variable to disable Cray cc's target INFO warning

# Host C compiler
# NOTE: you may need to set GCC_EXEC_PREFIX=/usr/bin/
# to get the correct assembler if gcc is your host compiler
HOST_CC='/usr/bin/gcc' ; export HOST_CC
HOST_CFLAGS='-g -O2' ; export HOST_CFLAGS

# Host C++ compiler - required by Titanium, not required for UPC or GASNet
HOST_CXX='/usr/bin/g++' ; export HOST_CXX
HOST_CXXFLAGS='' ; export HOST_CXXFLAGS

# Optional additional settings: (see configure --help for complete list)

MPI_CC="$CC" ; export MPI_CC     # MPI-enabled C compiler
#MPI_CFLAGS='' ; export MPI_CFLAGS  # flags for MPI_CC
MPI_LIBS='' ; export MPI_LIBS      # libs for linking with MPI_CC
MPIRUN_CMD="${APRUN:-aprun} -n %N %C" ; export MPIRUN_CMD  # launch command for MPI jobs
EXTRA_CONFIGURE_ARGS="--disable-auto-conduit-detect --enable-smp --enable-mpi --enable-gemini --enable-ofi=probe --with-ofi-provider=gni --disable-aligned-segments --enable-pshm --disable-pshm-posix --enable-pshm-xpmem --enable-throttle-poll"
# OS string for test harness purposes
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --with-feature-list=os_cnl"
# minimal backtracing support
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --enable-backtrace-execinfo"
if test -x /usr/bin/gdb ; then # Enable gdb probe if it appears to be present
  EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --enable-backtrace-gdb"
fi

# Work around bug 3480 if a PrgEnv environment module with major version >= 6 is loaded
if test -n `echo ":$LOADEDMODULES" | grep ':PrgEnv-[a-z]*/[6-9]' 2>/dev/null`; then
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --enable-bug3480-workaround"
fi

# 2. Fill in the canonical target machine type. You can usually obtain this
#   by running config-aux/config.guess on the target machine
TARGET_ID='x86_64-cnl-linux-gnu'

# 3. Optionally cross-compile and run the detect-cachesz.c utility and
#    fill in the value below and uncomment.  If not set the default is platform-dependent.
CACHE_LINE_BYTES=64; export CACHE_LINE_BYTES

# 4. Review the automatically-detected settings below and make corrections as necessary.

# 5. Place this output script in your top-level source directory and run it,
#   passing it any additional configure arguments as usual (see configure --help).

################################################
# AUTOMATICALLY DETECTED SETTINGS:


# Whether the system has a working version of anonymous mmap

CROSS_HAVE_MMAP='1' ; export CROSS_HAVE_MMAP

# The system VM page size (ie mmap granularity, even if swapping is not supported)

CROSS_PAGESIZE='4096' ; export CROSS_PAGESIZE

# Does the system stack grow up?

CROSS_STACK_GROWS_UP='0' ; export CROSS_STACK_GROWS_UP

# Is char a signed type?

CROSS_CHAR_IS_SIGNED='1' ; export CROSS_CHAR_IS_SIGNED

# Basic primitive C type sizes (in bytes)

CROSS_SIZEOF_CHAR='1' ; export CROSS_SIZEOF_CHAR
CROSS_SIZEOF_SHORT='2' ; export CROSS_SIZEOF_SHORT
CROSS_SIZEOF_INT='4' ; export CROSS_SIZEOF_INT
CROSS_SIZEOF_LONG='8' ; export CROSS_SIZEOF_LONG
CROSS_SIZEOF_LONG_LONG='8' ; export CROSS_SIZEOF_LONG_LONG
CROSS_SIZEOF_VOID_P='8' ; export CROSS_SIZEOF_VOID_P
CROSS_SIZEOF_SIZE_T='8' ; export CROSS_SIZEOF_SIZE_T
CROSS_SIZEOF_PTRDIFF_T='8' ; export CROSS_SIZEOF_PTRDIFF_T

# System signal values

CROSS_SIGHUP='1' ; export CROSS_SIGHUP
CROSS_SIGINT='2' ; export CROSS_SIGINT
CROSS_SIGQUIT='3' ; export CROSS_SIGQUIT
CROSS_SIGKILL='9' ; export CROSS_SIGKILL
CROSS_SIGTERM='15' ; export CROSS_SIGTERM
CROSS_SIGUSR1='10' ; export CROSS_SIGUSR1

# Find source directory

if test -z "$SRCDIR" || test ! -f "$SRCDIR/configure" ; then
  SRCDIR=`dirname $0`
fi
if test ! -f "$SRCDIR/configure" ; then
  echo "ERROR: Source directory not found. Either set \$SRCDIR=/path/to/src or copy/link the `basename $0` script to the same directory as the configure script"
  exit 1
fi

# Detect the build+host machine type
HOST_APPEND=
for sys in host build; do
  SYS_ARG=`echo "$@" | grep -i -e --$sys`
  if test -z "$SYS_ARG"; then
    if test -z "$HOST_ID"; then
      HOST_ID=`env CC= HOST_CC= CC_FOR_BUILD= $SRCDIR/config-aux/config.guess`
      if test -z "$HOST_ID"; then
        echo 'ERROR: failed to auto-detect build host. Please run with --host=machineid --build=machineid to identify the host machine running this script'
        exit 1
      fi
    fi
    HOST_APPEND="$HOST_APPEND --$sys=$HOST_ID"
  fi
done
# Now that everything is setup, run the actual configure script
$SRCDIR/configure --enable-cross-compile$HOST_APPEND --target=$TARGET_ID $EXTRA_CONFIGURE_ARGS "$@"
