In ./configure, only ask about jemalloc when running on Linux.

Also add functions to test whether we're running on Linux or macOS, and convert
every check over to them.

Fixes #6869
Change: 144761341
diff --git a/configure b/configure
index 87ef6e9..c755ee1 100755
--- a/configure
+++ b/configure
@@ -9,6 +9,23 @@
 popd > /dev/null
 
 PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
+
+function is_linux() {
+  if [[ "${PLATFORM}" == "linux" ]]; then
+    true
+  else
+    false
+  fi
+}
+
+function is_macos() {
+  if [[ "${PLATFORM}" == "darwin" ]]; then
+    true
+  else
+    false
+  fi
+}
+
 function is_windows() {
   # On windows, the shell script is actually running in msys
   if [[ "${PLATFORM}" =~ msys_nt* ]]; then
@@ -65,16 +82,20 @@
   TF_NEED_OPENCL=0
 fi
 
-while [ "$TF_NEED_JEMALLOC" == "" ]; do
-  read -p "Do you wish to use jemalloc as the malloc implementation? "\
-"(Linux only) [Y/n] " INPUT
-  case $INPUT in
-    [Yy]* ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
-    [Nn]* ) echo "jemalloc disabled on Linux"; TF_NEED_JEMALLOC=0;;
-    "" ) echo "jemalloc enabled on Linux"; TF_NEED_JEMALLOC=1;;
-    * ) echo "Invalid selection: " $INPUT;;
-  esac
-done
+if is_linux; then
+  while [ "$TF_NEED_JEMALLOC" == "" ]; do
+    read -p "Do you wish to use jemalloc as the malloc implementation? [Y/n] "\
+      INPUT
+    case $INPUT in
+      [Yy]* ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
+      [Nn]* ) echo "jemalloc disabled"; TF_NEED_JEMALLOC=0;;
+      "" ) echo "jemalloc enabled"; TF_NEED_JEMALLOC=1;;
+      * ) echo "Invalid selection: " $INPUT;;
+    esac
+  done
+else
+  TF_NEED_JEMALLOC=0
+fi
 
 if [ "$TF_NEED_JEMALLOC" == "1" ]; then
   sed -i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
@@ -99,7 +120,7 @@
 if [ "$TF_NEED_GCP" == "1" ]; then
   ## Verify that libcurl header files are available.
   # Only check Linux, since on MacOS the header files are installed with XCode.
-  if [[ $(uname -a) =~ Linux ]] && [[ ! -f "/usr/include/curl/curl.h" ]]; then
+  if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
     echo "ERROR: It appears that the development version of libcurl is not "\
 "available. Please install the libcurl3-dev package."
     exit 1
@@ -226,8 +247,6 @@
 done
 
 # Find out where the CUDA toolkit is installed
-OSNAME=`uname -s`
-
 while true; do
   # Configure the Cuda SDK version to use.
   if [ -z "$TF_CUDA_VERSION" ]; then
@@ -259,9 +278,9 @@
 
   if is_windows; then
     CUDA_RT_LIB_PATH="lib/x64/cudart.lib"
-  elif [ "$OSNAME" == "Linux" ]; then
+  elif is_linux; then
     CUDA_RT_LIB_PATH="lib64/libcudart.so${TF_CUDA_EXT}"
-  elif [ "$OSNAME" == "Darwin" ]; then
+  elif is_macos; then
     CUDA_RT_LIB_PATH="lib/libcudart${TF_CUDA_EXT}.dylib"
   fi
 
@@ -307,10 +326,10 @@
     if is_windows; then
       cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
       cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/lib/x64/cudnn.lib"
-    elif [ "$OSNAME" == "Linux" ]; then
+    elif is_linux; then
       cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib64/libcudnn.so"
       cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.so"
-    elif [ "$OSNAME" == "Darwin" ]; then
+    elif is_macos; then
       cudnn_lib_path="${CUDNN_INSTALL_PATH}/lib/libcudnn.dylib"
       cudnn_alt_lib_path="${CUDNN_INSTALL_PATH}/libcudnn.dylib"
     fi
@@ -337,7 +356,7 @@
       echo "libcudnn.dylib resolves to libcudnn${TF_CUDNN_EXT}"
     fi
   else
-    if [ "$OSNAME" == "Darwin" ]; then
+    if is_macos; then
       TF_CUDNN_EXT=".${TF_CUDNN_VERSION}.dylib"
     else
       TF_CUDNN_EXT=".$TF_CUDNN_VERSION"
@@ -347,10 +366,10 @@
   if is_windows; then
     CUDA_DNN_LIB_PATH="lib/x64/cudnn.lib"
     CUDA_DNN_LIB_ALT_PATH="lib/x64/cudnn.lib"
-  elif [ "$OSNAME" == "Linux" ]; then
+  elif is_linux; then
     CUDA_DNN_LIB_PATH="lib64/libcudnn.so${TF_CUDNN_EXT}"
     CUDA_DNN_LIB_ALT_PATH="libcudnn.so${TF_CUDNN_EXT}"
-  elif [ "$OSNAME" == "Darwin" ]; then
+  elif is_macos; then
     CUDA_DNN_LIB_PATH="lib/libcudnn${TF_CUDNN_EXT}"
     CUDA_DNN_LIB_ALT_PATH="libcudnn${TF_CUDNN_EXT}"
   fi
@@ -361,7 +380,7 @@
     break
   fi
 
-  if [ "$OSNAME" == "Linux" ]; then
+  if is_linux; then
     CUDNN_PATH_FROM_LDCONFIG="$(ldconfig -p | sed -n 's/.*libcudnn.so .* => \(.*\)/\1/p')"
     if [ -e "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}" ]; then
       export TF_CUDNN_VERSION
@@ -372,7 +391,7 @@
   echo "Invalid path to cuDNN ${CUDNN_VERSION} toolkit. Neither of the following two files can be found:"
   echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_PATH}"
   echo "${CUDNN_INSTALL_PATH}/${CUDA_DNN_LIB_ALT_PATH}"
-  if [ "$OSNAME" == "Linux" ]; then
+  if is_linux; then
     echo "${CUDNN_PATH_FROM_LDCONFIG}${TF_CUDNN_EXT}"
   fi
 
@@ -499,7 +518,7 @@
     fi
   fi
 
-  if [ "$OSNAME" == "Linux" ]; then
+  if is_linux; then
     SYCL_RT_LIB_PATH="lib/libComputeCpp.so"
   fi