#!/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:

if test -n "$USE_GCC" ; then
    # GCC-based compilers
    CC='/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc64-bgq-linux-gcc -Wno-unused'
    CXX='/bgsys/drivers/ppcfloor/gnu-linux/bin/powerpc64-bgq-linux-g++ -Wno-unused'
elif test -n "$USE_CLANG" ; then
    # CLANG-based compilers
    CC='bgclang -fno-integrated-as -Wno-unused -U__GNUC__'
    CXX='bgclang++ -fno-integrated-as -Wno-unused -U__GNUC__'
else
    # XLC-based compilers
    CC='bgxlc_r -qarch=qp -qtune=qp'
    CXX='bgxlC_r -qarch=qp -qtune=qp'
fi
export CC  # vanilla target C compiler
export CXX  # vanilla target C++ compiler

# 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)

if test -n "$USE_GCC" ; then
    # GCC-based compilers
    MPI_CC='mpicc'
elif test -n "$USE_CLANG" ; then
    # CLANG-based compilers
    MPI_CC='env MPICH_CC=bgclang mpicc'
else
    # XLC-based compilers
    MPI_CC='mpixlc -qarch=qp -qtune=qp'
fi
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='mpirun -np %N %C' ; export MPIRUN_CMD  # launch command for MPI jobs

# system batch submit command:
# The following MPIRUN_CMD is specific to the BG/Q system at Argonne 
# Leadership Computing Facility (ALCF).
MPIRUN_CMD='qsub -q default -t 1:00:00 -n %N %C' ; export MPIRUN_CMD  # launch command for MPI jobs
MPIRUN_CMD_BATCH='runjob -n %N : %C' ; export MPIRUN_CMD_BATCH  # launch command for MPI inside the batch script

EXTRA_CONFIGURE_ARGS='--with-max-pthreads-per-node=64 --disable-udp --disable-amudp'
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --disable-aligned-segments"
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --enable-pshm --enable-pshm-gheap"
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --with-segment-mmap-max=12G"
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --with-feature-list=os_bgq"
if test -z "$USE_GCC" ; then
EXTRA_CONFIGURE_ARGS="$EXTRA_CONFIGURE_ARGS --disable-tls"
fi
export EXTRA_CONFIGURE_ARGS  # misc configure args to pass

# 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='powerpc64-bgq-linux'

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

CROSS_CACHE_LINE_BYTES=128; export CROSS_CACHE_LINE_BYTES

# 4. 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='0' ; 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


SRCDIR=`dirname $0`
if test ! -f "$SRCDIR/configure" ; then
  echo "ERROR: The $0 script should be placed in the same directory as the configure script before execution"
  exit 1
fi
# Detect the build host machine type
HOST_ARG=`echo "$@" | grep -e --host`
HOST_APPEND=
if test "$HOST_ARG" = ""; then
  oldCC_FOR_BUILD="$CC_FOR_BUILD"
  oldHOST_CC="$HOST_CC"
  oldCC="$CC"
  CC_FOR_BUILD=
  HOST_CC=
  CC=
  if test "$HOST_ID" = ""; then
    HOST_ID=`$SRCDIR/config-aux/config.guess`
  fi
  if test "$HOST_ID" = ""; then
    echo 'ERROR: failed to auto-detect build host. Please run with --host=machineid to identify the host machine running this script'
    exit 1
  else
    HOST_APPEND="--host=$HOST_ID"
  fi
  CC_FOR_BUILD="$oldCC_FOR_BUILD"
  HOST_CC="$oldHOST_CC"
  CC="$oldCC"
fi
# Now that everything is setup, run the actual configure script
$SRCDIR/configure --enable-cross-compile $HOST_APPEND --build=$TARGET_ID --target=$TARGET_ID --program-prefix='' $EXTRA_CONFIGURE_ARGS "$@"
