pal_loader 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env bash
  2. while :
  3. do
  4. case "$1" in
  5. "SGX")
  6. SGX=1
  7. export SGX
  8. ;;
  9. "GDB")
  10. GDB=1
  11. ;;
  12. *)
  13. break
  14. ;;
  15. esac
  16. shift
  17. done
  18. RUNTIME_DIR=$(/usr/bin/dirname $(readlink -f ${BASH_SOURCE[0]}))
  19. if [ -z $PAL_HOST ]; then
  20. if [ ! -f /usr/bin/make ]; then
  21. libpal="$RUNTIME_DIR/libpal-*.so"
  22. libpal="$(echo -n $libpal)"
  23. libpal="${libpal//$RUNTIME_DIR\//}"
  24. if [ "$libpal" = 'libpal-*.so' ]; then
  25. echo "Unable to detect PAL_HOST. Please install the make program."
  26. exit 1
  27. fi
  28. array=($libpal)
  29. if [ ${#array[@]} -ne 1 ]; then
  30. echo "Multiple libpal detected ($libpal). Please explicitly set the environment variable PAL_HOST."
  31. exit 1
  32. fi
  33. PAL_HOST="${libpal%.so}"
  34. PAL_HOST="${PAL_HOST#libpal-}"
  35. else
  36. PAL_HOST=$(/usr/bin/make --no-print-directory --quiet -f "$RUNTIME_DIR/../Scripts/Makefile.configs" print_host 2>&1)
  37. fi
  38. fi
  39. MANIFEST=
  40. PREFIX=
  41. PAL_CMD=$RUNTIME_DIR/pal-$PAL_HOST
  42. if [ "$GDB" == "1" ]; then
  43. GDB=$RUNTIME_DIR/pal_gdb-$PAL_HOST
  44. if [ ! -f $GDB ]; then
  45. GDB="/usr/bin/gdb"
  46. fi
  47. fi
  48. if [ "$GDB" != "" ] && [ "$GDB" != "0" ]; then
  49. if [ -n "$INSIDE_EMACS" ]; then
  50. GDB="$GDB -i=mi"
  51. fi
  52. PREFIX="$GDB --args"
  53. fi
  54. if [ "$PERF" == "1" ]; then
  55. PREFIX="perf stat"
  56. fi
  57. if [ "$MEMUSG" == "1" ]; then
  58. PREFIX="$RUNTIME_DIR/../Scripts/memusg"
  59. fi
  60. while [ "$1" != "" ];
  61. do
  62. if [ "$MANIFEST" == "" ]; then
  63. MANIFEST=$1
  64. shift
  65. continue
  66. fi
  67. break
  68. done
  69. if [ ! -f "$PAL_CMD" ]; then
  70. echo "$PAL_CMD is not built, or security mode is not supported"
  71. exit 1
  72. fi
  73. exec $PREFIX $PAL_CMD $MANIFEST "$@"