eosio_build_centos.sh执行过程

首先打印系统信息,该信息在eosio_build.sh中已经通过export设置到环境变量中,从上到下分别是:系统名称,系统版本,CPU内核数,内存,磁盘总空间以及磁盘可用空间。

echo "OS name: ${NAME}"
echo "OS Version: ${VERSION_ID}"
echo "CPU cores: ${CPU_CORES}"
echo "Physical Memory: ${MEM_GIG}G"
echo "Disk space total: ${DISK_TOTAL}G"
echo "Disk space available: ${DISK_AVAIL}G"

接下来是系统配置要求:centos版本必须是7以上,内存必须不能小于7G,磁盘空间不能小于5G

( [[ $NAME == "CentOS Linux" ]] && [[ "$(echo ${VERSION} | sed 's/ .*//g')" < 7 ]] ) && echo " - You must be running Centos 7 or higher to install EOSIO." && exit 1

[[ $MEM_GIG -lt 7 ]] && echo "Your system must have 7 or more Gigabytes of physical memory installed." && exit 1
[[ "${DISK_AVAIL}" -lt "${DISK_MIN}" ]] && echo " - You must have at least ${DISK_MIN}GB of available storage to install EOSIO." && exit 1

echo ""

接下来是执行ensure-scl方法,该方法代码如下

 1 function ensure-scl() {
 2     echo "${COLOR_CYAN}[Ensuring installation of Centos Software Collections Repository]${COLOR_NC}" # Needed for rh-python36
 3     SCL=$( rpm -qa | grep -E 'centos-release-scl-[0-9].*' || true )
 4     if [[ -z "${SCL}" ]]; then
 5         while true; do
 6             [[ $NONINTERACTIVE == false ]] && read -p "${COLOR_YELLOW}Do you wish to install and enable the Centos Software Collections Repository? (y/n)?${COLOR_NC} " PROCEED
 7             echo ""
 8             case $PROCEED in
 9                 "" ) echo "What would you like to do?";;
10                 0 | true | [Yy]* ) install-package centos-release-scl "--enablerepo=extras"; break;;
11                 1 | false | [Nn]* ) echo " - User aborted installation of required Centos Software Collections Repository."; exit 1;;
12                 * ) echo "Please type 'y' for yes or 'n' for no.";;
13             esac
14         done
15     else
16         echo " - ${SCL} found."
17     fi
18 }

先看第3行,该行主要验证是否安装了centos-release-scl系统软件。如果安装则返回scl名称,否则返回空;

第4行对scl进行判断,如果没有安装,则提示安装,之后转到第10行,进行安装。

所以该方法是为了确保centos的scl文件必须存在。关于centos-release-scl作用,请查看如何在CentOS上启用软件集,这里简单介绍备忘

SCL(软件集合)可以让你在同一个操作系统上安装和使用多个版本的软件,而不会影响整个系统的安装包。

SCL的创建就是为了给RHEL / CentOS用户提供一种以方便,安全地安装和使用应用程序和运行时环境的多个(而且可能是更新的)版本的方式,同时避免把系统搞乱。

接下来执行ensure-devtoolset方法,改方法源代码如下:

function ensure-devtoolset() {
    echo "${COLOR_CYAN}[Ensuring installation of devtoolset-8]${COLOR_NC}"
    DEVTOOLSET=$( rpm -qa | grep -E 'devtoolset-8-[0-9].*' || true )
    if [[ -z "${DEVTOOLSET}" ]]; then
        while true; do
            [[ $NONINTERACTIVE == false ]] && printf "${COLOR_YELLOW}Not Found: Do you wish to install it? (y/n)?${COLOR_NC}" && read -p " " PROCEED
            echo ""
            case $PROCEED in
                "" ) echo "What would you like to do?";;
                0 | true | [Yy]* ) install-package devtoolset-8; break;;
                1 | false | [Nn]* ) echo " - User aborted installation of devtoolset-8."; break;;
                * ) echo "Please type 'y' for yes or 'n' for no.";;
            esac
        done
    else
        echo " - ${DEVTOOLSET} found."
    fi
}

