Files
2026-08-14 15:56:39 -04:00

143 lines
4.5 KiB
PowerShell

param(
[string]$RunewakerSourceRoot = $env:RUNEWAKER_SOURCE_ROOT,
[string]$PortableMsvcRoot = $env:MSVC_V142_ROOT,
[string]$WindowsSdkRoot = ${env:ProgramFiles(x86)} + '\Windows Kits\10'
)
$ErrorActionPreference = 'Stop'
$scriptRoot = $PSScriptRoot
$projectRoot = [IO.Path]::GetFullPath((Join-Path $scriptRoot '..\..\..'))
if ([string]::IsNullOrWhiteSpace($RunewakerSourceRoot)) {
$RunewakerSourceRoot = [IO.Path]::GetFullPath((Join-Path $projectRoot '..\rom-pvt-server-backups\Runewaker\SourceCodeVS2019'))
}
if ([string]::IsNullOrWhiteSpace($PortableMsvcRoot)) {
$PortableMsvcRoot = Join-Path $env:USERPROFILE 'msvc-v142-portable\Contents\VC\Tools\MSVC'
}
if (-not (Test-Path -LiteralPath $RunewakerSourceRoot)) {
throw "Runewaker source root not found: $RunewakerSourceRoot"
}
if (-not (Test-Path -LiteralPath $PortableMsvcRoot)) {
throw "Portable MSVC root not found: $PortableMsvcRoot"
}
if (-not (Test-Path -LiteralPath $WindowsSdkRoot)) {
throw "Windows SDK root not found: $WindowsSdkRoot"
}
$msvcVersionRoot = Get-ChildItem -LiteralPath $PortableMsvcRoot -Directory |
Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'bin\Hostx64\x64\cl.exe') } |
Sort-Object Name -Descending |
Select-Object -First 1
if ($null -eq $msvcVersionRoot) {
throw "cl.exe was not found below $PortableMsvcRoot"
}
$sdkVersionRoot = Get-ChildItem -LiteralPath (Join-Path $WindowsSdkRoot 'Include') -Directory |
Where-Object {
(Test-Path -LiteralPath (Join-Path $_.FullName 'um\Windows.h')) -and
(Test-Path -LiteralPath (Join-Path $WindowsSdkRoot ('Lib\' + $_.Name + '\um\x64\kernel32.lib')))
} |
Sort-Object Name -Descending |
Select-Object -First 1
if ($null -eq $sdkVersionRoot) {
throw "A usable Windows 10 SDK was not found below $WindowsSdkRoot"
}
$msvcRoot = $msvcVersionRoot.FullName
$sdkVersion = $sdkVersionRoot.Name
$sdkIncludeRoot = Join-Path $WindowsSdkRoot ('Include\' + $sdkVersion)
$sdkLibRoot = Join-Path $WindowsSdkRoot ('Lib\' + $sdkVersion)
$compilerRoot = Join-Path $msvcRoot 'bin\Hostx64\x64'
$env:Path = $compilerRoot + ';' + (Join-Path $WindowsSdkRoot ('bin\' + $sdkVersion + '\x64')) + ';' + $env:Path
$env:Include = @(
(Join-Path $msvcRoot 'include')
(Join-Path $sdkIncludeRoot 'ucrt')
(Join-Path $sdkIncludeRoot 'shared')
(Join-Path $sdkIncludeRoot 'um')
(Join-Path $sdkIncludeRoot 'winrt')
) -join ';'
$env:Lib = @(
(Join-Path $msvcRoot 'lib\x64')
(Join-Path $sdkLibRoot 'ucrt\x64')
(Join-Path $sdkLibRoot 'um\x64')
) -join ';'
$buildRoot = Join-Path $scriptRoot 'build'
$binRoot = Join-Path $scriptRoot 'bin'
New-Item -ItemType Directory -Path $buildRoot -Force | Out-Null
New-Item -ItemType Directory -Path $binRoot -Force | Out-Null
$sourceFile = Join-Path $scriptRoot 'runewaker_model_exporter.cpp'
$objectFile = Join-Path $buildRoot 'runewaker_model_exporter.obj'
$outputFile = Join-Path $binRoot 'runewaker_model_exporter.exe'
$librariesRoot = Join-Path $RunewakerSourceRoot 'Libraries'
$engineRoot = Join-Path $librariesRoot 'Rune Engine'
$compileArguments = @(
'/nologo'
'/EHsc'
'/O2'
'/MD'
'/std:c++17'
'/DNDEBUG'
'/D_LIB'
'/DCLOSE_DEBUG'
'/DWINDOWS_IGNORE_PACKING_MISMATCH'
'/I'
$librariesRoot
'/I'
(Join-Path $RunewakerSourceRoot 'SDK')
'/I'
(Join-Path $RunewakerSourceRoot 'SDK\dx9')
'/I'
(Join-Path $RunewakerSourceRoot 'SDK\fmod')
'/I'
(Join-Path $RunewakerSourceRoot 'SDK\lua')
'/I'
(Join-Path $engineRoot 'Tools')
'/I'
(Join-Path $librariesRoot 'Tools\tools')
'/I'
(Join-Path $librariesRoot 'Tools\tools\lua')
'/I'
(Join-Path $librariesRoot 'Tools\tools\luabind')
('/Fo' + $objectFile)
('/Fe' + $outputFile)
$sourceFile
'/link'
'/LTCG'
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\Rune Engine\x64\Release'))
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\Rune Engine NULL\x64\Release'))
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot '_bin\ToolsLib\Release'))
('/LIBPATH:' + (Join-Path $RunewakerSourceRoot 'SDK\lib'))
('/LIBPATH:' + (Join-Path $engineRoot 'Tools\granny\lib'))
'Rune.lib'
'Rune_NULL.lib'
'ToolsLib.lib'
'kernel32.lib'
'user32.lib'
'advapi32.lib'
'shell32.lib'
'ole32.lib'
'oleaut32.lib'
'uuid.lib'
'winmm.lib'
'ws2_32.lib'
)
Write-Host "Building with MSVC $($msvcVersionRoot.Name) and Windows SDK $sdkVersion"
& (Join-Path $compilerRoot 'cl.exe') $compileArguments
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Host "Built $outputFile"