github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/prepare.sh (about) 1 #!/bin/bash 2 3 # Copyright (C) 2017 go-nebulas authors 4 # 5 # This file is part of the go-nebulas library. 6 # 7 # the go-nebulas library is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 12 # the go-nebulas library is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>. 19 20 CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 21 #CUR_DIR="$( pwd )" 22 OS="$(uname -s)" 23 24 25 if [ "$OS" = "Darwin" ]; then 26 LOGICAL_CPU=$(sysctl -n hw.ncpu) 27 DYLIB="dylib" 28 else 29 LOGICAL_CPU=$(cat /proc/cpuinfo |grep "processor"|wc -l) 30 DYLIB="so" 31 fi 32 33 PARALLEL=$LOGICAL_CPU 34 NEED_CHECK_INSTALL=false 35 36 mkdir -p $CUR_DIR/lib 37 git submodule update --init 38 39 install_system_tools() { 40 if [ "$OS" = "Darwin" ]; then 41 if ! hash brew 2>/dev/null; then 42 echo "install brew for macOS" 43 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 44 fi 45 fi 46 47 if ! hash unzip 2>/dev/null; then 48 case $OS in 49 'Linux') 50 sudo apt-get install -y unzip 51 ;; 52 'Darwin') 53 brew install unzip 54 ;; 55 *) ;; 56 esac 57 fi 58 check_script_run unzip 59 60 if ! hash autoreconf 2>/dev/null; then 61 case $OS in 62 'Linux') 63 sudo apt-get install -y autoconf 64 ;; 65 'Darwin') 66 brew install autoconf 67 ;; 68 *) ;; 69 esac 70 fi 71 check_script_run autoconf 72 73 if ! hash libtool 2>/dev/null; then 74 case $OS in 75 'Linux') 76 sudo apt-get install -y libtool-bin 77 ;; 78 'Darwin') 79 brew install libtool 80 ;; 81 *) ;; 82 esac 83 fi 84 check_script_run libtool 85 } 86 87 check_script_run() { 88 if [ $? -ne 0 ]; then 89 echo "$1 install failed. Please check environment!" 90 exit 1 91 fi 92 } 93 94 check_install() { 95 if $NEED_CHECK_INSTALL; then 96 if [ "$OS" = "Linux" ]; then 97 result=`ldconfig -p | grep -c $1` 98 else 99 result=`brew list | grep -c $1` 100 fi 101 return `test $result -ne 0` 102 else 103 return 1 104 fi 105 } 106 107 build_with_cmake(){ 108 check_install $1 109 if [ $? -eq 0 ]; then 110 # has been installed in system, skip make and install 111 echo "$1 has installed" 112 return 113 fi 114 115 cd $CUR_DIR/3rd_party/$1 116 build="build.tmp" 117 if [ -d $build ]; then 118 rm -rf $build 119 fi 120 mkdir $build 121 cd $build 122 123 params=("$@") 124 flags=${params[@]:1} 125 flagsStr=`echo $flags` 126 cmake -DCMAKE_MODULE_PATH=$CUR_DIR/lib/lib/cmake -DCMAKE_LIBRARY_PATH=$CUR_DIR/lib/lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$CUR_DIR/lib/ -DRelease=1 ../ $flagsStr 127 make -j$PARALLEL && make install && make clean 128 cd ../ && rm -rf $build 129 } 130 131 build_with_configure(){ 132 check_install $1 133 if [ $? -eq 0 ]; then 134 # has been installed in system, skip make and install 135 return 136 fi 137 138 cd $CUR_DIR/3rd_party/$1 139 ./configure --prefix=$CUR_DIR/lib/ 140 make -j$PARALLEL && make install && make clean 141 } 142 143 build_with_make(){ 144 check_install $1 145 if [ $? -eq 0 ]; then 146 # has been installed in system, skip make and install 147 return 148 fi 149 150 cd $CUR_DIR/3rd_party/$1 151 make -j$PARALLEL && make install PREFIX=$CUR_DIR/lib/ 152 make clean 153 } 154 155 # V1 >= V2 156 function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } 157 158 check_install_cmake() { 159 #check if cmake has been installed 160 if hash cmake 2>/dev/null; then 161 version=$(cmake --version|grep version|awk '{print $3}') 162 #echo "check cmake installed $version" 163 if version_ge $version "3.12.2"; then 164 return 165 fi 166 fi 167 168 if [ ! -d $CUR_DIR/3rd_party/cmake-3.12.2 ]; then 169 cd $CUR_DIR/3rd_party/ 170 tar -xf cmake-3.12.2.tar.gz 171 fi 172 173 if [ ! -f $CUR_DIR/lib/bin/cmake ]; then 174 cd $CUR_DIR/3rd_party/cmake-3.12.2/ 175 ./bootstrap --prefix=$CUR_DIR/lib --parallel=$PARALLEL && make -j$PARALLEL && make install 176 fi 177 178 check_script_run cmake 179 export PATH=$CUR_DIR/lib/bin:$PATH 180 } 181 182 check_install_llvm() { 183 cd $CUR_DIR/3rd_party 184 LLVM_VERSION=6.0.1 185 unzip_llvm_tar(){ 186 if [ ! -d $1-$LLVM_VERSION.src ]; then 187 tar -xf $1-$LLVM_VERSION.src.tar.xz 188 fi 189 } 190 unzip_llvm_tar llvm 191 unzip_llvm_tar cfe 192 unzip_llvm_tar clang-tools-extra 193 unzip_llvm_tar compiler-rt 194 unzip_llvm_tar libcxx 195 unzip_llvm_tar libcxxabi 196 unzip_llvm_tar libunwind 197 unzip_llvm_tar lld 198 199 if [ ! -d $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/tools/clang ]; then 200 ln -s $CUR_DIR/3rd_party/cfe-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/tools/clang 201 ln -s $CUR_DIR/3rd_party/lld-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/tools/lld 202 ln -s $CUR_DIR/3rd_party/clang-tools-extra-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/tools/clang/tools/extra 203 ln -s $CUR_DIR/3rd_party/compiler-rt-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/projects/compiler-rt 204 ln -s $CUR_DIR/3rd_party/libcxx-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/projects/libcxx 205 ln -s $CUR_DIR/3rd_party/libcxxabi-$LLVM_VERSION.src $CUR_DIR/3rd_party/llvm-$LLVM_VERSION.src/projects/libcxxabi 206 fi 207 208 cd $CUR_DIR/3rd_party 209 if [ ! -f $CUR_DIR/lib_llvm/bin/clang ]; then 210 mkdir llvm-build 211 cd llvm-build 212 cmake -DCMAKE_CXX_COMPILER=g++ -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$CUR_DIR/lib_llvm/ ../llvm-$LLVM_VERSION.src 213 make -j$PARALLEL && make install 214 cd .. 215 fi 216 217 if [ ! -e $CUR_DIR/lib/lib/libc++.$DYLIB ]; then 218 mkdir -p $CUR_DIR/lib/lib 219 cp -Rf $CUR_DIR/lib_llvm/lib/libc++* $CUR_DIR/lib/lib/ 220 fi 221 222 check_script_run llvm 223 224 export LD_LIBRARY_PATH=$CUR_DIR/lib/lib:$CUR_DIR/lib_llvm/lib:$LD_LIBRARY_PATH 225 export PATH=$CUR_DIR/lib_llvm/bin:$PATH 226 export CXX=$CUR_DIR/lib_llvm/bin/clang++ 227 export CC=$CUR_DIR/lib_llvm/bin/clang 228 } 229 230 check_install_boost() { 231 cd $CUR_DIR/3rd_party 232 if [ ! -d "boost_1_67_0" ]; then 233 tar -zxvf boost_1_67_0.tar.gz 234 fi 235 if [ ! -e $CUR_DIR/lib/lib/libboost_system.$DYLIB ]; then 236 cd boost_1_67_0 237 ./bootstrap.sh --with-toolset=clang --prefix=$CUR_DIR/lib/ 238 ./b2 clean 239 ./b2 toolset=clang --with-date_time --with-graph --with-program_options --with-filesystem --with-system --with-thread -j$PARALLEL 240 ./b2 install toolset=clang --with-date_time --with-graph --with-program_options --with-filesystem --with-system --with-thread --prefix=$CUR_DIR/lib/ 241 fi 242 check_script_run boost 243 } 244 245 check_install_gflags() { 246 if [ ! -d $CUR_DIR/3rd_party/gflags ]; then 247 cd $CUR_DIR/3rd_party 248 git clone -b v2.2.1 https://github.com/gflags/gflags.git 249 fi 250 251 if [ ! -e $CUR_DIR/lib/lib/libgflags.$DYLIB ]; then 252 #cp $CUR_DIR/3rd_party/build_option_bak/CMakeLists.txt-gflags $CUR_DIR/3rd_party/gflags/CMakeLists.txt 253 build_with_cmake gflags -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_SHARED_LIBS=true 254 fi 255 check_script_run gflags 256 } 257 258 check_install_glog() { 259 if [ ! -e $CUR_DIR/lib/lib/libglog.$DYLIB ]; then 260 #cp $CUR_DIR/3rd_party/build_option_bak/CMakeLists.txt-glog $CUR_DIR/3rd_party/glog/CMakeLists.txt 261 build_with_cmake glog -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_SHARED_LIBS=true 262 fi 263 check_script_run glog 264 } 265 266 check_install_gtest() { 267 if [ ! -e $CUR_DIR/lib/lib/libgtest.$DYLIB ]; then 268 #cp $CUR_DIR/3rd_party/build_option_bak/CMakeList.txt-googletest $CUR_DIR/3rd_party/googletest/CMakeLists.txt 269 build_with_cmake googletest -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_SHARED_LIBS=true 270 fi 271 check_script_run gtest 272 } 273 274 check_install_ff() { 275 if [ ! -e $CUR_DIR/lib/lib/libff_functionflow.$DYLIB ]; then 276 build_with_cmake fflib 277 fi 278 check_script_run ff 279 } 280 281 check_install_snappy() { 282 if [ ! -e $CUR_DIR/lib/lib/libsnappy.$DYLIB ]; then 283 #cd $CUR_DIR/3rd_party/snappy && cp ../snappy.patch ./ && git apply snappy.patch 284 # cd $CUR_DIR/3rd_party/snappy 285 # turn off unittest 286 build_with_cmake snappy -DBUILD_SHARED_LIBS=true -DSNAPPY_BUILD_TESTS=false 287 fi 288 check_script_run snappy 289 } 290 291 check_install_zlib() { 292 if [ ! -e $CUR_DIR/lib/lib/libz.$DYLIB ]; then 293 build_with_configure zlib 294 cd $CUR_DIR/3rd_party/zlib 295 git checkout . 296 fi 297 check_script_run zlib 298 } 299 300 check_install_zstd() { 301 if [ ! -e $CUR_DIR/lib/lib/libzstd.$DYLIB ]; then 302 build_with_make zstd 303 fi 304 check_script_run zstd 305 } 306 307 check_install_bzlib() { 308 if [ ! -e $CUR_DIR/lib/lib/libbz2.$DYLIB ]; then 309 cd $CUR_DIR/3rd_party/bzip2-1.0.6 310 cp -f ../Makefile-libbz2_$DYLIB ./ 311 make -j$PARALLEL -f Makefile-libbz2_$DYLIB && make -f Makefile-libbz2_$DYLIB install PREFIX=$CUR_DIR/lib/ && make -f Makefile-libbz2_$DYLIB clean 312 rm -rf Makefile-libbz2_$DYLIB 313 fi 314 check_script_run bzlib 315 } 316 317 check_install_lz4() { 318 if [ ! -e $CUR_DIR/lib/lib/liblz4.$DYLIB ]; then 319 build_with_make lz4 320 fi 321 check_script_run lz4 322 } 323 324 check_install_rocksdb() { 325 #check if rocksdb has been installed in system 326 check_install rocksdb 327 if [ $? -eq 0 ]; then 328 return 329 fi 330 331 check_install_snappy 332 check_install_zlib 333 # check_install_zstd 334 # check_install_bzlib 335 check_install_lz4 336 337 if [ ! -e $CUR_DIR/lib/lib/librocksdb.$DYLIB ]; then 338 # cp $CUR_DIR/3rd_party/build_option_bak/CMakeLists.txt-rocksdb $CUR_DIR/3rd_party/rocksdb/CMakeLists.txt 339 # cp $CUR_DIR/3rd_party/build_option_bak/Makefile-rocksdb $CUR_DIR/3rd_party/rocksdb/Makefile 340 341 cd $CUR_DIR/3rd_party/rocksdb 342 #export CXX=$CUR_DIR/lib_llvm/bin/clang++ 343 ROCKSDB_DISABLE_GFLAGS=On LIBRARY_PATH=$CUR_DIR/lib/lib CPATH=$CUR_DIR/lib/include make install-shared INSTALL_PATH=$CUR_DIR/lib -j$PARALLEL 344 #ROCKSDB_DISABLE_GFLAGS=On LIBRARY_PATH=$CUR_DIR/lib/lib CPATH=$CUR_DIR/lib/include CXXFLAGS=-stdlib=libc++ LDFLAGS=-lc++ make install-shared INSTALL_PATH=$CUR_DIR/lib -j$PARALLEL 345 make clean 346 fi 347 check_script_run rocksdb 348 } 349 350 check_install_protoc() { 351 if [ ! -f $CUR_DIR/lib/bin/protoc ]; then 352 cd $CUR_DIR/3rd_party/protobuf 353 ./autogen.sh 354 ./configure --prefix=$CUR_DIR/lib/ 355 make -j$PARALLEL && make install && make clean 356 fi 357 check_script_run protoc 358 } 359 360 check_install_softfloat() { 361 if [ ! -e $CUR_DIR/lib/lib/libsoftfloat.$DYLIB ]; then 362 cd $CUR_DIR/3rd_party/SoftFloat-3e/build/Linux-x86_64-GCC/ 363 make -j$PARALLEL 364 cp libsoftfloat.so $CUR_DIR/lib/lib/libsoftfloat.$DYLIB 365 cp ../../source/include/softfloat.h $CUR_DIR/lib/include/ 366 cp ../../source/include/softfloat_types.h $CUR_DIR/lib/include/ 367 make clean 368 fi 369 check_script_run softfloat 370 } 371 372 check_install_sha() { 373 if [ ! -e $CUR_DIR/3rd_party/cryptopp/sha3.h ]; then 374 cd $CUR_DIR/3rd_party/cryptopp 375 unzip cryptopp810.zip 376 fi 377 check_script_run sha 378 } 379 380 check_install_crypto() { 381 if [ ! -e $CUR_DIR/lib/lib/libcryptopp.$DYLIB ]; then 382 cd $CUR_DIR/3rd_party/cryptopp 383 export CXX=$CUR_DIR/lib_llvm/bin/clang++ 384 make dynamic -j$PARALLEL && make install PREFIX=$CUR_DIR/lib/ 385 make clean 386 fi 387 check_script_run cryptopp 388 } 389 390 check_install_gperftools() { 391 if [ ! -e $CUR_DIR/lib/lib/libprofiler.$DYLIB ]; then 392 cd $CUR_DIR/3rd_party/gperftools 393 ./autogen.sh 394 build_with_configure gperftools 395 fi 396 check_script_run gperftools 397 } 398 399 install_system_tools 400 check_install_cmake 401 check_install_llvm 402 check_install_boost 403 check_install_gflags 404 check_install_glog 405 check_install_gtest 406 check_install_ff 407 check_install_bzlib 408 check_install_zstd 409 check_install_rocksdb 410 check_install_protoc 411 check_install_softfloat 412 check_install_sha 413 check_install_crypto 414 check_install_gperftools 415 416 cd $CUR_DIR