其代码功能整体和ensure-scl几乎一样,只是替换为安装devtoolset-8工具集,有关devtoolset-8工具集功能,请参考:Developer Toolset 8,其主要功能是

为在CentOS或Red Hat Enterprise Linux平台上工作的开发人员设计的。它提供了最新版本的GNU编译器集合,GNU调试器以及其他开发,调试和性能监视工具。

接下来启用devtoolset-8工具集,源码如下

if [[ -d /opt/rh/devtoolset-8 ]]; then
    echo "${COLOR_CYAN}[Enabling Centos devtoolset-8 (so we can use GCC 8)]${COLOR_NC}"
    execute-always source /opt/rh/devtoolset-8/enable
    echo " - ${COLOR_GREEN}Centos devtoolset-8 successfully enabled!${COLOR_NC}"
fi

接下来的方法比较复杂,源代码如下

# Ensure packages exist
ensure-yum-packages "${REPO_ROOT}/scripts/eosio_build_centos7_deps"

这里有两个内容,其中ensure-yum-packages是验证依赖包是否存在,且将不存在的依赖包安装的过程,源码如下

function ensure-yum-packages() {
# 验证依赖包入参 ( [[
-z "${1}" ]] || [[ ! -f "${1}" ]] ) && echo "\$1 must be the location of your dependency file!" && exit 1 #定义临时包文件
DEPS_FILE
="${TEMP_DIR}/$(basename ${1})" # Create temp file so we can add to it cat $1 > $DEPS_FILE
#安行读取所有的依赖包,设置进DEPS_FILE中
if [[ ! -z "${2}" ]]; then # Handle EXTRA_DEPS passed in and add them to temp DEPS_FILE printf "\n" >> $DEPS_FILE # Avoid needing a new line at the end of deps files OLDIFS="$IFS"; IFS=$'' _2=("$(echo $2 | sed 's/-qa /-qa\n/g')") for ((i = 0; i < ${#_2[@]}; i++)); do echo "${_2[$i]}\n" | sed 's/-qa\\n/-qa/g' >> $DEPS_FILE; done fi

# 跟新yum while true; do [[ $NONINTERACTIVE == false ]] && printf "${COLOR_YELLOW}Do you wish to update YUM repositories? (y/n)?${COLOR_NC}" && read -p " " PROCEED echo "" case $PROCEED in "" ) echo "What would you like to do?";; 0 | true | [Yy]* ) execute eval $( [[ $CURRENT_USER == "root" ]] || echo $SUDO_LOCATION -E ) $YUM -y update; break;; 1 | false | [Nn]* ) echo " - Proceeding without update!"; break;; * ) echo "Please type 'y' for yes or 'n' for no.";; esac done echo "${COLOR_CYAN}[Ensuring package dependencies]${COLOR_NC}" OLDIFS="$IFS"; IFS=$',' # || [[ -n "$testee" ]]; needed to see last line of deps file (https://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line) while read -r testee tester || [[ -n "$testee" ]]; do if [[ ! -z $(eval $tester $testee) ]]; then echo " - ${testee} ${COLOR_GREEN}ok${COLOR_NC}" else DEPS=$DEPS"${testee} " echo " - ${testee} ${COLOR_RED}NOT${COLOR_NC} found!" (( COUNT+=1 )) fi done < $DEPS_FILE IFS=$OLDIFS OLDIFS="$IFS"; IFS=$' ' echo "" if [[ $COUNT > 0 ]]; then while true; do [[ $NONINTERACTIVE == false ]] && printf "${COLOR_YELLOW}Do you wish to install missing dependencies? (y/n)?${COLOR_NC}" && read -p " " PROCEED echo "" case $PROCEED in "" ) echo "What would you like to do?";; 0 | true | [Yy]* ) for DEP in $DEPS; do

#循环安装更新包 install-package $DEP done break;; 1 | false | [Nn]* ) echo " ${COLOR_RED}- User aborted installation of required dependencies.${COLOR_NC}"; exit;; * ) echo "Please type 'y' for yes or 'n' for no.";; esac done echo "" else echo "${COLOR_GREEN} - No required package dependencies to install.${COLOR_NC}" echo "" fi IFS=$OLDIFS }

