build.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # 默认构建类型
  3. BUILD_TYPE="Release"
  4. # 解析命令行参数
  5. if [[ "$1" == "--debug" ]]; then
  6. BUILD_TYPE="Debug"
  7. echo "Building ylib in DEBUG mode"
  8. fi
  9. # 安装软件
  10. sudo apt update
  11. sudo apt install -y g++
  12. sudo apt install -y cmake
  13. sudo apt install -y libssl-dev
  14. sudo apt install -y xorg libx11-dev libgl1-mesa-dev
  15. sudo apt install -y openssl
  16. sudo apt install -y libboost-dev
  17. sudo apt install -y libmysqlcppconn-dev
  18. sudo apt install -y libleveldb-dev
  19. sudo apt install -y libsoci-dev
  20. sudo apt install -y unixodbc-dev
  21. sudo apt install -y libz-dev
  22. sudo apt install -y libmimalloc-dev
  23. # 初始化变量
  24. src_dir=$(pwd)
  25. cd ..
  26. root_dir=$(pwd)
  27. install_dir=$(pwd)/ylib_linux_build
  28. # 根据构建类型设置不同的构建目录
  29. if [ "$BUILD_TYPE" == "Debug" ]; then
  30. install_dir="${install_dir}_debug"
  31. echo "Debug build directory: $install_dir"
  32. fi
  33. # 创建必要文件夹
  34. if [ ! -d $install_dir ]; then
  35. mkdir -p $install_dir
  36. else
  37. # 如果目录已存在,清理它
  38. echo "Cleaning existing build directory: $install_dir"
  39. rm -rf $install_dir/*
  40. fi
  41. ######核心######
  42. cd $install_dir
  43. echo "Running cmake with build type: $BUILD_TYPE"
  44. cmake $src_dir -DCMAKE_BUILD_TYPE=$BUILD_TYPE
  45. make -j4
  46. sudo make install
  47. echo "ylib $BUILD_TYPE build completed successfully!"