forked from walkco/stadia-vigem
/
Build.ps1
99 lines (71 loc) · 2.74 KB
/
Build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[CmdletBinding()]
param (
[Parameter()][ValidateSet("DEBUG", "RELEASE")][string]$Configuration = "DEBUG",
[Parameter()][ValidateSet("x86", "x64", "arm64")][string]$Architecture = "x86",
[Parameter()][bool]$SkipBuildToolsSetup = $false
)
$script:CommonFlags = @("/Zi", "/W4", "/EHsc", "/DWIN32", "/D_UNICODE", "/DUNICODE")
$script:DebugFlags = @( "/Od" )
$script:ReleaseFlags = @("/GL", "/O2")
$script:OutputName = "stadia-vigem-"
function Import-Prerequisites {
if ($SkipBuildToolsSetup -eq $true) {
return
}
if (Get-Module -ListAvailable -Name VSSetup) {
Update-Module -Name VSSetup
} else {
Install-Module -Name VSSetup -Scope CurrentUser -Force
}
Import-Module -Name VSSetup
if (Get-Module -ListAvailable -Name WintellectPowerShell) {
Update-Module -Name WintellectPowerShell
} else {
Install-Module -Name WintellectPowerShell -Scope CurrentUser -Force
}
Import-Module -Name WintellectPowerShell
}
function Invoke-BuildTools {
param (
$Architecture
)
if ($SkipBuildToolsSetup -eq $true) {
return
}
$latestVsInstallationInfo = Get-VSSetupInstance -All | Sort-Object -Property InstallationVersion -Descending | Select-Object -First 1
Invoke-CmdScript "$($latestVsInstallationInfo.InstallationPath)\VC\Auxiliary\Build\vcvarsall.bat" $Architecture
}
function Invoke-Build {
param (
$Architecture
)
$OutputName = "$script:OutputName$Architecture.exe"
$Flags = If ($Configuration -eq "DEBUG") {$script:DebugFlags} else {$script:ReleaseFlags}
$StopWatch = New-Object -TypeName System.Diagnostics.Stopwatch
Write-Host "*** ${OutputName}: Build started ***"
Write-Host
$StopWatch.Start()
& "rc.exe" /foobj/stadia-vigem.res res/res.rc
& "cl.exe" $Flags $CommonFlags advapi32.lib /IViGEmClient/include /Foobj/ /Febin/$OutputName ViGEmClient/src/*.cpp obj/stadia-vigem.res src/*.c
$StopWatch.Stop()
Write-Host
Write-Host "*** ${OutputName}: Build finished in $($StopWatch.Elapsed) ***"
}
# Entry
New-Item -Path "bin" -ItemType Directory -Force > $null
New-Item -Path "obj" -ItemType Directory -Force > $null
Import-Prerequisites
Write-Host "-- Build started. Configuration: $Configuration, Architecture: $Architecture --"
if ($Architecture -eq "x86" -Or $Architecture -eq "ALL") {
Invoke-BuildTools -Architecture "x86"
Invoke-Build -Architecture "x86"
}
if ($Architecture -eq "x64" -Or $Architecture -eq "ALL") {
Invoke-BuildTools -Architecture "x64"
Invoke-Build -Architecture "x64"
}
if ($Architecture -eq "arm64" -Or $Architecture -eq "ALL") {
Invoke-BuildTools -Architecture "arm64"
Invoke-Build -Architecture "arm64"
}
Write-Host "-- Build completed. --"