其中必须安装的更新包在${REPO_ROOT}/scripts/eosio_build_centos7_deps中,内容如下:

git,rpm -qa
autoconf,rpm -qa
automake,rpm -qa
libtool,rpm -qa
make,rpm -qa
bzip2,rpm -qa
doxygen,rpm -qa
graphviz,rpm -qa
bzip2-devel,rpm -qa
openssl-devel,rpm -qa
gmp-devel,rpm -qa
ocaml,rpm -qa
libicu-devel,rpm -qa
python,rpm -qa
python-devel,rpm -qa
rh-python36,rpm -qa
gettext-devel,rpm -qa
file,rpm -qa
libusbx-devel,rpm -qa
libcurl-devel,rpm -qa
patch,rpm -qa

确认安装python3.6版本,rh-python36

export PYTHON3PATH="/opt/rh/rh-python36"
if $DRYRUN || [ -d $PYTHON3PATH ]; then
    echo "${COLOR_CYAN}[Enabling python36]${COLOR_NC}"
    execute source $PYTHON3PATH/enable
    echo " ${COLOR_GREEN}- Python36 successfully enabled!${COLOR_NC}"
    echo ""
fi

接下来安装基础软件

# Handle clang/compiler
ensure-compiler
# CMAKE Installation
ensure-cmake
# CLANG Installation
build-clang
# LLVM Installation
ensure-llvm
# BOOST Installation
ensure-boost

