1 Star 0 Fork 123

吴政琪/SysAK

forked from anolis/SysAK 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
configure 6.19 KB
一键复制 编辑 原始数据 按行查看 历史
zhaohang 提交于 2023-03-15 07:04 . !476 update configure
#! /bin/sh
config_host_mak="config-host.mak"
kern_ver=`uname -r`
objdir=$(pwd)/out
enable_lkm=NO
enable_libbpf=NO
enable_packages=NO
disable_libbpf=NO
static_link=no
enable_all=no
default_target=yes
kernel_bpf_support=NO
disable_list=test
usage() {
echo "Usage: configure [options]"
echo "options:"
echo " --kernel=KERNEL_VERSION kernel version"
echo " --builddir=OBJDIR the build dir"
echo " --enable-lkm enable linux kernel module"
echo " --enable-libbpf enable libbpf"
echo " --enable-packages auto install dependent packages for tools"
echo " --disable-libbpf disable all bpf tools"
echo " --enable-static static link for c/cpp tools"
echo " --enable-target-xxx xxx is the actual tool, like memleak, you may use --show-target to list all"
echo " --enable-target-all enable all components"
echo " --disable-default disable default components to built-in"
echo " --disable-target-xxx xxx is the actual tool, like memleak, you may use --show-target to list all"
echo " --show-target list all support tools"
}
check_bpf_kernel() {
kern_major=$(echo $kern_ver | awk -F '.' '{print $1}')
kern_minor=$(echo $kern_ver | awk -F '.' '{print $2}')
is_centos7=$(echo $kern_ver | grep el7 | wc -l)
if [ $((kern_major)) -ge 4 -a $((kern_minor)) -ge 4 ]; then
kernel_bpf_support="YES"
fi
if [ $is_centos7 = 1 ]; then
centos_minor=$(echo $kern_ver | awk -F '-' '{print $2}' | awk -F '.' '{print $1}')
if [ $((centos_minor)) -ge 957 ];then
kernel_bpf_support="YES"
fi
fi
if [ $kernel_bpf_support != "YES" ];then
echo "this kernel version not support ebpf"
exit 1
else
echo "check kernel bpf support OK"
fi
}
check_bpf_depend() {
if [ ! -d "source/lib/internal/ebpf/coolbpf/build.sh" ];then
echo "Cloning coolbpf"
git submodule update --init
fi
check_bpf_kernel
if [ $kernel_bpf_support = "YES" ];then
clang -v > /dev/null
if [ $? = 0 ];then
echo "check clang OK"
else
echo "check clang failed, should intall first"
exit 1
fi
fi
}
check_lkm_depend() {
if [ ! -d "source/lib/internal/kernel_module" ];then
echo "download sysak-module ... "
wget https://gitee.com/anolis/sysak-module/repository/archive/master.zip -O sysak-module.zip
echo "extract sysak-module"
unzip sysak-module.zip -d source/lib/internal/
mv source/lib/internal/sysak-module-master source/lib/internal/kernel_module
fi
rpm -q kernel-devel-$kern_ver > /dev/null
if [ $? != 0 ];then
echo "check kernel-devel-$kern_ver failed, should intall first"
exit 1;
fi
}
check_packages_depend() {
PWD=$(pwd)
PACKAGEBUILD_TMP="packagebuild_tmp"
BUILD_SH="package_build.sh"
SH_ABS_PATH=$(pwd)/$PACKAGEBUILD_TMP/$BUILD_SH
mkdir -p $(pwd)/$PACKAGEBUILD_TMP
if [ -f "$SH_ABS_PATH" ];then
rm -f $SH_ABS_PATH
fi
echo "$(grep "DEP_PKG_INSTALL" $(pwd)/source/ -nr | awk -F ":=" '{print$2}'| tr -d "\"")"| while read line
do
echo $line
OLDIFS="$IFS"
IFS=@
echo "cd $(pwd)/$PACKAGEBUILD_TMP" >> $SH_ABS_PATH
for cmd in $line
do
echo $cmd >> $SH_ABS_PATH
if [[ $cmd =~ "git clone" ]];then
echo "WARNING:\"$cmd\" failed"
fi
#source $cmd
done
IFS="$OLDIFS"
echo "cd $PWD" >> $SH_ABS_PATH
done
chmod +x $SH_ABS_PATH
exec ./$PACKAGEBUILD_TMP/$BUILD_SH
cd $PWD
}
check_depend() {
if [ $enable_lkm = "YES" ]; then
check_lkm_depend
fi
if [ $enable_libbpf = "YES" ]; then
check_bpf_depend
fi
if [ $enable_packages = "YES" ]; then
check_packages_depend
fi
}
for opt; do
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
case "$opt" in
--kernel=*)
kern_ver=$optarg
;;
--builddir=*)
objdir=$(readlink -f $optarg)
;;
--enable-lkm)
enable_lkm="YES"
;;
--enable-libbpf)
enable_libbpf="YES"
;;
--enable-packages)
enable_packages="YES"
;;
--disable-libbpf)
disable_libbpf="YES"
;;
--enable-static)
static_link="yes"
;;
--enable-target-*)
target=$(expr "$opt" : '--enable-target-\(.*\)')
if [ $target = "all" ]; then
enable_all="yes"
else
target_list="$target $target_list"
fi
;;
--disable-default)
default_target=no
;;
--disable-target-*)
disable=$(expr "$opt" : '--disable-target-\(.*\)')
disable_list="$disable|$disable_list"
;;
--show-target)
find $(pwd)/source/tools/ -name Makefile -exec grep -H 'target :=' {} \; | awk '{print $3}' | grep -v test
exit
;;
*)
usage
exit
;;
esac
done
if [ $default_target = "yes" ]; then
target_list="tcp_syn_drop cpuirq sysmonitor cpu_flamegraph $target_list"
fi
for i in $target_list;do
target_files="$(grep -nrw "target := $i" $(pwd)/source/tools/ | awk -F ":" '{print $1}') $target_files"
done
if [ $disable_libbpf = "YES" ]; then
disable_target_1=$(grep "bpf\.mk" $(pwd)/source/tools/ -nEr --color | xargs -I {} expr {} : '.*/source/tools/\(.*\)/\(.*\)' |grep -E "combine|bpf_test|cgroup"|awk -F "/" '{print $2}' | uniq)
for single_target_1 in $disable_target_1;do
disable_list="$single_target_1|$disable_list"
done
disable_target_2=$(grep "bpf\.mk" $(pwd)/source/tools/ -nEr --color | xargs -I {} expr {} : '.*/source/tools/\(.*\)/\(.*\)' |grep -v -E "combine|bpf_test|cgroup"|awk -F "/" '{print $3}' | uniq)
for single_target_2 in $disable_target_2;do
disable_list="$single_target_2|$disable_list"
done
fi
if [ $enable_all = "yes" ]; then
target_files=$(grep -nrw "target :=" $(pwd)/source/tools/ | grep -vwE $disable_list | awk -F ":" '{print $1}' | grep "Makefile")
fi
for file in $target_files;do
target_path=$(dirname $file)
target_paths="$target_path $target_paths"
grep -nrw modin $file > /dev/null
if [ $? = 0 ]; then
echo "$target_path need lkm, you may set --enable-lkm"
fi
grep -nr "bpf.mk" $file > /dev/null
if [ $? = 0 ]; then
enable_libbpf="YES"
echo "$target_path need libbpf"
fi
done
check_depend
echo "# Automatically generated by configure - do not modify" > $config_host_mak
if [ $static_link = "yes" ]; then
echo "EXTRA_LDFLAGS = --static" >> $config_host_mak
fi
echo "KERNEL_VERSION = $kern_ver" >> $config_host_mak
echo "OBJPATH = $objdir" >> $config_host_mak
echo "BUILD_KERNEL_MODULE = $enable_lkm" >> $config_host_mak
echo "BUILD_LIBBPF = $enable_libbpf" >> $config_host_mak
echo "TARGET_LIST = $target_paths" >> $config_host_mak
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu_zhengqi/sysak.git
[email protected]:wu_zhengqi/sysak.git
wu_zhengqi
sysak
SysAK
opensource_branch

搜索帮助