mnn 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. set -e
  3. pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
  4. bold() {
  5. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  6. }
  7. clean() {
  8. bold "mnn clean"
  9. rm -rf "./third_party/src/mnn"
  10. }
  11. sync() {
  12. bold "mnn sync"
  13. [ -d "./third_party/src/mnn" ] || git clone --quiet https://github.com/alibaba/MNN.git "./third_party/src/mnn"
  14. pushd "./third_party/src/mnn" > /dev/null
  15. git pull --quiet --prune
  16. popd > /dev/null
  17. }
  18. schema() {
  19. bold "mnn schema"
  20. case "${OSTYPE}" in
  21. linux*)
  22. flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
  23. flatc_dir=./third_party/bin/flatbuffers/${flatc_version}
  24. if [ ! -f "${flatc_dir}/flatc" ]; then
  25. mkdir -p "${flatc_dir}"
  26. pushd "${flatc_dir}" > /dev/null
  27. curl -sL https://github.com/google/flatbuffers/archive/${flatc_version}.tar.gz | tar zx --strip-components 1
  28. cmake -G "Unix Makefiles" . &> /dev/null
  29. make > /dev/null
  30. popd > /dev/null
  31. fi
  32. export PATH=${flatc_dir}:${PATH}
  33. ;;
  34. darwin*)
  35. brew list flatbuffers > /dev/null 2>&1 || brew install flatbuffers > /dev/null
  36. ;;
  37. msys*)
  38. flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
  39. flatc_dir=./third_party/bin/flatbuffers/${flatc_version}
  40. if [ ! -f "${flatc_dir}/flatc.exe" ]; then
  41. mkdir -p "${flatc_dir}"
  42. pushd "${flatc_dir}" > /dev/null
  43. curl -sL -O https://github.com/google/flatbuffers/releases/download/${flatc_version}/flatc_windows.zip
  44. unzip flatc_windows.zip > /dev/null
  45. popd > /dev/null
  46. fi
  47. flatc=${flatc_dir}/flatc.exe
  48. ;;
  49. esac
  50. [[ $(grep -U $'\x0D' ./src/mnn-schema.js) ]] && crlf=1
  51. flatc --no-js-exports --gen-all -o ./tools/. --js ./third_party/src/mnn/schema/default/MNN.fbs
  52. mv ./tools/MNN_generated.js ./src/mnn-schema.js
  53. cat <<EOT >> ./src/mnn-schema.js
  54. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  55. module.exports = MNN;
  56. }
  57. EOT
  58. if [[ -n ${crlf} ]]; then
  59. unix2dos --quiet --newfile ./src/mnn-schema.js ./src/mnn-schema.js
  60. fi
  61. }
  62. while [ "$#" != 0 ]; do
  63. command="$1" && shift
  64. case "${command}" in
  65. "clean") clean;;
  66. "sync") sync;;
  67. "schema") schema;;
  68. esac
  69. done