|
| 1 | +# build_sdl_windows.ps1 |
| 2 | +# Builds SDL 2.32.10 for Windows x64 and installs it into Windows/frameworks/sdl |
| 3 | + |
| 4 | +param( |
| 5 | + [string]$SDL_VERSION = "2.32.10", |
| 6 | + [string]$ROOT_DIR = (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) |
| 7 | +) |
| 8 | + |
| 9 | +$SDL_URL = "https://github.com/libsdl-org/SDL/releases/download/release-${SDL_VERSION}/SDL2-${SDL_VERSION}.tar.gz" |
| 10 | +$TP_DIR = "$ROOT_DIR/Windows/third_party" |
| 11 | +$INSTALL_DIR = "$ROOT_DIR/Windows/frameworks/sdl" |
| 12 | + |
| 13 | +# Create third_party directory |
| 14 | +New-Item -ItemType Directory -Force -Path $TP_DIR | Out-Null |
| 15 | +Push-Location $TP_DIR |
| 16 | + |
| 17 | +# Download if needed |
| 18 | +$ARCHIVE = "SDL2-${SDL_VERSION}.tar.gz" |
| 19 | +if (-Not (Test-Path $ARCHIVE)) { |
| 20 | + Write-Host "Downloading SDL ${SDL_VERSION}..." |
| 21 | + Invoke-WebRequest -Uri $SDL_URL -OutFile $ARCHIVE |
| 22 | +} |
| 23 | + |
| 24 | +# Extract if needed |
| 25 | +$EXTRACT_DIR = "SDL2-${SDL_VERSION}" |
| 26 | +if (-Not (Test-Path $EXTRACT_DIR)) { |
| 27 | + Write-Host "Extracting SDL..." |
| 28 | + # Use 7z if available, otherwise tar (PowerShell 7+) |
| 29 | + if (Get-Command 7z -ErrorAction SilentlyContinue) { |
| 30 | + 7z x $ARCHIVE |
| 31 | + } else { |
| 32 | + tar -xzf $ARCHIVE |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +# Configure & build |
| 37 | +$BUILD_DIR = "$EXTRACT_DIR/build-x64" |
| 38 | +New-Item -ItemType Directory -Force -Path $BUILD_DIR | Out-Null |
| 39 | +Push-Location $BUILD_DIR |
| 40 | + |
| 41 | +Write-Host "Building SDL for x64..." |
| 42 | +cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DSDL_SHARED=ON -DSDL_STATIC=ON |
| 43 | +cmake --build . --config Release -- -m |
| 44 | + |
| 45 | +# Backup |
| 46 | +$timestamp = Get-Date -Format "yyyyMMddHHmmss" |
| 47 | +$BACKUP_DIR = "$INSTALL_DIR/backups" |
| 48 | +New-Item -ItemType Directory -Force -Path $BACKUP_DIR | Out-Null |
| 49 | +if (Test-Path "$INSTALL_DIR/lib") { |
| 50 | + Copy-Item -Path "$INSTALL_DIR/lib" -Destination "$BACKUP_DIR/lib.$timestamp" -Recurse -Force |
| 51 | +} |
| 52 | +if (Test-Path "$INSTALL_DIR/include") { |
| 53 | + Copy-Item -Path "$INSTALL_DIR/include" -Destination "$BACKUP_DIR/include.$timestamp" -Recurse -Force |
| 54 | +} |
| 55 | + |
| 56 | +# Create install directories |
| 57 | +New-Item -ItemType Directory -Force -Path "$INSTALL_DIR/lib/x64" | Out-Null |
| 58 | +New-Item -ItemType Directory -Force -Path "$INSTALL_DIR/include" | Out-Null |
| 59 | + |
| 60 | +# Copy artifacts (Release build) |
| 61 | +$RELEASE_BUILD = "Release" |
| 62 | +Copy-Item -Path "$BUILD_DIR/$RELEASE_BUILD/SDL2.lib" -Destination "$INSTALL_DIR/lib/x64/SDL2.lib" -Force |
| 63 | +Copy-Item -Path "$BUILD_DIR/$RELEASE_BUILD/SDL2.dll" -Destination "$INSTALL_DIR/lib/x64/SDL2.dll" -Force |
| 64 | +Copy-Item -Path "$BUILD_DIR/$RELEASE_BUILD/SDL2main.lib" -Destination "$INSTALL_DIR/lib/x64/SDL2main.lib" -Force |
| 65 | + |
| 66 | +# Install headers |
| 67 | +Remove-Item -Path "$INSTALL_DIR/include/SDL2" -Recurse -Force -ErrorAction SilentlyContinue |
| 68 | +Copy-Item -Path "$BUILD_DIR/include/SDL2" -Destination "$INSTALL_DIR/include/" -Recurse -Force |
| 69 | +Copy-Item -Path "$BUILD_DIR/$RELEASE_BUILD/SDL_config.h" -Destination "$INSTALL_DIR/include/SDL2/SDL_config.h" -Force |
| 70 | + |
| 71 | +Write-Host "SDL ${SDL_VERSION} built and installed into ${INSTALL_DIR}" |
| 72 | +Pop-Location |
| 73 | +Pop-Location |
0 commit comments