ensure-compiler源码如下

 1 function ensure-compiler() {
 2     # Support build-essentials on ubuntu
 3     if [[ $NAME == "CentOS Linux" ]] || [[ $VERSION_ID == "16.04" ]] || ( $PIN_COMPILER && [[ $VERSION_ID == "18.04" ]] ); then
 4         export CXX=${CXX:-'g++'}
 5         export CC=${CC:-'gcc'}
 6     fi
 7     export CXX=${CXX:-'clang++'}
 8     export CC=${CC:-'clang'}
 9     if $PIN_COMPILER || [[ -f $CLANG_ROOT/bin/clang++ ]]; then
10         export PIN_COMPILER=true
11         export BUILD_CLANG=true
12         export CPP_COMP=$CLANG_ROOT/bin/clang++
13         export CC_COMP=$CLANG_ROOT/bin/clang
14         export PATH=$CLANG_ROOT/bin:$PATH
15     elif [[ $PIN_COMPILER == false ]]; then
16         which $CXX &>/dev/null || ( echo "${COLOR_RED}Unable to find $CXX compiler: Pass in the -P option if you wish for us to install it or install a C++17 compiler and set \$CXX and \$CC to the proper binary locations. ${COLOR_NC}"; exit 1 )
17         # readlink on mac differs from linux readlink (mac doesn't have -f)
18         [[ $ARCH == "Linux" ]] && READLINK_COMMAND="readlink -f" || READLINK_COMMAND="readlink"
19         COMPILER_TYPE=$( eval $READLINK_COMMAND $(which $CXX) || true )
20         if [[ $CXX =~ "clang" ]] || [[ $COMPILER_TYPE =~ "clang" ]]; then
21             if [[ $ARCH == "Darwin" ]]; then
22                 ### Check for apple clang version 10 or higher
23                 [[ $( $(which $CXX) --version | cut -d ' ' -f 4 | cut -d '.' -f 1 | head -n 1 ) -lt 10 ]] && export NO_CPP17=true
24             else
25                 if [[ $( $(which $CXX) --version | cut -d ' ' -f 3 | head -n 1 | cut -d '.' -f1) =~ ^[0-9]+$ ]]; then # Check if the version message cut returns an integer
26                     [[ $( $(which $CXX) --version | cut -d ' ' -f 3 | head -n 1 | cut -d '.' -f1) < 6 ]] && export NO_CPP17=true
27                 elif [[ $(clang --version | cut -d ' ' -f 4 | head -n 1 | cut -d '.' -f1) =~ ^[0-9]+$ ]]; then # Check if the version message cut returns an integer
28                     [[ $( $(which $CXX) --version | cut -d ' ' -f 4 | cut -d '.' -f 1 | head -n 1 ) < 6 ]] && export NO_CPP17=true
29                 fi
30             fi
31         else
32             ## Check for c++ version 7 or higher
33             [[ $( $(which $CXX) -dumpversion | cut -d '.' -f 1 ) -lt 7 ]] && export NO_CPP17=true
34             if [[ $NO_CPP17 == false ]]; then # https://github.com/EOSIO/eos/issues/7402
35                 while true; do
36                     echo "${COLOR_YELLOW}WARNING: Your GCC compiler ($CXX) is less performant than clang (https://github.com/EOSIO/eos/issues/7402). We suggest running the build script with -P or install your own clang and try again.${COLOR_NC}"
37                     [[ $NONINTERACTIVE == false ]] && printf "${COLOR_YELLOW}Do you wish to proceed anyway? (y/n)?${COLOR_NC}" && read -p " " PROCEED
38                     case $PROCEED in
39                         "" ) echo "What would you like to do?";;
40                         0 | true | [Yy]* ) break;;
41                         1 | false | [Nn]* ) exit 1;;
42                         * ) echo "Please type 'y' for yes or 'n' for no.";;
43                     esac
44                 done
45             fi
46         fi
47     fi
48     if $NO_CPP17; then
49         while true; do
50             echo "${COLOR_YELLOW}Unable to find C++17 support in ${CXX}!${COLOR_NC}"
51             echo "If you already have a C++17 compiler installed or would like to install your own, export CXX to point to the compiler of your choosing."
52             [[ $NONINTERACTIVE == false ]] && printf "${COLOR_YELLOW}Do you wish to download and build C++17? (y/n)?${COLOR_NC}" && read -p " " PROCEED
53             case $PROCEED in
54                 "" ) echo "What would you like to do?";;
55                 0 | true | [Yy]* )
56                     export PIN_COMPILER=true
57                     export BUILD_CLANG=true
58                     export CPP_COMP=$CLANG_ROOT/bin/clang++
59                     export CC_COMP=$CLANG_ROOT/bin/clang
60                     export PATH=$CLANG_ROOT/bin:$PATH
61                 break;;
62                 1 | false | [Nn]* ) echo "${COLOR_RED} - User aborted C++17 installation!${COLOR_NC}"; exit 1;;
63                 * ) echo "Please type 'y' for yes or 'n' for no.";;
64             esac
65         done
66     fi
67     $BUILD_CLANG && export PINNED_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE='${BUILD_DIR}/pinned_toolchain.cmake'"
68     echo ""
69 }

这个方法咋看下去确实很多,也很难分析,但其实核心内容就三个:

1. 确保clang安装,并且安装版本必须是10+

2.安装gcc在7版本以上

3.兼容c++17

然后是ensure-cmake,源码如下

function ensure-cmake() {
    echo "${COLOR_CYAN}[Ensuring CMAKE installation]${COLOR_NC}"
    if [[ ! -e "${CMAKE}" ]]; then
        execute bash -c "cd $SRC_DIR && \
        curl -LO https://cmake.org/files/v${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}/cmake-${CMAKE_VERSION}.tar.gz \
        && tar -xzf cmake-${CMAKE_VERSION}.tar.gz \
        && cd cmake-${CMAKE_VERSION} \
        && ./bootstrap --prefix=${EOSIO_INSTALL_DIR} \
        && make -j${JOBS} \
        && make install \
        && cd .. \
        && rm -f cmake-${CMAKE_VERSION}.tar.gz"
        [[ -z "${CMAKE}" ]] && export CMAKE="${BIN_DIR}/cmake"
        echo " - CMAKE successfully installed @ ${CMAKE}"
        echo ""
    else
        echo " - CMAKE found @ ${CMAKE}."
        echo ""
    fi
}

