89 lines
3.0 KiB
PowerShell
89 lines
3.0 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[ValidateSet('Debug', 'Release')]
|
|
[string]$Configuration = 'Debug',
|
|
[string]$WdkRoot
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$projectDir = $PSScriptRoot
|
|
$repoRoot = (Resolve-Path (Join-Path $projectDir '..\..')).Path
|
|
. (Join-Path $projectDir 'common.ps1')
|
|
$wdkRoot = Find-Qa6WdkRoot -ExplicitRoot $WdkRoot -RepoRoot $repoRoot
|
|
$wdkVersion = Find-Qa6WdkVersion -WdkRoot $wdkRoot
|
|
$wdfVersion = '1.33'
|
|
$sdkRoot = 'C:\Program Files (x86)\Windows Kits\10'
|
|
$msvcRoot = Find-Qa6MsvcRoot
|
|
$toolBin = Join-Path $msvcRoot 'bin\Hostx64\x64'
|
|
$outputDir = Join-Path $projectDir "build\$Configuration\x64"
|
|
$objectPath = Join-Path $outputDir 'driver.obj'
|
|
$sysPath = Join-Path $outputDir 'QemuA6Ude.sys'
|
|
$pdbPath = Join-Path $outputDir 'QemuA6Ude.pdb'
|
|
$compilePdbPath = Join-Path $outputDir 'QemuA6Ude-compile.pdb'
|
|
|
|
foreach ($required in @(
|
|
(Join-Path $toolBin 'cl.exe'),
|
|
(Join-Path $toolBin 'link.exe'),
|
|
(Join-Path $wdkRoot "Include\$wdkVersion\km\ude\1.0\UdeCx.h")
|
|
)) {
|
|
if (-not (Test-Path -LiteralPath $required -PathType Leaf)) {
|
|
throw "Composant de compilation introuvable : $required"
|
|
}
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
|
|
|
|
$compileArgs = @(
|
|
'/nologo', '/c', '/kernel', '/Zp8', '/W4', '/WX-', '/Zi', '/Oi',
|
|
'/D_AMD64_', '/DAMD64', '/DWIN64', '/D_WIN64',
|
|
'/DNTDDI_VERSION=0x0A00000C', '/D_WIN32_WINNT=0x0A00',
|
|
'/DUNICODE', '/D_UNICODE', '/D_WDF_',
|
|
'/DKMDF_VERSION_MAJOR=1', '/DKMDF_VERSION_MINOR=33',
|
|
"/I$msvcRoot\include",
|
|
"/I$wdkRoot\Include\$wdkVersion\km",
|
|
"/I$wdkRoot\Include\$wdkVersion\shared",
|
|
"/I$sdkRoot\Include\$wdkVersion\shared",
|
|
"/I$sdkRoot\Include\$wdkVersion\um",
|
|
"/I$sdkRoot\Include\$wdkVersion\ucrt",
|
|
"/I$wdkRoot\Include\wdf\kmdf\$wdfVersion",
|
|
"/Fo$objectPath", "/Fd$compilePdbPath",
|
|
(Join-Path $projectDir 'driver.c')
|
|
)
|
|
if ($Configuration -eq 'Release') {
|
|
$compileArgs += @('/O2', '/GL')
|
|
} else {
|
|
$compileArgs += @('/Od')
|
|
}
|
|
|
|
& (Join-Path $toolBin 'cl.exe') @compileArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "La compilation du pilote a échoué ($LASTEXITCODE)."
|
|
}
|
|
|
|
$kmLib = Join-Path $wdkRoot "Lib\$wdkVersion\km\x64"
|
|
$wdfLib = Join-Path $wdkRoot "Lib\wdf\kmdf\x64\$wdfVersion"
|
|
$linkArgs = @(
|
|
'/nologo', '/driver', '/subsystem:native,10.00', '/entry:FxDriverEntry',
|
|
'/kernel', '/nodefaultlib', '/incremental:no', '/debug',
|
|
'/opt:ref', '/opt:icf', '/merge:_TEXT=.text', '/section:INIT,d',
|
|
"/out:$sysPath", "/pdb:$pdbPath",
|
|
"/libpath:$kmLib", "/libpath:$wdfLib",
|
|
(Join-Path $kmLib 'ude\1.0\udecxstub.lib'),
|
|
'usbdex.lib', 'WdmSec.lib', 'ntstrsafe.lib',
|
|
'BufferOverflowFastFailK.lib', 'ntoskrnl.lib', 'hal.lib', 'wmilib.lib',
|
|
'wdfldr.lib', 'wdfdriverentry.lib',
|
|
$objectPath
|
|
)
|
|
if ($Configuration -eq 'Release') {
|
|
$linkArgs += '/LTCG'
|
|
}
|
|
|
|
& (Join-Path $toolBin 'link.exe') @linkArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "L'édition de liens du pilote a échoué ($LASTEXITCODE)."
|
|
}
|
|
|
|
Copy-Item -LiteralPath (Join-Path $projectDir 'QemuA6Ude.inf') -Destination $outputDir -Force
|
|
Write-Host "Pilote construit : $sysPath"
|