#!/usr/bin/env bash
#set -e 表示当命令发生错误时停止执行脚本
#set 打印运行命令,-x 开启
set -ex
#检测是否存在.git目录,存在则表示是通过git clone获取的代码,需要来联网更新子模块。
if [ -d .git ]; then
git submodule update --init --recursive
fi
# := 表示如果这个变量是空或者未赋初值,则对其进行赋值. 否则, 就不赋值.检测用户是否事先声明
# 这两个环境变量,若没有,则将BUILD_DIR设为当前目录下的build目录,CEPH_GIT_DIR设置为..
# CEPH_GIT_DIR设置为.. 意味着并不能随意设置BUILD_DIR变量更改编译目录,目录名可以修改,
# 但必须位于源代码根目录下
: ${BUILD_DIR:=build}
: ${CEPH_GIT_DIR:=..}
# 检测编译目录是否已存在,已存则提示用户更改编译目录并退出脚本
if [ -e $BUILD_DIR ]; then
echo "'$BUILD_DIR' dir already exists; either rm -rf '$BUILD_DIR' and re-run, or set BUILD_DIR env var to a different directory name"
exit 1
fi
PYBUILD="3"
ARGS="-GNinja"
# 检测/etc/os-release是否可读,shell判断命令如下:
# ------------------------------------------------
# -e (exist) |
# -e filename, 判断文件是否存在 |
# ------------------------------------------------
# -d (directory) |
# -d filename,判断文件是否为目录 |
# ------------------------------------------------
# -f (file) |
# -f filename,判断文件是否为常规文件 |
# ------------------------------------------------
# -L (link) |
# -L filename,判断文件是否问链接文件 |
# ------------------------------------------------
# -r (read) |
# -r filename,判断文件是否可读 |
# ------------------------------------------------
# -w (write) |
# -w filename,判断文件是否可写 |
# ------------------------------------------------
# -x (exec) |
# -x filename,判断文件是否可执行 |
# ------------------------------------------------
# -s (size) |
# -s filename,判断文件长度是否为0 |
# ------------------------------------------------
# -h (hard link) |
# -h filename,判断文件是否为硬链接文件 |
# ------------------------------------------------
# -nt (newer than) |
# filename1 -nt filename2,判断文件1是否比文件2新 |
# ------------------------------------------------
# -ot (older than) |
# filename1 -ot filename2,判断文件1是否比文件2旧 |
# ------------------------------------------------
if [ -r /etc/os-release ]; then
# 若存在/etc/os-release,则通过os-release判断操作系统类型
source /etc/os-release
case "$ID" in
fedora)
if [ "$VERSION_ID" -ge "35" ] ; then
PYBUILD="3.10"
elif [ "$VERSION_ID" -ge "33" ] ; then
PYBUILD="3.9"
elif [ "$VERSION_ID" -ge "32" ] ; then
PYBUILD="3.8"
else
PYBUILD="3.7"
fi
;;
rhel|centos)
MAJOR_VER=$(echo "$VERSION_ID" | sed -e 's/\..*$//')
if [ "$MAJOR_VER" -ge "9" ] ; then
PYBUILD="3.9"
elif [ "$MAJOR_VER" -ge "8" ] ; then
PYBUILD="3.6"
fi
;;
opensuse*|suse|sles)
PYBUILD="3"
ARGS+=" -DWITH_RADOSGW_AMQP_ENDPOINT=OFF"
ARGS+=" -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF"
;;
esac
#对于ubuntu系统,不进入任何一个case分支
elif [ "$(uname)" == FreeBSD ] ; then
PYBUILD="3"
ARGS+=" -DWITH_RADOSGW_AMQP_ENDPOINT=OFF"
ARGS+=" -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF"
else
echo Unknown release
exit 1
fi
# ubuntu系统下,PYBUILD为默认值"3",ARGS为默认值"-GNinja"
ARGS+=" -DWITH_PYTHON3=${PYBUILD}"
# 此时 ARGS = -GNinja -DWITH_PYTHON3=3
# 获取ccache类型信息,并将标准输出重定向到/dev/null,同时将标准错误输出重定向到标准输出,
# 即将所有打印信息丢弃,仅保留返回值信息,此判断即为判断ccache命令是否存在
if type ccache > /dev/null 2>&1 ; then
echo "enabling ccache"
ARGS+=" -DWITH_CCACHE=ON"
fi
# 创建编译目录
mkdir $BUILD_DIR
# cd进入编译目录
cd $BUILD_DIR
# 判断cmake3是否存在,存在则用cmake3进行编译,否则使用cmake
if type cmake3 > /dev/null 2>&1 ; then
CMAKE=cmake3
else
CMAKE=cmake
fi
${CMAKE} $ARGS "$@" $CEPH_GIT_DIR || exit 1
# 若cmake3和ccache都存在,则次命令展开如下:
# cmake3 -GNinja -DWITH_PYTHON3=3 -DWITH_CCACHE=ON ..
#关闭命令行打印
set +x
# minimal config to find plugins
# 接收标准输入,并以EOF结束,将接收到的标准输入重定向到ceph.conf,即将EOF之前的三行写入文件
cat <<EOF > ceph.conf
[global]
plugin dir = lib
erasure code dir = lib
EOF
echo done.
if [[ ! "$ARGS $@" =~ "-DCMAKE_BUILD_TYPE" ]]; then
cat <<EOF
****
WARNING: do_cmake.sh now creates debug builds by default. Performance
may be severely affected. Please use -DCMAKE_BUILD_TYPE=RelWithDebInfo
if a performance sensitive build is required.
****
EOF
fi
ceph do_cmake.sh添加注释
最新推荐文章于 2023-08-05 21:58:06 发布