You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

crc32.sh 2.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # Copyright 2020 Huawei Technologies Co., Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -e
  16. SCRIPT_BASEDIR=$(realpath "$(dirname "$0")")
  17. build_crc32() {
  18. if ! command -v cmake > /dev/null; then
  19. command cmake
  20. fi
  21. if ! command -v c++ > /dev/null; then
  22. command c++
  23. fi
  24. if command -v python3 > /dev/null; then
  25. PYTHON=python3
  26. elif command -v python > /dev/null; then
  27. PYTHON=python
  28. else
  29. command python3
  30. fi
  31. if ! "$PYTHON" -c 'import sys; assert sys.version_info >= (3, 7)' > /dev/null; then
  32. echo "Python 3.7 or higher is required. You are running $("$PYTHON" -V)"
  33. exit 1
  34. fi
  35. PYBIND11_INCLUDES="$($PYTHON -m pybind11 --includes)"
  36. if [ ! -n "$PYBIND11_INCLUDES" ]; then
  37. echo "pybind11 is required"
  38. exit 1
  39. fi
  40. BUILDDIR="$(dirname "$SCRIPT_BASEDIR")/build_securec"
  41. [ -d "$BUILDDIR" ] && rm -rf "$BUILDDIR"
  42. mkdir "$BUILDDIR"
  43. cd "$BUILDDIR" || exit
  44. cmake ../..
  45. cmake --build .
  46. MINDINSIGHT_DIR=$(realpath "$SCRIPT_BASEDIR/../../mindinsight")
  47. THIRD_PARTY_DIR=$(realpath "$SCRIPT_BASEDIR/../../third_party")
  48. cd "$MINDINSIGHT_DIR/datavisual/utils" || exit
  49. CRC32_SO_FILE="crc32$(python3-config --extension-suffix)"
  50. rm -f "$CRC32_SO_FILE"
  51. SECUREC_LIB_FILE="$BUILDDIR/libsecurec.a"
  52. c++ -O2 -O3 -shared -std=c++11 -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 \
  53. -Wno-maybe-uninitialized -Wno-unused-parameter -Wall -Wl,-z,relro,-z,now,-z,noexecstack \
  54. -I"$MINDINSIGHT_DIR" -I"$THIRD_PARTY_DIR" $PYBIND11_INCLUDES \
  55. -o "$CRC32_SO_FILE" crc32/crc32.cc "$SECUREC_LIB_FILE"
  56. if [ ! -f "$CRC32_SO_FILE" ]; then
  57. echo "$CRC32_SO_FILE file does not exist, build failed"
  58. exit 1
  59. fi
  60. [ -d "$BUILDDIR" ] && rm -rf "$BUILDDIR"
  61. }
  62. build_crc32