Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # Copyright 2017 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. #      http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16.  
  17. # Installation script for CLIF.
  18. # Adapted from https://github.com/google/clif/blob/master/INSTALL.sh
  19. #
  20. # Usage:
  21. #   ./install_clif.sh [PYTHON_EXECUTABLE] [PYTHON_LIBRARY]
  22. #
  23. #   PYTHON_EXECUTABLE - python executable to use (default: python)
  24. #   PYTHON_LIBRARY - overrides the python library to use
  25.  
  26. set -e
  27.  
  28. TOOLS_DIR="$PWD"
  29. CLIF_DIR="$PWD/clif"
  30.  
  31. PYTHON="python"
  32. if [ -n "$1" ]; then
  33.   PYTHON="$1"
  34. fi
  35. PYTHON_EXECUTABLE="$(which $PYTHON)"
  36. PYTHON_PIP="$PYTHON_EXECUTABLE -m pip"
  37. PYTHON_ENV=$($PYTHON_EXECUTABLE -c "import sys; print(sys.prefix)")
  38.  
  39. PV=$($PYTHON_EXECUTABLE -c "import sys; print(sys.version_info[0])")
  40. if [[ $PV == 3 ]]; then
  41.  
  42.   PYTHON_LIBRARY=$($PYTHON_EXECUTABLE $TOOLS_DIR/find_python_library.py)
  43.   if [ -n "$2" ]; then
  44.     PYTHON_LIBRARY="$2"
  45.   fi
  46.   if [ ! -f "$PYTHON_LIBRARY" ]; then
  47.     echo "Python library $PYTHON_LIBRARY could not be found."
  48.     echo "Please specify the python library as an argument to $0"
  49.     echo "e.g. $0 /usr/bin/python3 /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1"
  50.     exit 1
  51.   fi
  52.  
  53.     PYTHON_INCLUDE_DIR=$($PYTHON_EXECUTABLE -c 'from sysconfig import get_paths; print(get_paths()["include"])')
  54.     CMAKE_PY_FLAGS=(-DPYTHON_INCLUDE_DIR="$PYTHON_INCLUDE_DIR" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" -DPYTHON_LIBRARY="$PYTHON_LIBRARY")
  55. fi
  56.  
  57. ####################################################################
  58. # Ensure CMake is installed (needs 3.5+)
  59. ####################################################################
  60. CV=$(cmake --version | head -1 | cut -f3 -d\ ); CV=(${CV//./ })
  61. if (( CV[0] < 3 || CV[0] == 3 && CV[1] < 5 )); then
  62.   echo "Install CMake version 3.5+"
  63.   exit 1
  64. fi
  65.  
  66. ####################################################################
  67. # Ensure Google protobuf C++ library is installed (needs v3.2+).
  68. ####################################################################
  69. if [ -d "$TOOLS_DIR/protobuf" ]; then
  70.   export PATH="$TOOLS_DIR/protobuf/bin:$PATH"
  71.   export PKG_CONFIG_PATH="$TOOLS_DIR/protobuf:$PKG_CONFIG_PATH"
  72. fi
  73. PV=$(protoc --version | cut -f2 -d\ ); PV=(${PV//./ })
  74. if (( PV[0] < 3 || PV[0] == 3 && PV[1] < 2 )); then
  75.   echo "Install Google protobuf version 3.2+"
  76.   exit 1
  77. fi
  78. PROTOBUF_PREFIX_PATH="$(dirname "$(dirname "$(which protoc)")")"
  79. PYCLIF_CFLAGS="$(pkg-config --cflags protobuf)"
  80. PYCLIF_LDFLAGS="$(pkg-config --libs protobuf)"
  81.  
  82. ####################################################################
  83. # Set C++ system include directory and standard library
  84. ####################################################################
  85.  
  86. CXX_SYSTEM_INCLUDE_DIR_FLAGS=
  87. if [ "`uname`" == "Darwin" ]; then
  88.   PYCLIF_CFLAGS="${PYCLIF_CFLAGS} -stdlib=libc++"
  89.   XCODE_TOOLCHAIN_DIR="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain"
  90.   COMMAND_LINE_TOOLCHAIN_DIR="/Library/Developer/CommandLineTools"
  91.   if [ -d "$XCODE_TOOLCHAIN_DIR" ]; then
  92.     CXX_SYSTEM_INCLUDE_DIR="${XCODE_TOOLCHAIN_DIR}/usr/include/c++/v1"
  93.   elif [ -d "$COMMAND_LINE_TOOLCHAIN_DIR" ]; then
  94.     CXX_SYSTEM_INCLUDE_DIR="${COMMAND_LINE_TOOLCHAIN_DIR}/usr/include/c++/v1"
  95.   else
  96.     echo "Could not find toolchain directory!"
  97.     echo "Install xcode command line tools, e.g. xcode-select --install"
  98.     exit 1
  99.   fi
  100.   CXX_SYSTEM_INCLUDE_DIR_FLAGS="-DCXX_SYSTEM_INCLUDE_DIR=$CXX_SYSTEM_INCLUDE_DIR"
  101. fi
  102.  
  103. ######################################################################
  104.  
  105. CLIF_GIT="-b pykaldi https://github.com/pykaldi/clif.git"
  106. LLVM_DIR="$CLIF_DIR/../clif_backend"
  107. BUILD_DIR="$LLVM_DIR/build_matcher"
  108.  
  109. if [ ! -d "$CLIF_DIR" ]; then
  110.   git clone $CLIF_GIT $CLIF_DIR
  111. else
  112.   echo "Destination $CLIF_DIR already exists."
  113. fi
  114.  
  115. cd "$CLIF_DIR"
  116. git pull
  117.  
  118. declare -a CMAKE_G_FLAGS
  119. declare -a MAKE_PARALLELISM
  120. if which ninja; then
  121.   CMAKE_G_FLAGS=(-G Ninja)
  122.   MAKE_OR_NINJA="ninja"
  123.   MAKE_PARALLELISM=()  # Ninja does this on its own.
  124.   # ninja can run a dozen huge ld processes at once during install without
  125.   # this flag... grinding a 12 core workstation with "only" 32GiB to a halt.
  126.   # linking and installing should be I/O bound anyways.
  127.   MAKE_INSTALL_PARALLELISM=(-j 2)
  128.   echo "Using ninja for the clif backend build."
  129. else
  130.   CMAKE_G_FLAGS=()  # The default generates a Makefile.
  131.   MAKE_OR_NINJA="make"
  132.   MAKE_PARALLELISM=(-j 4)
  133.   if [[ -r /proc/cpuinfo ]]; then
  134.     N_CPUS="$(cat /proc/cpuinfo | grep -c ^processor)"
  135.     [[ "$N_CPUS" -gt 0 ]] && MAKE_PARALLELISM=(-j $N_CPUS)
  136.     MAKE_INSTALL_PARALLELISM=(${MAKE_PARALLELISM[@]})
  137.   fi
  138.   echo "Using make.  Build will take a long time.  Consider installing ninja."
  139. fi
  140.  
  141. # Download, build and install LLVM and Clang (needs a specific revision).
  142.  
  143. mkdir -p "$LLVM_DIR"
  144. cd "$LLVM_DIR"
  145. svn co https://llvm.org/svn/llvm-project/llvm/trunk@307315 llvm
  146. cd llvm/tools
  147. svn co https://llvm.org/svn/llvm-project/cfe/trunk@307315 clang
  148. ln -s -f -n "$CLIF_DIR/clif" clif
  149.  
  150. # Build and install the CLIF backend.  Our backend is part of the llvm build.
  151. # NOTE: To speed up, we build only for X86. If you need it for a different
  152. # arch, change it to your arch, or just remove the =X86 line below.
  153.  
  154. mkdir -p "$BUILD_DIR"
  155. cd "$BUILD_DIR"
  156. cmake -DCMAKE_INSTALL_PREFIX="$PYTHON_ENV/clang" \
  157.       -DCMAKE_PREFIX_PATH="$PROTOBUF_PREFIX_PATH" \
  158.       -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=true \
  159.       -DLLVM_INSTALL_TOOLCHAIN_ONLY=true \
  160.       -DCMAKE_BUILD_TYPE=Release \
  161.       -DLLVM_BUILD_DOCS=false \
  162.       -DLLVM_TARGETS_TO_BUILD=X86 \
  163.       "${CMAKE_PY_FLAGS[@]}" \
  164.       "${CXX_SYSTEM_INCLUDE_DIR_FLAGS}" \
  165.       "${CMAKE_G_FLAGS[@]}" "$LLVM_DIR/llvm"
  166. "$MAKE_OR_NINJA" "${MAKE_PARALLELISM[@]}" clif-matcher clif_python_utils_proto_util
  167. "$MAKE_OR_NINJA" "${MAKE_INSTALL_PARALLELISM[@]}" install
  168.  
  169. # Get back to the CLIF Python directory and have pip run setup.py.
  170.  
  171. cd "$CLIF_DIR"
  172. # Grab the python compiled .proto
  173. cp "$BUILD_DIR/tools/clif/protos/ast_pb2.py" clif/protos/
  174. # Grab CLIF generated wrapper implementation for proto_util.
  175. cp "$BUILD_DIR/tools/clif/python/utils/proto_util.cc" clif/python/utils/
  176. cp "$BUILD_DIR/tools/clif/python/utils/proto_util.h" clif/python/utils/
  177. cp "$BUILD_DIR/tools/clif/python/utils/proto_util.init.cc" clif/python/utils/
  178.  
  179. ####################################################################
  180. # Check write access to Python package dir
  181. ####################################################################
  182. PYTHON_PACKAGE_DIR=$($PYTHON_EXECUTABLE -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
  183. if [ ! -w $PYTHON_PACKAGE_DIR ]; then
  184.   echo ""
  185.   echo "*** PYTHON_PACKAGE_DIR=$PYTHON_PACKAGE_DIR"
  186.   echo "*** Writing to PYTHON_PACKAGE_DIR requires sudo access."
  187.   echo "*** Run the following command to install pyclif Python package."
  188.   echo ""
  189.   echo "sudo CFLAGS=\"$PYCLIF_CFLAGS\" LDFLAGS=\"$PYCLIF_LDFLAGS\" $PYTHON_PIP install $CLIF_DIR"
  190.   exit 1
  191. else
  192.   CFLAGS="$PYCLIF_CFLAGS" LDFLAGS="$PYCLIF_LDFLAGS" $PYTHON_PIP install .
  193. fi
  194.  
  195. echo "Done installing CLIF."
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top