echo "RUNNING SETUP_CHANNEL FOR THE GASNET CHANNEL"

#
# NOTE: This file is sourced from the setup_device with the current working
# directory set to the top-level build directory.
#

#
# Variables of interest...
#
# $with_device - device name and arguments
# $device_name - name of the device
# $device_args - contains name of channel select plus an channel args
# $channel_name - name of the channel
# $master_top_srcdir - top-level source directory
# $master_top_builddir - top-level build directory
# $ac_configure_args - all arguments passed to configure
#

file=${master_top_srcdir}/src/mpid/${device_name}/channels/gasnet/setup_channel.args
if test -f ${file} ; then
    . ${file}
else
    echo "Error: ${file} not found"
    exit 1
fi

pathlist=""
pathlist="$pathlist src/mpid/${device_name}/channels/${channel_name}/include"
for path in $pathlist ; do
    CPPFLAGS="$CPPFLAGS -I${master_top_builddir}/${path}"
    CPPFLAGS="$CPPFLAGS -I${master_top_srcdir}/${path}"
done

##
## Use the sock implementation found in the common directory
##
#file=${master_top_srcdir}/src/mpid/common/sock/setup
#if test -f $file ; then
#    echo "sourcing $file"
#    . $file
#fi

# include gasnet
if test -n "$gasnet_dir" ; then
  CPPFLAGS="$CPPFLAGS -I${gasnet_dir}/include -I${gasnet_dir}/include/${gasnet_conduit}-conduit"
  LDFLAGS="$LDFLAGS -L${gasnet_dir}/lib"
fi
if test -n "$gasnet_include_dir" ; then
  CPPFLAGS="$CPPFLAGS -I${gasnet_include_dir} -I${gasnet_include_dir}/${gasnet_conduit}-conduit"
fi
if test -n "$gasnet_lib_dir" ; then
  LDFLAGS="$LDFLAGS -L${gasnet_lib_dir}"
fi
LIBS="$LIBS -lgasnet-${gasnet_conduit}-seq"

case "$gasnet_conduit" in
  gm )
    if test -n "$gm_dir" ; then
      LDFLAGS="$LDFLAGS -L${gm_dir}/lib"
      CPPFLAGS="$CPPFLAGS -I${gm_dir}/include"
    fi
    if test -n "$gm_include_dir" ; then
      CPPFLAGS="$CPPFLAGS -I${gm_include_dir}"
    fi
    if test -n "$gm_lib_dir" ; then
      LDFLAGS="$LDFLAGS -L${gm_lib_dir}"
    fi
    LIBS="$LIBS -lgm"
    ;;
  lapi )
    CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE"
    LIBS="$LIBS -llapi_r -lpthread"
    ;;
  "" )
    echo "You must specify a gasnet conduit using --with-gasnet-conduit="
    exit 1
    ;;
esac

case "$CC" in
  *pgcc* )
    CFLAGS="${CFLAGS} -Masmkeyword"
    ;;
esac
