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.6 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
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. THIRD_PARTY_DIR=$(realpath "$SCRIPT_BASEDIR/../../third_party")
  18. MINDINSIGHT_DIR=$(realpath "$SCRIPT_BASEDIR/../../mindinsight")
  19. BUILDDIR="$(dirname "$SCRIPT_BASEDIR")/build_securec"
  20. build_securec() {
  21. [ -n "$BUILDDIR" ] && rm -rf "$BUILDDIR"
  22. mkdir "$BUILDDIR"
  23. cd "$BUILDDIR" || exit
  24. if ! command -v cmake; then
  25. command cmake
  26. fi
  27. cmake ../..
  28. make
  29. }
  30. clean_securec() {
  31. [ -n "$BUILDDIR" ] && rm -rf "$BUILDDIR"
  32. }
  33. build_crc32() {
  34. DATAVISUAL_DIR=$(realpath "$SCRIPT_BASEDIR/../../mindinsight/datavisual")
  35. CRC32_SOURCE_DIR="$DATAVISUAL_DIR/utils/crc32"
  36. CRC32_OUTPUT_DIR="$DATAVISUAL_DIR/utils"
  37. CRC32_SO_FILE="crc32$(python3-config --extension-suffix)"
  38. cd "$CRC32_SOURCE_DIR" || exit
  39. if ! command -v c++; then
  40. command c++
  41. fi
  42. if command -v python3; then
  43. PYTHON=python3
  44. elif command -v python; then
  45. PYTHON=python
  46. else
  47. command python3
  48. fi
  49. if ! "$PYTHON" -c 'import sys; assert sys.version_info >= (3, 7)' &>/dev/null; then
  50. echo "Python 3.7 or higher is required. You are running $("$PYTHON" -V)"
  51. exit 1
  52. fi
  53. rm -f "$CRC32_SOURCE_DIR/$CRC32_SO_FILE"
  54. rm -f "$CRC32_OUTPUT_DIR/$CRC32_SO_FILE"
  55. read -ra PYBIND11_INCLUDES <<< "$($PYTHON -m pybind11 --includes)"
  56. if [ ! -n "${PYBIND11_INCLUDES[0]}" ]; then
  57. echo "pybind11 is required"
  58. exit 1
  59. fi
  60. c++ -O2 -O3 -shared -std=c++11 -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 \
  61. -Wno-maybe-uninitialized -Wno-unused-parameter -Wall -Wl,-z,relro,-z,now,-z,noexecstack \
  62. -I"$MINDINSIGHT_DIR" -I"$THIRD_PARTY_DIR" "${PYBIND11_INCLUDES[0]}" "${PYBIND11_INCLUDES[1]}" \
  63. -o "$CRC32_SO_FILE" crc32.cc "$BUILDDIR/libsecurec.a"
  64. if [ ! -f "$CRC32_SO_FILE" ]; then
  65. echo "$CRC32_SO_FILE file does not exist, build failed"
  66. exit 1
  67. fi
  68. mv "$CRC32_SO_FILE" "$CRC32_OUTPUT_DIR"
  69. }
  70. build_securec
  71. build_crc32
  72. clean_securec