This commit is contained in:
xxoommd 2025-05-27 16:35:42 +08:00
parent 71cce2b79b
commit dbd242cfb4

View File

@ -20,69 +20,86 @@ function set_proxy() {
echo echo
} }
function _c3_tool_help() {
echo
echo "Usage:"
echo " - c3tool build|b [ARGS]"
echo " [-u | --update-all] Updating Augustus custom resources and libs: SDL2 SDL2_mixer"
echo " [-f | --force] Clean all and rebuild, including resources and libs"
echo " [-r | --release] Build release version, default is debug"
echo " - c3tool clean|c"
echo
}
function c3tool() { function c3tool() {
__GREEN__='\033[0;32m'
__RED__='\033[0;31m'
__BLUE__='\033[0;34m'
__YELLOW__='\033[0;33m'
__UNDERLINE__='\033[4m' # 下划线
__RESET_COLOR__='\033[0m' # No Color
__NC__='\033[0m' # No Color
# check `cmake` # check `cmake`
if command -v cmake &>/dev/null; then if command -v cmake &>/dev/null; then
echo "[CHECK] cmake 已安装" echo "[CHECK] cmake 已安装"
else else
echo "[CHECK] FAIL: cmake 未安装,请先安装 cmake" echo "[${__RED__}Err${__NC__}] cmake 未安装,请先安装 cmake"
return 0 return 0
fi fi
if command -v mingw32-make &>/dev/null; then if command -v mingw32-make &>/dev/null; then
echo "[CHECK] mingw32-make 已安装" echo "[CHECK] mingw32-make 已安装"
else else
echo "[CHECK] FAIL: mingw32-make 未安装,请先安装 mingw32-make" echo "[${__RED__}Err${__NC__}] mingw32-make 未安装,请先安装 mingw32-make"
return 0 return 0
fi fi
# check if augustus or julius build folder # check augustus or julius project folder
if [[ $PWD =~ "augustus" || $PWD =~ "julius" ]]; then if [ $(basename $PWD) == "build" ]; then
# 判断 basename 是否为 build PROJECT_DIR=$(cd .. && pwd)
if [ "$(basename "$PWD")" = "build" ]; then BUILD_DIR=$PWD
echo "[CHECK] Working directory: $PWD"
else
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
return 1
fi
else else
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录" PROJECT_DIR=$PWD
BUILD_DIR="$PWD/build"
fi
if [ ! -f $PROJECT_DIR/CMakeLists.txt ]; then
echo -e "[${__RED__}ERR${__NC__}] Enter '${__YELLOW__}augustus${__NC__}' or '${__YELLOW__}julius${__NC__}' project first."
return 1 return 1
fi fi
printf "[CHECK] %-20s${__GREEN__}$PROJECT_DIR${__NC__}\n" "Project location:"
echo if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR
fi
printf "[CHECK] %-20s${__GREEN__}$BUILD_DIR${__NC__}\n" "Build location:"
cmd="" TARGET_NAME=$(awk '/set\(SHORT_NAME/ {print $2}' $PROJECT_DIR/CMakeLists.txt | sed 's/)//g')
if [[ $1 == "" || "$1" == -* ]]; then printf "[CHECK] %-20s${__GREEN__}$TARGET_NAME${__NC__}\n" "Target name:"
cmd="build"
else if [[ $1 == "" || "$1" == "-h" || "$1" == "--help" ]]; then
cmd=$1 _c3_tool_help
shift return 0
fi fi
cmd=$1 && shift
force=false force=false
update_res=false update=false
update_libs=false
# Parse args... # Parse args...
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
-r | --update-resources) -u | --update)
update_res=true update=true
;;
-l | --update-libs)
update_libs=true
;; ;;
-f | --force) -f | --force)
force=true force=true
update=true
;; ;;
-a | --all) -r | --release)
force=true BUILD_TYPE=release
update_res=true
update_libs=true
;;
--release)
export CMAKE_BUILD_TYPE=release
;; ;;
esac esac
done done
@ -91,70 +108,70 @@ function c3tool() {
case "$cmd" in case "$cmd" in
b | build) b | build)
if $force; then if $force; then
printf "[BUILD] 清理make文件:" && rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* .cmake && printf "[CLEAN] ... " && rm -rf $BUILD_DIR/* $BUILD_DIR/.* && echo "Done"
echo "Done"
fi fi
printf "evn: - CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE\n\n" printf "[CHECK] %-20s${__GREEN__}$BUILD_TYPE${__NC__}\n" "CMAKE_BUILD_TYPE:"
# cmake # cmake
if [[ ! -f "Makefile" ]]; then if [[ ! -f "Makefile" ]]; then
exec_str="cmake .. -G \"MinGW Makefiles\"" && eval $exec_str exec_str="cd $BUILD_DIR && cmake .. -G \"MinGW Makefiles\" > /dev/null"
eval $exec_str
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[BUILD] FAIL. Execute string: ${exec_str}" echo -e "[${__RED__}ERR${__NC__}] Execute string: ${exec_str}"
return 1 return 1
fi fi
fi fi
# mingw32-make # mingw32-make
echo "开始编译..." echo "[BUILD] Start ..."
if command -v nproc &>/dev/null; then if command -v nproc &>/dev/null; then
makenum=$(nproc) makenum=$(nproc)
else else
makenum=2 makenum=2
fi fi
exec_str="mingw32-make -j$makenum" && eval $exec_str
export CMAKE_BUILD_TYPE=${BUILD_TYPE}
exec_str="cd $BUILD_DIR && mingw32-make -j$makenum --quiet > /dev/null"
eval $exec_str
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[BUILD] FAIL. Execute string: ${exec_str}" unset CMAKE_BUILD_TYPE
echo -e "[${__RED__}ERR${__NC__}] FAIL. Execute string: ${exec_str}"
return 1 return 1
fi fi
unset CMAKE_BUILD_TYPE
if $update_res; then if $update; then
printf "[BUILD] 清理res..." && rm -rf assets maps && echo "Done" if [[ $TARGET_NAME == "augustus" ]]; then
fi printf "[UPDATE] Cleaning res..." && rm -rf assets maps && echo "Done"
fi
if $update_libs; then printf "[UPDATE] Cleaning libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
printf "[BUILD] 清理libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
fi fi
# Updating res: # Updating res:
if [[ ! -d assets || ! -d maps ]]; then if [[ $TARGET_NAME == "augustus" ]]; then
printf "[BUILD] Updating assets ..." && cp -r ../res/assets . && echo "Done" if [[ ! -d assets || ! -d maps ]]; then
printf "[BUILD] Updating maps ..." && cp -r ../res/maps . && echo "Done" printf "[UPDATE] Copying assets ..." && cp -r ../res/assets . && echo "Done"
printf "[UPDATE] Copying maps ..." && cp -r ../res/maps . && echo "Done"
fi
fi fi
# Updating libs: # Updating libs:
if [[ ! -f SDL2.dll || ! -f SDL2_mixer.dll ]]; then if [[ ! -f SDL2.dll || ! -f SDL2_mixer.dll ]]; then
printf "[BUILD] Updating libs ..." && cp ../ext/SDL2/SDL2-2.32.4/x86_64-w64-mingw32/bin/SDL2.dll . && printf "[UPDATE] Copying libs ..." && cp ../ext/SDL2/SDL2-2.32.4/x86_64-w64-mingw32/bin/SDL2.dll . &&
cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . && cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . &&
echo "Done" echo "Done"
fi fi
echo "[BUILD] success" echo -e "[BUILD] Build ${__GREEN__}${TARGET_NAME}${__NC__} success"
;; ;;
c | clean) c | clean)
printf "开始清理..." printf "[CLEAN] ... " && rm -rf $BUILD_DIR/* $BUILD_DIR/.* && echo "Done"
rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* &&
rm -rf assets maps &&
rm -f SDL2* &&
echo "Done"
;; ;;
*) *)
echo "[Err] Invalid cmd: $cmd" echo "[Err] Invalid cmd: $cmd"
echo _c3_tool_help
echo "Usage:"
echo " - c3tool build|b [-r -l -f -a --release]"
echo " - c3tool clean|c"
return 1 return 1
;; ;;
esac esac