提交 66b38ea4 编写于 作者: W wenxingsen.wxs

support rpm build

上级 be5a61dd
deps/3rd/
build
build_*/
\ No newline at end of file
cmake_minimum_required(VERSION 3.20.0)
include(cmake/Utils.cmake)
include(cmake/Env.cmake)
project(oblogmsg VERSION 3.2.1)
if(NOT CMAKE_BUILD_TYPE)
......
#!/bin/sh
TOPDIR=`readlink -f \`dirname $0\``
BUILD_SH=$TOPDIR/build.sh
ALL_ARGS=("$@")
DEP_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/deps/devel
TOOLS_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/devtools
CMAKE_COMMAND="${TOOLS_DIR}/bin/cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1"
echo "$0 ${ALL_ARGS[@]}"
CPU_CORES=`grep -c ^processor /proc/cpuinfo`
NEED_INIT=false
NEED_MAKE=false
MAKE_ARGS=(-j $CPU_CORES)
# parse arguments
function parse_args
{
for i in "${ALL_ARGS[@]}"; do
if [[ "$i" == "--init" ]]
then
NEED_INIT=true
elif [[ "$i" == "--make" ]]
then
NEED_MAKE=make
elif [[ $NEED_MAKE == false ]]
then
BUILD_ARGS+=("$i")
else
MAKE_ARGS+=("$i")
fi
done
}
function usage
{
echo -e "Usage:
\t./build.sh -h
\t./build.sh init
\t./build.sh clean
\t./build.sh [BuildType] [--init] [--make [MakeOptions]]
OPTIONS:
BuildType => debug(default), release, errsim, dissearray, rpm
MakeOptions => Options to make command, default: -j N
Examples:
\t# Build by debug mode and make with -j24.
\t./build.sh debug --make -j24
"
}
# try call init if --init given.
function try_init
{
if [[ $NEED_INIT == true ]]
then
do_init || exit $?
fi
}
# try call command make, if use give --make in command line.
function try_make
{
if [[ $NEED_MAKE != false ]]
then
$NEED_MAKE "${MAKE_ARGS[@]}"
fi
}
# dep_create.sh
function do_init
{
(cd $TOPDIR/deps/3rd && bash dep_create.sh)
}
# create build directory and cd it.
function prepare_build_dir
{
TYPE=$1
mkdir -p $TOPDIR/build_$TYPE && cd $TOPDIR/build_$TYPE
}
# make build directory && cmake && make (if need)
function do_build
{
TYPE=$1; shift
prepare_build_dir $TYPE || return
${CMAKE_COMMAND} ${TOPDIR} "$@"
}
# clean build directories
function do_clean
{
echo "cleaning..."
find . -maxdepth 1 -type d -name 'build_*' | xargs rm -rf
}
function build
{
set -- "${BUILD_ARGS[@]}"
case "x$1" in
xrelease)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo
;;
xdebug)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug
;;
*)
BUILD_ARGS=(debug "${BUILD_ARGS[@]}")
build
;;
esac
}
function main
{
case "$1" in
-h)
usage
;;
init)
do_init
;;
clean)
do_clean
;;
*)
parse_args
try_init
build
try_make
;;
esac
}
main "$@"
\ No newline at end of file
ob_define(DEVTOOLS_DIR "${CMAKE_SOURCE_DIR}/deps/3rd/usr/local/oceanbase/devtools")
ob_define(DEP_DIR "${CMAKE_SOURCE_DIR}/deps/3rd/usr/local/oceanbase/deps/devel")
set(CMAKE_C_COMPILER "${DEVTOOLS_DIR}/bin/clang")
set(CMAKE_CXX_COMPILER "${DEVTOOLS_DIR}/bin/clang++")
ob_define(GCC9 "${DEVTOOLS_DIR}")
set(CMAKE_CXX_FLAGS "--gcc-toolchain=${GCC9}")
set(CMAKE_C_FLAGS "--gcc-toolchain=${GCC9}")
macro(ob_define VAR DEFAULT)
if (NOT DEFINED ${VAR})
set(${VAR} ${DEFAULT})
endif()
endmacro()
\ No newline at end of file
#!/bin/bash
#clear env
unalias -a
PWD="$(cd $(dirname $0); pwd)"
OS_ARCH="$(uname -m)" || exit 1
OS_RELEASE="0"
if [[ ! -f /etc/os-release ]]; then
echo "[ERROR] os release info not found" 1>&2 && exit 1
fi
source /etc/os-release || exit 1
PNAME=${PRETTY_NAME:-"${NAME} ${VERSION}"}
PNAME="${PNAME} (${OS_ARCH})"
function compat_centos8() {
echo "[NOTICE] '$PNAME' is compatible with CentOS 8, use el8 dependencies list"
OS_RELEASE=8
}
function compat_centos7() {
echo "[NOTICE] '$PNAME' is compatible with CentOS 7, use el7 dependencies list"
OS_RELEASE=7
}
function not_supported() {
echo "[ERROR] '$PNAME' is not supported yet."
}
function version_ge() {
test "$(awk -v v1=$VERSION_ID -v v2=$1 'BEGIN{print(v1>=v2)?"1":"0"}' 2>/dev/null)" == "1"
}
function get_os_release() {
if [[ "${OS_ARCH}x" == "x86_64x" ]]; then
case "$ID" in
alinux)
version_ge "2.1903" && compat_centos7 && return
;;
alios)
version_ge "8.0" && compat_centos8 && return
version_ge "7.2" && compat_centos7 && return
;;
anolis)
version_ge "8.0" && compat_centos8 && return
version_ge "7.0" && compat_centos7 && return
;;
ubuntu)
version_ge "16.04" && compat_centos7 && return
;;
centos)
version_ge "8.0" && OS_RELEASE=8 && return
version_ge "7.0" && OS_RELEASE=7 && return
;;
debian)
version_ge "9" && compat_centos7 && return
;;
fedora)
version_ge "33" && compat_centos7 && return
;;
opensuse-leap)
version_ge "15" && compat_centos7 && return
;;
#suse
sles)
version_ge "15" && compat_centos7 && return
;;
uos)
version_ge "20" && compat_centos7 && return
;;
arch)
compat_centos8 && return
;;
rocky)
version_ge "8.0" && compat_centos8 && return
;;
esac
elif [[ "${OS_ARCH}x" == "aarch64x" ]]; then
case "$ID" in
alios)
version_ge "8.0" && compat_centos8 && return
version_ge "7.0" && compat_centos7 && return
;;
centos)
version_ge "8.0" && OS_RELEASE=8 && return
version_ge "7.0" && OS_RELEASE=7 && return
;;
esac
elif [[ "${OS_ARCH}x" == "sw_64x" ]]; then
case "$ID" in
UOS)
version_ge "20" && OS_RELEASE=20 && return
;;
esac
fi
not_supported && return 1
}
get_os_release || exit 1
OS_TAG="el$OS_RELEASE.$OS_ARCH"
DEP_FILE="drcmsg.${OS_TAG}.deps"
echo -e "check dependencies profile for ${DEP_FILE}... \c"
if [[ ! -f "${DEP_FILE}" ]]; then
echo "NOT FOUND" 1>&2
exit 2
else
echo "FOUND"
fi
mkdir "${PWD}/pkg" >/dev/null 2>&1
declare -A targets
declare -A packages
section="default"
content=""
function save_content {
if [[ "$content" != "" ]]
then
if [[ $(echo "$section" | grep -E "^target\-") != "" ]]
then
target_name=$(echo $section | sed 's|^target\-\(.*\)$|\1|g')
targets["$target_name"]="$(echo "${content}" | grep -Eo "repo=.*" | awk -F '=' '{ print $2 }')"
echo "target: $target_name, repo: ${targets["$target_name"]}"
else
packages["$section"]=$content
fi
fi
}
echo -e "check repository address in profile..."
while read -r line
do
if [[ $(echo "$line" | grep -E "\[.*\]") != "" ]]
then
save_content
content=""
# section=${line//\[\(.*\)\]/\1}
section=$(echo $line | sed 's|.*\[\(.*\)\].*|\1|g')
else
[[ "$line" != "" ]] && [[ "$line" != '#'* ]] && content+=$'\n'"$line"
fi
done < $DEP_FILE
save_content
# 删除旧依赖
ls |grep -v dep_create.sh |grep -v .deps |grep -v pkg |xargs rm -rf
echo "download dependencies..."
for sect in "${!packages[@]}"
do
#if [[ "$1" != "all" ]]
#then
# [[ "$sect" == "test-utils" ]] && continue
#fi
echo "${packages["$sect"]}" | while read -r line
do
[[ "$line" == "" ]] && continue
pkg=${line%%\ *}
target_name="default"
temp=$(echo "$line" | grep -Eo "target=(\S*)")
[[ "$temp" != "" ]] && target_name=${temp#*=}
if [[ -f "${PWD}/pkg/${pkg}" ]]; then
echo "find package <${pkg}> in cache"
else
echo -e "download package <${pkg}>... \c"
repo=${targets["$target_name"]}
TEMP=$(mktemp -p "/" -u ".${pkg}.XXXX")
wget "$repo/${pkg}" -q -O "${PWD}/pkg/${TEMP}"
if (( $? == 0 )); then
mv -f "${PWD}/pkg/$TEMP" "${PWD}/pkg/${pkg}"
echo "SUCCESS"
else
rm -rf "${PWD}/pkg/$TEMP"
echo "FAILED" 1>&2
exit 4
fi
fi
echo -e "unpack package <${pkg}>... \c"
if [ "$ID" = "arch" ]; then
rpmextract.sh "${PWD}/pkg/${pkg}"
else
rpm2cpio "${PWD}/pkg/${pkg}" | cpio -di -u --quiet
fi
if [[ $? -eq 0 ]]; then
echo "SUCCESS"
else
echo "FAILED" 1>&2
exit 5
fi
done
done
[target-default]
os=7
arch=aarch64
repo=http://yum-test.obvos.alibaba-inc.com/oceanbase/development-kit/el/7/aarch64/
[deps]
devdeps-gtest-1.8.0-3.el7.aarch64.rpm
[tools]
obdevtools-cmake-3.22.1-1.el7.aarch64.rpm
obdevtools-gcc9-9.3.0-3.el7.aarch64.rpm
obdevtools-llvm-11.0.1-13.el7.aarch64.rpm
[target-default]
os=7
arch=x86_64
repo=http://yum-test.obvos.alibaba-inc.com/oceanbase/development-kit/el/7/x86_64/
[deps]
devdeps-gtest-1.8.0-3.el7.x86_64.rpm
[tools]
obdevtools-cmake-3.22.1-1.el7.x86_64.rpm
obdevtools-gcc9-9.3.0-3.el7.x86_64.rpm
obdevtools-llvm-11.0.1-13.el7.x86_64.rpm
Name: devdeps-oblogmsg
Version: %(echo $VERSION)
Release: %(echo $RELEASE)%{?dist}
# if you want use the parameter of rpm_create on build time,
# uncomment below
Summary: blogmsg
Group: Development/Tools
License: Commercial
Url: oceanbase.com
%define _prefix /usr/local/oceanbase/deps/devel
%define __strip /bin/true
%define __os_install_post %{nil}
%define debug_package %{nil}
# uncomment below, if your building depend on other packages
#BuildRequires: package_name = 1.0.0
# uncomment below, if depend on other packages
#Requires: package_name = 1.0.0
%description
# if you want publish current svn URL or Revision use these macros
Lua static library for oceanbase
#%debug_package
# support debuginfo package, to reduce runtime package size
# prepare your files
%install
mkdir -p $RPM_BUILD_ROOT/%{_prefix}
mkdir -p $RPM_BUILD_ROOT/%{_prefix}/include/blogmsg
mkdir -p $RPM_BUILD_ROOT/%{_prefix}/lib
cd $OLDPWD/../
sh build.sh --init release
cd build_release
make -j8
cd ..
cp build_release/src/libblogmsg.a $RPM_BUILD_ROOT/%{_prefix}/lib/
cp build_release/src/libblogmsg.so $RPM_BUILD_ROOT/%{_prefix}/lib/
cp include/*.h $RPM_BUILD_ROOT/%{_prefix}/include/blogmsg/
# package infomation
%files
# set file attribute here
%defattr(-,root,root)
# need not list every file here, keep it as this
%{_prefix}
## create an empy dir
# %dir %{_prefix}/var/log
## need bakup old config file, so indicate here
# %config %{_prefix}/etc/sample.conf
## or need keep old config file, so indicate with "noreplace"
# %config(noreplace) %{_prefix}/etc/sample.conf
## indicate the dir for crontab
# %attr(644,root,root) %{_crondir}/*
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%changelog
* Tue Sep 6 2022 wenxignsen.wxs
- for ob 4.0 opensource
(base)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册