核心内容也只是安装符合要求的cmake,接下来的ensure-llvm、ensure-boost也几乎如此,这里把源码贴上

 1 function ensure-boost() {
 2     [[ $ARCH == "Darwin" ]] && export CPATH="$(python-config --includes | awk '{print $1}' | cut -dI -f2):$CPATH" # Boost has trouble finding pyconfig.h
 3     echo "${COLOR_CYAN}[Ensuring Boost $( echo $BOOST_VERSION | sed 's/_/./g' ) library installation]${COLOR_NC}"
 4     BOOSTVERSION=$( grep "#define BOOST_VERSION" "$BOOST_ROOT/include/boost/version.hpp" 2>/dev/null | tail -1 | tr -s ' ' | cut -d\  -f3 || true )
 5     if [[ "${BOOSTVERSION}" != "${BOOST_VERSION_MAJOR}0${BOOST_VERSION_MINOR}0${BOOST_VERSION_PATCH}" ]]; then
 6         B2_FLAGS="-q -j${JOBS} --with-iostreams --with-date_time --with-filesystem --with-system --with-program_options --with-chrono --with-test install"
 7         BOOTSTRAP_FLAGS=""
 8         if [[ $ARCH == "Linux" ]] && $PIN_COMPILER; then
 9             B2_FLAGS="toolset=clang cxxflags='-stdlib=libc++ -D__STRICT_ANSI__ -nostdinc++ -I${CLANG_ROOT}/include/c++/v1' linkflags='-stdlib=libc++' link=static threading=multi --with-iostreams --with-date_time --with-filesystem --with-system --with-program_options --with-chrono --with-test -q -j${JOBS} install"
10             BOOTSTRAP_FLAGS="--with-toolset=clang"
11         fi
12         execute bash -c "cd $SRC_DIR && \
13         curl -LO https://dl.bintray.com/boostorg/release/$BOOST_VERSION_MAJOR.$BOOST_VERSION_MINOR.$BOOST_VERSION_PATCH/source/boost_$BOOST_VERSION.tar.bz2 \
14         && tar -xjf boost_$BOOST_VERSION.tar.bz2 \
15         && cd $BOOST_ROOT \
16         && ./bootstrap.sh ${BOOTSTRAP_FLAGS} --prefix=$BOOST_ROOT \
17         && ./b2 ${B2_FLAGS} \
18         && cd .. \
19         && rm -f boost_$BOOST_VERSION.tar.bz2 \
20         && rm -rf $BOOST_LINK_LOCATION"        
21         echo " - Boost library successfully installed @ ${BOOST_ROOT}"
22         echo ""
23     else
24         echo " - Boost library found with correct version @ ${BOOST_ROOT}"
25         echo ""
26     fi
27 }
28 
29 function ensure-llvm() {
30     echo "${COLOR_CYAN}[Ensuring LLVM 4 support]${COLOR_NC}"
31     if [[ ! -d $LLVM_ROOT ]]; then
32         if [[ $ARCH == "Darwin" ]]; then # Handle brew installed llvm@4
33             execute ln -s /usr/local/opt/llvm@4 $LLVM_ROOT
34             echo " - LLVM successfully linked from /usr/local/opt/llvm@4 to ${LLVM_ROOT}"
35         else
36             if $PIN_COMPILER || $BUILD_CLANG; then
37                 CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX='${LLVM_ROOT}' -DLLVM_TARGETS_TO_BUILD=host -DLLVM_BUILD_TOOLS=false -DLLVM_ENABLE_RTTI=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE='${BUILD_DIR}/pinned_toolchain.cmake' .."
38             else
39                 if [[ $NAME == "Ubuntu" ]]; then
40                     execute ln -s /usr/lib/llvm-4.0 $LLVM_ROOT
41                     echo " - LLVM successfully linked from /usr/lib/llvm-4.0 to ${LLVM_ROOT}"
42                     return 0
43                 fi
44                 CMAKE_FLAGS="-G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX=${LLVM_ROOT} -DLLVM_TARGETS_TO_BUILD='host' -DLLVM_BUILD_TOOLS=false -DLLVM_ENABLE_RTTI=1 -DCMAKE_BUILD_TYPE=Release .."
45             fi
46             execute bash -c "cd ${OPT_DIR} \
47             && git clone --depth 1 --single-branch --branch $LLVM_VERSION https://github.com/llvm-mirror/llvm.git llvm && cd llvm \
48             && mkdir build \
49             && cd build \
50             && ${CMAKE} ${CMAKE_FLAGS} \
51             && make -j${JOBS} \
52             && make install"
53             echo " - LLVM successfully installed @ ${LLVM_ROOT}"
54             echo ""
55         fi
56     else
57         echo " - LLVM found @ ${LLVM_ROOT}."
58         echo ""
59     fi
60 }

