gollvm: check/vet shell as part of initial config setup

Test to make sure that $SHELL is set and works properly as part
of the cmake setup for gollvm.

Updates golang/go#38728.

Change-Id: I63491e08b5f1a9c7823e0ba8af72626df983dde8
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/240558
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/README.md b/README.md
index 0d5785f..ccb448a 100644
--- a/README.md
+++ b/README.md
@@ -85,6 +85,8 @@
 The Gollvm compiler driver defaults to using the gold linker when linking Go programs.  If some other linker is desired, this can be accomplished by passing "-DGOLLVM_DEFAULT_LINKER=<variant>" when running cmake. Note that this default can still be overridden on the command line using the "-fuse-ld" option.
+Gollvm's cmake rules expect a valid value for the SHELL environment variable; if not set, a default shell of /bin/bash will be used.
 ## Installing gollvm <a name="installing"></a>
 A gollvm installation will contain 'llvm-goc' (the compiler driver), the libgo standard Go libraries, and the standard Go tools ("go", "vet", "cgo", etc).
diff --git a/cmake/modules/GoVars.cmake b/cmake/modules/GoVars.cmake
index 178e656..4579e70 100644
--- a/cmake/modules/GoVars.cmake
+++ b/cmake/modules/GoVars.cmake
@@ -31,9 +31,19 @@
   message(SEND_ERROR "Arch ${llarch} not yet supported")
-# FIXME: write code to insure that this is set and that the shell
-# in question behaves properly.
+# We need a working shell. 
 set(shell $ENV{SHELL})
+if(shell STREQUAL "")
+set(shell "/bin/bash")
+execute_process(COMMAND "${shell}" "-c" "echo foo" OUTPUT_VARIABLE echofoo)
+if(echofoo STREQUAL "")
+message(FATAL_ERROR "fatal: shell ${shell} missing or not functional")
+string(STRIP "${echofoo}" stripechofoo)
+if(NOT stripechofoo STREQUAL "foo")
+message(FATAL_ERROR "fatal: shell ${shell} missing or not functional")
 # FIXME: write cmake to discover awk, test to make sure it works
 set(awk "/usr/bin/awk")