darwin: Make nproc run in the docker instance

Darwin doesn't have an nproc command, so unless we run this in the docker
container, we won't be able to see how many cores we have. Additionally, this
fixes setup.sh to skip the inclusion of the j command, since Darwin doesn't run
a recent bash instance.

Change-Id: Ia6423a2da7500fb8337b05bc32fcc901a0ff247b
diff --git a/docker.mk b/docker.mk
index 3985c00..208e2cc 100644
--- a/docker.mk
+++ b/docker.mk
@@ -68,7 +68,7 @@
 			adduser $(shell id -u -n) docker; \
 			/etc/init.d/docker start; \
 			sudo -E -u $(shell id -u -n) /bin/bash -c "source build/setup.sh; m \
-			-j$(shell nproc) $*";'
+			-j$$(shell nproc) $*";'
 
 # Macro for running make target in arm64 docker image
 define docker-arm64-run
@@ -93,7 +93,7 @@
 	     useradd -m -e "" -s /bin/bash --gid $$(shell id -g) --uid $$(shell id -u) $$(shell id -u -n); \
 	     passwd -d $$(shell id -u -n); \
 	     echo "$$(shell id -u -n) ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers; \
-	     source build/setup.sh; m -j$(shell nproc) $2'
+	     source build/setup.sh; m -j$$(shell nproc) $2'
 endef
 
 # Test x86 docker ('m docker-test-docker')
diff --git a/setup.sh b/setup.sh
index c719dcb..4a4706a 100755
--- a/setup.sh
+++ b/setup.sh
@@ -98,54 +98,56 @@
     complete -F _mm mm
 fi
 
-unset JUMP_TARGETS
-declare -Ax JUMP_TARGETS
-JUMP_TARGETS[.]="."
-JUMP_TARGETS[board]="${ROOTDIR}/board"
-JUMP_TARGETS[top]="${ROOTDIR}"
-JUMP_TARGETS[rootdir]="${ROOTDIR}"
-JUMP_TARGETS[out]="${OUT}"
-JUMP_TARGETS[product]="${PRODUCT_OUT}"
-JUMP_TARGETS[host]="${HOST_OUT}"
-JUMP_TARGETS[root]="${ROOT_OUT}"
-JUMP_TARGETS[build]="${ROOTDIR}/build"
-JUMP_TARGETS[kernel]="${ROOTDIR}/linux-imx/"
-JUMP_TARGETS[uboot]="${ROOTDIR}/uboot-imx/"
+if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
+    unset JUMP_TARGETS
+    declare -Ax JUMP_TARGETS
+    JUMP_TARGETS[.]="."
+    JUMP_TARGETS[board]="${ROOTDIR}/board"
+    JUMP_TARGETS[top]="${ROOTDIR}"
+    JUMP_TARGETS[rootdir]="${ROOTDIR}"
+    JUMP_TARGETS[out]="${OUT}"
+    JUMP_TARGETS[product]="${PRODUCT_OUT}"
+    JUMP_TARGETS[host]="${HOST_OUT}"
+    JUMP_TARGETS[root]="${ROOT_OUT}"
+    JUMP_TARGETS[build]="${ROOTDIR}/build"
+    JUMP_TARGETS[kernel]="${ROOTDIR}/linux-imx/"
+    JUMP_TARGETS[uboot]="${ROOTDIR}/uboot-imx/"
 
-function j
-{
-    local target="$1"; shift
-
-    if [[ -z "${target}" ]]; then
-        cd "${ROOTDIR}"
-        return 0
-    fi
-
-    if [[ -z "${JUMP_TARGETS[$target]}" ]]; then
-        echo "Jump targets are:"
-        echo "${!JUMP_TARGETS[@]}"
-        return 1
-    fi
-
-    cd "${JUMP_TARGETS[$target]}"
-}
-
-if builtin complete >/dev/null 2>/dev/null; then
-    function _j_targets
+    function j
     {
-        echo "${!JUMP_TARGETS[@]}"
-    }
+        local target="$1"; shift
 
-    function _j
-    {
-        local cur=${COMP_WORDS[COMP_CWORD]}
-        COMPREPLY=()
-        if [[ $COMP_CWORD -eq 1 ]]; then
-            COMPREPLY=( $(compgen -W "$(_j_targets)" $cur) )
+        if [[ -z "${target}" ]]; then
+            cd "${ROOTDIR}"
+            return 0
         fi
+
+        if [[ -z "${JUMP_TARGETS[$target]}" ]]; then
+            echo "Jump targets are:"
+            echo "${!JUMP_TARGETS[@]}"
+            return 1
+        fi
+
+        cd "${JUMP_TARGETS[$target]}"
     }
 
-    complete -F _j j
+    if builtin complete >/dev/null 2>/dev/null; then
+        function _j_targets
+        {
+            echo "${!JUMP_TARGETS[@]}"
+        }
+
+        function _j
+        {
+            local cur=${COMP_WORDS[COMP_CWORD]}
+            COMPREPLY=()
+            if [[ $COMP_CWORD -eq 1 ]]; then
+                COMPREPLY=( $(compgen -W "$(_j_targets)" $cur) )
+            fi
+        }
+
+        complete -F _j j
+    fi
 fi
 
 echo ========================================