然后看build-clang方法,源码如下:

function build-clang() {
    if $BUILD_CLANG; then
        echo "${COLOR_CYAN}[Ensuring Clang support]${COLOR_NC}"
        if [[ ! -d $CLANG_ROOT ]]; then
            execute bash -c "cd ${TEMP_DIR} \
            && rm -rf clang8 \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/llvm.git clang8 \
            && cd clang8 && git checkout $PINNED_COMPILER_LLVM_COMMIT \
            && cd tools \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/lld.git \
            && cd lld && git checkout $PINNED_COMPILER_LLD_COMMIT && cd ../ \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/polly.git \
            && cd polly && git checkout $PINNED_COMPILER_POLLY_COMMIT && cd ../ \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/clang.git clang && cd clang \
            && git checkout $PINNED_COMPILER_CLANG_COMMIT \
            && patch -p2 < \"$REPO_ROOT/scripts/clang-devtoolset8-support.patch\" \
            && cd tools && mkdir extra && cd extra \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/clang-tools-extra.git \
            && cd clang-tools-extra && git checkout $PINNED_COMPILER_CLANG_TOOLS_EXTRA_COMMIT && cd .. \
            && cd ../../../../projects \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/libcxx.git \
            && cd libcxx && git checkout $PINNED_COMPILER_LIBCXX_COMMIT && cd ../ \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/libcxxabi.git \
            && cd libcxxabi && git checkout $PINNED_COMPILER_LIBCXXABI_COMMIT && cd ../ \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/libunwind.git \
            && cd libunwind && git checkout $PINNED_COMPILER_LIBUNWIND_COMMIT && cd ../ \
            && git clone --single-branch --branch $PINNED_COMPILER_BRANCH https://git.llvm.org/git/compiler-rt.git \
            && cd compiler-rt && git checkout $PINNED_COMPILER_COMPILER_RT_COMMIT && cd ../ \
            && cd ${TEMP_DIR}/clang8 \
            && mkdir build && cd build \
            && ${CMAKE} -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX='${CLANG_ROOT}' -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_ENABLE_LIBCXX=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_DOCS=OFF -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_TARGETS_TO_BUILD=all -DCMAKE_BUILD_TYPE=Release .. \
            && make -j${JOBS} \
            && make install \
            && rm -rf ${TEMP_DIR}/clang8"
            echo " - Clang 8 successfully installed @ ${CLANG_ROOT}"
            echo ""
        else
            echo " - Clang 8 found @ ${CLANG_ROOT}"
            echo ""
        fi
        export CXX=$CPP_COMP
        export CC=$CC_COMP
    fi
}

这里是对所有的安装依赖包进行make安装。

从上述代码可以知道,eos依赖的LLVM已经在这里被安装好了

然后是mongo DB的安装,源码如下:

