#!/bin/sh


echo '----------查找路径'
# 获取当前物理路径
SOURCE=$BASH_SOURCE[0]
while [ -h "$SOURCE" ] 
do
	DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
	SOURCE="$(readlink "$SOURCE")"
	[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# 权限
chmod -R 777 $DIR/*

echo '----------参数解析'
# pars
# pars
ONLY_BUILD=0
for parkey in "$@"
do
        if [ "$parkey" = "ob" ];then
                ONLY_BUILD=1
        fi
done

if [ $ONLY_BUILD -eq 0 ]; then
	echo '----------GCC检测'
	# gcc
	export compiler=$(which gcc)
	MAJOR=$(echo __GNUC__ | $compiler -E -xc - | tail -n 1)
	MINOR=$(echo __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
	PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -xc - | tail -n 1)
	if [ $MAJOR -lt 7 ]; then
		#echo '----------安装scl'
		#yum -y install centos-release-scl
		echo '----------安装gcc7'
		yum -y install devtoolset-7-gcc*
                #--2024-07-05_wzc_新增--
                sed -i "/\/opt\/rh\/devtoolset-7\/enable/d" /etc/profile
                #-------------------------
		echo 'source /opt/rh/devtoolset-7/enable' >>/etc/profile
		source /etc/profile
	#	scl enable devtoolset-7 bash
	fi

	echo '----------cmake安装'
	# cmake3
	yum -y install cmake3

	# libtool
	yum -y install libtool

	echo '----------hiredis安装'
	# hiredis
	cd $DIR/hiredis-0.13.3
	make install

	echo '----------libuv安装'
	# libuv
	yum -y install libuv
	yum -y install libuv-devel
	#yum -y remove libuv
	
	# uuid
	yum -y install libuuid-devel

	echo '----------uvw安装'
	# uvw
	mkdir $DIR/uvw-2.3.0_libuv-v1.34/build
	cd $DIR/uvw-2.3.0_libuv-v1.34/build
	cmake3 $DIR/uvw-2.3.0_libuv-v1.34 -DCMAKE_INSTALL_PREFIX=/usr/local
	make install

	echo '----------zlib安装'
	# zlib
	mkdir $DIR/zlib-1.2.11/build
	cd $DIR/zlib-1.2.11/build
	cmake3 $DIR/zlib-1.2.11 -DCMAKE_INSTALL_PREFIX=/usr/local
	make install
	
	# kafka
	yum -y install librdkafka-devel



	cd $DIR
fi

echo '----------开始编译'
# cmake 编译
mkdir $DIR/build
cd $DIR/build
cmake3 $DIR
make
