57 lines
1.7 KiB
PowerShell
57 lines
1.7 KiB
PowerShell
[CmdletBinding()]
|
||
param(
|
||
[ValidateSet('Debug', 'Release')]
|
||
[string]$Configuration = 'Release'
|
||
)
|
||
|
||
$ErrorActionPreference = 'Stop'
|
||
|
||
$projectDir = $PSScriptRoot
|
||
. (Join-Path $projectDir '..\QemuA6Ude\common.ps1')
|
||
$msvcRoot = Find-Qa6MsvcRoot
|
||
$vsInstall = (Resolve-Path (Join-Path $msvcRoot '..\..\..\..')).Path
|
||
$vsDevCmd = Join-Path $vsInstall 'Common7\Tools\VsDevCmd.bat'
|
||
$cl = Join-Path $msvcRoot 'bin\Hostx64\x64\cl.exe'
|
||
$outputDir = Join-Path $projectDir "build\$Configuration\x64"
|
||
$exePath = Join-Path $outputDir 'QemuA6UsbBridge.exe'
|
||
|
||
if (-not (Test-Path -LiteralPath $vsDevCmd -PathType Leaf)) {
|
||
throw "Environnement Visual Studio introuvable : $vsDevCmd"
|
||
}
|
||
|
||
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
|
||
|
||
$environmentCommand = 'call "{0}" -arch=x64 -host_arch=x64 >nul && set' -f $vsDevCmd
|
||
$environmentLines = & cmd.exe /d /s /c $environmentCommand
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw 'Impossible de charger l’environnement MSVC x64.'
|
||
}
|
||
foreach ($line in $environmentLines) {
|
||
$separator = $line.IndexOf('=')
|
||
if ($separator -gt 0) {
|
||
$name = $line.Substring(0, $separator)
|
||
$value = $line.Substring($separator + 1)
|
||
Set-Item -Path "Env:$name" -Value $value
|
||
}
|
||
}
|
||
|
||
$arguments = @('/nologo', '/W4', '/D_CRT_SECURE_NO_WARNINGS', '/MT')
|
||
if ($Configuration -eq 'Release') {
|
||
$arguments += @('/O2')
|
||
} else {
|
||
$arguments += @('/Od', '/Zi')
|
||
}
|
||
$arguments += @(
|
||
"/Fo:$outputDir\bridge.obj",
|
||
(Join-Path $projectDir 'bridge.c'),
|
||
"/Fe:$exePath",
|
||
'/link', 'ws2_32.lib'
|
||
)
|
||
|
||
& $cl @arguments
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "La compilation du pont USB a échoué ($LASTEXITCODE)."
|
||
}
|
||
|
||
Write-Host "Pont construit : $exePath"
|