if $INSTALL_MONGO; then

    echo "${COLOR_CYAN}[Ensuring MongoDB installation]${COLOR_NC}"
    if [[ ! -d $MONGODB_ROOT ]]; then
        execute bash -c "cd $SRC_DIR && \
        curl -OL https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-$MONGODB_VERSION.tgz \
        && tar -xzf mongodb-linux-x86_64-amazon-$MONGODB_VERSION.tgz \
        && mv $SRC_DIR/mongodb-linux-x86_64-amazon-$MONGODB_VERSION $MONGODB_ROOT \
        && touch $MONGODB_LOG_DIR/mongod.log \
        && rm -f mongodb-linux-x86_64-amazon-$MONGODB_VERSION.tgz \
        && cp -f $REPO_ROOT/scripts/mongod.conf $MONGODB_CONF \
        && mkdir -p $MONGODB_DATA_DIR \
        && rm -rf $MONGODB_LINK_DIR \
        && rm -rf $BIN_DIR/mongod \
        && ln -s $MONGODB_ROOT $MONGODB_LINK_DIR \
        && ln -s $MONGODB_LINK_DIR/bin/mongod $BIN_DIR/mongod"
        echo " - MongoDB successfully installed @ ${MONGODB_ROOT}."
    else
        echo " - MongoDB found with correct version @ ${MONGODB_ROOT}."
    fi
    echo "${COLOR_CYAN}[Ensuring MongoDB C driver installation]${COLOR_NC}"
    if [[ ! -d $MONGO_C_DRIVER_ROOT ]]; then
        execute bash -c "cd $SRC_DIR && \
        curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/$MONGO_C_DRIVER_VERSION/mongo-c-driver-$MONGO_C_DRIVER_VERSION.tar.gz \
        && tar -xzf mongo-c-driver-$MONGO_C_DRIVER_VERSION.tar.gz \
        && cd mongo-c-driver-$MONGO_C_DRIVER_VERSION \
        && mkdir -p cmake-build \
        && cd cmake-build \
        && $CMAKE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$EOSIO_INSTALL_DIR -DENABLE_BSON=ON -DENABLE_SSL=OPENSSL -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_STATIC=ON -DENABLE_ICU=OFF -DENABLE_SNAPPY=OFF $PINNED_TOOLCHAIN .. \
        && make -j${JOBS} \
        && make install \
        && cd ../.. \
        && rm mongo-c-driver-$MONGO_C_DRIVER_VERSION.tar.gz"
        echo " - MongoDB C driver successfully installed @ ${MONGO_C_DRIVER_ROOT}."
    else
        echo " - MongoDB C driver found with correct version @ ${MONGO_C_DRIVER_ROOT}."
    fi
    echo "${COLOR_CYAN}[Ensuring MongoDB CXX driver installation]${COLOR_NC}"
    if [[ ! -d $MONGO_CXX_DRIVER_ROOT ]]; then
        execute bash -c "cd $SRC_DIR && \
        curl -L https://github.com/mongodb/mongo-cxx-driver/archive/r$MONGO_CXX_DRIVER_VERSION.tar.gz -o mongo-cxx-driver-r$MONGO_CXX_DRIVER_VERSION.tar.gz \
        && tar -xzf mongo-cxx-driver-r${MONGO_CXX_DRIVER_VERSION}.tar.gz \
        && cd mongo-cxx-driver-r$MONGO_CXX_DRIVER_VERSION \
        && sed -i 's/\"maxAwaitTimeMS\", count/\"maxAwaitTimeMS\", static_cast<int64_t>(count)/' src/mongocxx/options/change_stream.cpp \
        && sed -i 's/add_subdirectory(test)//' src/mongocxx/CMakeLists.txt src/bsoncxx/CMakeLists.txt \
        && cd build \
        && $CMAKE -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$EOSIO_INSTALL_DIR -DCMAKE_PREFIX_PATH=$EOSIO_INSTALL_DIR $PINNED_TOOLCHAIN .. \
        && make -j${JOBS} VERBOSE=1 \
        && make install \
        && cd ../.. \
        && rm -f mongo-cxx-driver-r$MONGO_CXX_DRIVER_VERSION.tar.gz"
        echo " - MongoDB C++ driver successfully installed @ ${MONGO_CXX_DRIVER_ROOT}."
    else
        echo " - MongoDB C++ driver found with correct version @ ${MONGO_CXX_DRIVER_ROOT}."
    fi
fi

这里就不进行详细分析了。整个基于centos7 eos的build过程就已经完成了其他系统的build脚本也大致如此,在此不进行特定分析,接下来是eosio_install.sh的执行过程。

猜你喜欢

转载自www.cnblogs.com/wangzxblog/p/11840642.html