mnn 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/..; pwd)
  4. src=${root}/src
  5. third_party=${root}/third_party
  6. tools=${root}/tools
  7. identifier=mnn
  8. bold() {
  9. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  10. }
  11. git_sync() {
  12. mkdir -p "${third_party}"
  13. if [ -d "${third_party}/${1}" ]; then
  14. git -C "${third_party}/${1}" pull --quiet --prune
  15. else
  16. git -C "${third_party}" clone --quiet --recursive ${2} ${1}
  17. fi
  18. git -C "${third_party}/${1}" submodule sync --quiet
  19. git -C "${third_party}/${1}" submodule update --quiet --init --recursive
  20. }
  21. clean() {
  22. bold "mnn clean"
  23. rm -rf ${third_party}/${identifier}
  24. }
  25. sync() {
  26. bold "mnn sync"
  27. git_sync flatbuffers https://github.com/google/flatbuffers.git
  28. git_sync mnn https://github.com/alibaba/MNN.git
  29. }
  30. install() {
  31. bold "mnn install"
  32. case "$(uname)" in
  33. "Linux")
  34. [ -n "$(which cmake)" ] || sudo apt install -y cmake
  35. ;;
  36. "Darwin")
  37. brew list cmake > /dev/null 2>&1 || brew install cmake > /dev/null
  38. ;;
  39. esac
  40. pushd "${third_party}/flatbuffers" > /dev/null
  41. cmake -G "Unix Makefiles" . > /dev/null
  42. make > /dev/null
  43. popd > /dev/null
  44. }
  45. schema() {
  46. bold "mnn schema"
  47. ${third_party}/flatbuffers/flatc --no-js-exports --gen-all -o ${tools}/. --js ${third_party}/mnn/schema/default/MNN.fbs
  48. mv ${tools}/MNN_generated.js ${src}/mnn-schema.js
  49. cat <<EOT >> ${src}/mnn-schema.js
  50. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  51. module.exports = MNN;
  52. }
  53. EOT
  54. }
  55. while [ "$#" != 0 ]; do
  56. command="$1" && shift
  57. case "${command}" in
  58. "clean") clean;;
  59. "sync") sync;;
  60. "install") install;;
  61. "schema") schema;;
  62. esac
  63. done