diff --git a/debug-macos.sh b/debug-macos.sh new file mode 100755 index 000000000..bba561449 --- /dev/null +++ b/debug-macos.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +FRESH=false +ASAN=false +PRO=false +DEBUG=false +MACPORTS=false +HOMEBREW=false +BUILD_TYPE="MinSizeRel" +COMPILER_FLAGS="" +DEBUG_FLAGS="" +PRO_VERSION_FLAG="" + +while (( "$#" )); do + case "$1" in + -f|--fresh) + FRESH=true + shift + ;; + -a|--asan) + ASAN=true + shift + ;; + -p|--pro) + PRO=true + shift + ;; + -d|--debug) + DEBUG=true + shift + ;; + -m|--macports) + MACPORTS=true + shift + ;; + -h|--homebrew) + HOMEBREW=true + shift + ;; + --) + shift + break + ;; + -*) + echo "Unknown option: $1" >&2 + exit 1 + ;; + *) + echo "Invalid argument: $1" >&2 + exit 1 + ;; + esac +done + +if [ "$MACPORTS" = true ] && [ "$HOMEBREW" = true ]; then + echo "Error: -m/--macports and -h/--homebrew options are mutually exclusive." + exit 1 +fi + +# remove MacPorts from PATH if we're not using it or we're using Homebrew +if [ "$MACPORTS" = false ] || [ "$HOMEBREW" = true ]; then + PATH=${PATH/\/opt\/local\/bin:/} +fi + +if [ "$FRESH" = true ]; then + rm -rf .cache CMakeCache.txt CMakeFiles/ cmake_install.cmake + rm -rf build && git restore 'build/*' +fi + +if [ "$ASAN" = true ]; then + DEBUG=true + DEBUG_FLAGS="-DBUILD_NO_OPTIMIZATION=On -DBUILD_ASAN_DEBUG=On" +fi + +if [ "$PRO" = true ]; then + PRO_VERSION_FLAG="-DBUILD_PRO=On" +fi + +if [ "$DEBUG" = true ]; then + BUILD_TYPE="Debug" +fi + +if [ "$MACPORTS" = true ]; then + CLANG=$(which clang) + CLANGPP=$(which clang++) + if [ -z "$CLANG" ] || [ -z "$CLANGPP" ]; then + echo "clang or clang++ not found. Please ensure they are installed and in your PATH." + exit 1 + fi + COMPILER_FLAGS="-DCMAKE_C_COMPILER=$CLANG -DCMAKE_CXX_COMPILER=$CLANGPP" + export CPPFLAGS='-isystem/opt/local/include' + export LDFLAGS='-L/opt/local/lib' + echo + echo "Using clang at $CLANG and clang++ at $CLANGPP from MacPorts" +fi + +if [ "$HOMEBREW" = true ]; then + export PATH="/opt/homebrew/opt/llvm/bin:$PATH" + export LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib" + export CPPFLAGS="-I/opt/homebrew/opt/llvm/include" + echo + echo "Using clang at $(which clang) and clang++ at $(which clang++) from Homebrew" +fi + +echo +echo "+--------------------------------+-------+" +echo "| Build Options | Value |" +echo "+--------------------------------+-------+" +echo "| Fresh build (-f, --fresh) | $(printf "%-5s" $([ "$FRESH" = true ] && echo "Yes" || echo "No")) |" +echo "| Address Sanitizer (-a, --asan) | $(printf "%-5s" $([ "$ASAN" = true ] && echo "Yes" || echo "No")) |" +echo "| Pro version (-p, --pro) | $(printf "%-5s" $([ "$PRO" = true ] && echo "Yes" || echo "No")) |" +echo "| Debug build (-d, --debug) | $(printf "%-5s" $([ "$DEBUG" = true ] && echo "Yes" || echo "No")) |" +echo "| MacPorts (-m, --macports) | $(printf "%-5s" $([ "$MACPORTS" = true ] && echo "Yes" || echo "No")) |" +echo "| Homebrew (-h, --homebrew) | $(printf "%-5s" $([ "$HOMEBREW" = true ] && echo "Yes" || echo "No")) |" +echo "+--------------------------------+-------+" +echo + +cd ./build || exit + +cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ + $PRO_VERSION_FLAG \ + -DBUILD_SDLGPU=On \ + $DEBUG_FLAGS \ + $COMPILER_FLAGS \ + -DBUILD_WITH_ALL=On \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=On \ + .. && \ +cmake --build . --config "$BUILD_TYPE" --parallel diff --git a/debug-windows.ps1 b/debug-windows.ps1 new file mode 100644 index 000000000..52ead24b4 --- /dev/null +++ b/debug-windows.ps1 @@ -0,0 +1,99 @@ +[CmdletBinding()] +param( + [Parameter()] + [Alias("f")] + [switch]$Fresh, + + [Parameter()] + [Alias("p")] + [switch]$Pro, + + [Parameter()] + [Alias("d")] + [switch]$bDebug, + + [Parameter()] + [Alias("x")] + [switch]$Win32, + + [Parameter()] + [Alias("m")] + [switch]$Msys2 +) + +$BUILD_TYPE = "MinSizeRel" +$SDLGPU_FLAG = "-DBUILD_SDLGPU=On" +$PRO_VERSION_FLAG = "" +$ARCH_FLAGS = "-A x64" +$CMAKE_GENERATOR = "" + +if ($Fresh) { + Remove-Item -Path .cache, CMakeCache.txt, CMakeFiles, cmake_install.cmake -Force -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path ".\build\" -Force -Recurse -ErrorAction Stop + Remove-Item -Path ".\vendor\janet\src\conf\janetconf.h" -Force -ErrorAction SilentlyContinue + git restore '.\build\*' + git submodule deinit -f -- .\vendor\janet + git submodule update --init --recursive +} + +if ($Pro) { + $PRO_VERSION_FLAG = "-DBUILD_PRO=On" +} + +if ($bDebug) { + $BUILD_TYPE = "Debug" +} + +if ($Win32) { + $ARCH_FLAGS = "-A Win32 -T v141_xp" + Copy-Item -Path "build\janet\janetconf.h" -Destination "vendor\janet\src\conf\janetconf.h" -Force + $SDLGPU_FLAG = "" +} + +if ($Msys2) { + $ARCH_FLAGS = "" + $CMAKE_GENERATOR = '-G "MinGW Makefiles"' +} else { + $CMAKE_GENERATOR = '-G "Visual Studio 16 2019"' +} + +Write-Host +Write-Host "+-------------------------------+-------+" +Write-Host "| Build Options | Value |" +Write-Host "+-------------------------------+-------+" +Write-Host "| Fresh build (-f, -fresh) | $(if ($Fresh) { "Yes" } else { "No " }) |" +Write-Host "| Pro version (-p, -pro) | $(if ($Pro) { "Yes" } else { "No " }) |" +Write-Host "| Debug build (-d, -bdebug) | $(if ($bDebug) { "Yes" } else { "No " }) |" +Write-Host "| Win32 (-x, -win32) | $(if ($Win32) { "Yes" } else { "No " }) |" +Write-Host "| MSYS2 (-m, -msys2) | $(if ($Msys2) { "Yes" } else { "No " }) |" +Write-Host "+-------------------------------+-------+" +Write-Host + +Set-Location -Path ./build -ErrorAction Stop + +$cmakeCommand = "cmake $CMAKE_GENERATOR " + + "$ARCH_FLAGS " + + "-DCMAKE_BUILD_TYPE=$BUILD_TYPE " + + "$PRO_VERSION_FLAG " + + "$SDLGPU_FLAG " + + "-DBUILD_WITH_ALL=On " + + "-DCMAKE_EXPORT_COMPILE_COMMANDS=On " + + ".." + +Write-Host "Executing CMake Command: $cmakeCommand" +Invoke-Expression $cmakeCommand + +$numCPUs = [Environment]::ProcessorCount + +if ($LASTEXITCODE -eq 0) { + if ($Msys2) { + mingw32-make "-j$numCPUs" + } else { + cmake --build . --config "$BUILD_TYPE" --parallel + } +} else { + Write-Host "(C)Make failed. Exiting." + exit 1 +} + +Set-Location -Path .. -ErrorAction Stop