Browse Source

[Pal] pal_loader: Detect PAL_HOST if `make` is unavailable

In certain cases (e.g, a container runtime for production), `make` and `gcc`
programs may be unavailable. In this case, detect `PAL_HOST` based on the
base name of libpal.
Jia Zhang 4 years ago
parent
commit
fd0c564cf9
1 changed files with 22 additions and 1 deletions
  1. 22 1
      Runtime/pal_loader

+ 22 - 1
Runtime/pal_loader

@@ -18,7 +18,28 @@ do
 done
 
 RUNTIME_DIR=$(/usr/bin/dirname $(readlink -f ${BASH_SOURCE[0]}))
-PAL_HOST=$(/usr/bin/make --no-print-directory --quiet -f $RUNTIME_DIR/../Pal/src/Makefile.Host print_host 2>&1)
+if [ -z $PAL_HOST ]; then
+    if [ ! -f /usr/bin/make ]; then
+        libpal="$RUNTIME_DIR/libpal-*.so"
+        libpal="$(echo -n $libpal)"
+        libpal="${libpal//$RUNTIME_DIR\//}"
+        if [ "$libpal" = 'libpal-*.so' ]; then
+            echo "Unable to detect PAL_HOST. Please install the make program."
+            exit 1
+        fi
+
+        array=($libpal)
+        if [ ${#array[@]} -ne 1 ]; then
+            echo "Multiple libpal detected ($libpal). Please explicitly set the environment variable PAL_HOST."
+            exit 1
+        fi
+
+        PAL_HOST="${libpal%.so}"
+        PAL_HOST="${PAL_HOST#libpal-}"
+    else
+        PAL_HOST=$(/usr/bin/make --no-print-directory --quiet -f $RUNTIME_DIR/../Pal/src/Makefile.Host print_host 2>&1)
+    fi
+fi
 
 MANIFEST=
 PREFIX=