This commit is contained in:
xxoommd 2025-04-27 13:34:06 +08:00
parent 395ee7a49e
commit d7d36f793a

View File

@ -20,46 +20,135 @@ function set_proxy() {
echo
}
function c3_build() {
function c3tool() {
# check `cmake`
if command -v cmake &> /dev/null; then
echo "[CHECK] cmake 已安装"
else
echo "[CHECK] FAIL: cmake 未安装,请先安装 cmake"
return 0
fi
if command -v mingw32-make &> /dev/null; then
echo "[CHECK] mingw32-make 已安装"
else
echo "[CHECK] FAIL: mingw32-make 未安装,请先安装 mingw32-make"
return 0
fi
# check if augustus or julius build folder
if [[ $PWD =~ "augustus" || $PWD =~ "julius" ]]; then
# 判断 basename 是否为 build
if [ "$(basename "$PWD")" = "build" ]; then
echo "当前目录: $PWD"
echo "[CHECK] Working directory: $PWD"
else
echo "【错误】进入 'augustus' 或者 'julius' 的 'build' 目录"
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
return 1
fi
else
echo "【错误】进入 'augustus' 或者 'julius' 的 'build' 目录"
echo "[CHECK] FAIL: 进入 'augustus' 或者 'julius' 的 'build' 目录"
return 1
fi
echo
cmd=$1
MINGW32_MAKE_PATH="mingw32-make"
if [[ -z $cmd || $cmd == "build" ]]; then
if [[ ! -f "Makefile" ]]; then
cmake .. -G "MinGW Makefiles"
fi
$MINGW32_MAKE_PATH -j$(nproc)
rm -rf assets maps
echo
echo " - Updating assets ..." && cp -r ../res/assets .
echo " - Updating maps ..." && cp -r ../res/maps .
echo " - Updating 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 .
elif [[ $cmd == "clean" ]]; then
echo "开始清理..."
echo " - Deleting CMakeCache.txt ..." && rm -rf CMakeCache.txt
echo " - Deleting CMakeFiles ..." && rm -rf CMakeFiles
echo " - Deleting Makefile ..." && rm -f Makefile
echo " - Deleting cmake_install.cmake ..." && rm -f cmake_install.cmake
echo " - Deleting compile_commands.json ..." && rm -f compile_commands.json
echo " - Deleting augustus.* ..." && rm -f augustus.*
echo " - Deleting res ..." && rm -rf assets maps
echo " - Deleting libs ..." && rm -rf SDL2*
echo " - Deleting Logs ..." && rm -rf *log*.txt
cmd=""
if [[ $1 == "" || "$1" == -* ]]; then
cmd="build"
else
cmd=$1; shift;
fi
force=false
update_res=false
update_libs=false
# Parse args...
for arg in "$@"; do
case "$arg" in
-r|--update-resources)
update_res=true
;;
-l|--update-libs)
update_libs=true
;;
-f|--force)
force=true
;;
-a|--all)
force=true
update_res=true
update_libs=true
;;
esac
done
# Execute cmd...
case "$cmd" in
b|build)
if $force; then
printf "[BUILD] 清理make文件:" && rm -rf CMakeCache.txt CMakeFiles Makefile cmake_install.cmake compile_commands.json augustus* && \
echo "Done"
fi
# cmake
if [[ ! -f "Makefile" ]]; then
exec_str="cmake .. -G \"MinGW Makefiles\"" && eval $exec_str
if [ $? -ne 0 ]; then
echo "[BUILD] FAIL. Execute string: ${exec_str}"
return 1
fi
fi
# mingw32-make
echo "开始编译..."
if command -v nproc &> /dev/null; then
makenum=$(nproc)
else
makenum=2
fi
exec_str="mingw32-make -j$makenum" && eval $exec_str
if [ $? -ne 0 ]; then
echo "[BUILD] FAIL. Execute string: ${exec_str}"
return 1
fi
if $update_res; then
printf "[BUILD] 清理res..." && rm -rf assets maps && echo "Done"
fi
if $update_libs; then
printf "[BUILD] 清理libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
fi
# Updating res:
if [[ ! -d assets || ! -d maps ]]; then
printf "[BUILD] Updating assets ..." && cp -r ../res/assets . && echo "Done"
printf "[BUILD] Updating maps ..." && cp -r ../res/maps . && echo "Done"
fi
# Updating libs:
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 . && \
cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . && \
echo "Done"
fi
echo "[BUILD] success"
;;
c|clean)
printf "开始清理..."
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
echo "Usage:"
echo " - c3tool build|b [-r -l -f -a]"
echo " - c3tool clean|c"
return 1
esac
}