🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
12 KiB

  1. #
  2. # winrtbuild.ps1 -- A Powershell script to build all SDL/WinRT variants,
  3. # across all WinRT platforms, in all of their supported, CPU architectures.
  4. #
  5. # Initial version written by David Ludwig <dludwig@pobox.com>
  6. #
  7. # This script can be launched from Windows Explorer by double-clicking
  8. # on winrtbuild.bat
  9. #
  10. # Output will be placed in the following subdirectories of the SDL source
  11. # tree:
  12. # * VisualC-WinRT\lib\ -- final .dll, .lib, and .pdb files
  13. # * VisualC-WinRT\obj\ -- intermediate build files
  14. #
  15. # Recommended Dependencies:
  16. # * Windows 8.1 or higher
  17. # * Powershell 4.0 or higher (included as part of Windows 8.1)
  18. # * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
  19. # * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
  20. # * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
  21. # Windows Phone 8.1, as needed
  22. #
  23. # Commom parameters/variables may include, but aren't strictly limited to:
  24. # * PlatformToolset: the name of one of Visual Studio's build platforms.
  25. # Different PlatformToolsets output different binaries. One
  26. # PlatformToolset exists for each WinRT platform. Possible values
  27. # may include:
  28. # - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
  29. # - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
  30. # - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
  31. # - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
  32. # * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
  33. # * VSProjectName: the internal name of a Visual Studio or Visual C++ project
  34. # file. Some of Visual Studio's own build tools use this name when
  35. # calculating paths for build-output.
  36. # * Platform: a Visual Studio platform name, which often maps to a CPU
  37. # CPU architecture. Possible values may include: "Win32" (for 32-bit x86),
  38. # "ARM", or "x64" (for 64-bit x86).
  39. #
  40. # Base version of SDL, used for packaging purposes
  41. $SDLVersion = "2.0.22"
  42. # Gets the .bat file that sets up an MSBuild environment, given one of
  43. # Visual Studio's, "PlatformToolset"s.
  44. function Get-MSBuild-Env-Launcher
  45. {
  46. param(
  47. [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
  48. )
  49. if ($PlatformToolset -eq "v110") { # Windows 8.0 (not Windows Phone), via VS 2012
  50. return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
  51. }
  52. if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
  53. return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
  54. }
  55. if ($PlatformToolset -eq "v120") { # Windows 8.1 (not Windows Phone), via VS 2013
  56. return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
  57. }
  58. if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
  59. return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
  60. }
  61. if ($PlatformToolset -eq "v140") { # Windows 10, via VS 2015
  62. return "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
  63. }
  64. return ""
  65. }
  66. # Gets a string that identifies the build-variant of SDL/WinRT that is specific
  67. # to a particular Visual Studio PlatformToolset.
  68. function Get-SDL-WinRT-Variant-Name
  69. {
  70. param(
  71. [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
  72. # If true, append a string to this function's output, identifying the
  73. # build-variant's minimum-supported version of Visual Studio.
  74. [switch]$IncludeVSSuffix = $false
  75. )
  76. if ($PlatformToolset -eq "v110") { # Windows 8.0 (not Windows Phone), via VS 2012 project files
  77. if ($IncludeVSSuffix) {
  78. return "WinRT80_VS2012"
  79. } else {
  80. return "WinRT80"
  81. }
  82. }
  83. if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
  84. if ($IncludeVSSuffix) {
  85. return "WinPhone80_VS2012"
  86. } else {
  87. return "WinPhone80"
  88. }
  89. }
  90. if ($PlatformToolset -eq "v120") { # Windows 8.1 (not Windows Phone), via VS 2013 project files
  91. if ($IncludeVSSuffix) {
  92. return "WinRT81_VS2013"
  93. } else {
  94. return "WinRT81"
  95. }
  96. }
  97. if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
  98. if ($IncludeVSSuffix) {
  99. return "WinPhone81_VS2013"
  100. } else {
  101. return "WinPhone81"
  102. }
  103. }
  104. if ($PlatformToolset -eq "v140") { # Windows 10, via VS 2015 project files
  105. if ($IncludeVSSuffix) {
  106. return "UWP_VS2015"
  107. } else {
  108. return "UWP"
  109. }
  110. }
  111. return ""
  112. }
  113. # Returns the internal name of a Visual Studio Project.
  114. #
  115. # The internal name of a VS Project is encoded inside the project file
  116. # itself, inside a set of <ProjectName></ProjectName> XML tags.
  117. function Get-VS-ProjectName
  118. {
  119. param(
  120. [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
  121. )
  122. # For now, just do a regex for the project name:
  123. $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
  124. foreach ($match in $matches) {
  125. if ($match.Groups.Count -ge 1) {
  126. return $match.Groups[1].Value
  127. }
  128. }
  129. return $null
  130. }
  131. # Build a specific variant of SDL/WinRT
  132. function Build-SDL-WinRT-Variant
  133. {
  134. #
  135. # Read in arguments:
  136. #
  137. param (
  138. # name of an SDL project file, minus extensions and
  139. # platform-identifying suffixes
  140. [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
  141. [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
  142. [Parameter(Mandatory=$true,Position=3)][string]$Platform
  143. )
  144. #
  145. # Derive other properties from read-in arguments:
  146. #
  147. # The .bat file to setup a platform-appropriate MSBuild environment:
  148. $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
  149. # The full path to the VS Project that'll be built:
  150. $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
  151. # The internal name of the VS Project, used in some post-build steps:
  152. $VSProjectName = Get-VS-ProjectName $VSProjectPath
  153. # Where to place output binaries (.dll, .lib, and .pdb files):
  154. $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
  155. # Where to place intermediate build files:
  156. $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
  157. #
  158. # Build the VS Project:
  159. #
  160. cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Configuration=Release /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
  161. $BuildResult = $?
  162. #
  163. # Move .dll files into place. This fixes a problem whereby MSBuild may
  164. # put output files into a sub-directory of $OutDir, rather than $OutDir
  165. # itself.
  166. #
  167. if (Test-Path "$OutDir\$VSProjectName\") {
  168. Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
  169. }
  170. #
  171. # Clean up unneeded files in $OutDir:
  172. #
  173. if (Test-Path "$OutDir\$VSProjectName\") {
  174. Remove-Item -Recurse "$OutDir\$VSProjectName"
  175. }
  176. Remove-Item "$OutDir\*.exp"
  177. Remove-Item "$OutDir\*.ilk"
  178. Remove-Item "$OutDir\*.pri"
  179. #
  180. # All done. Indicate success, or failure, to the caller:
  181. #
  182. #echo "RESULT: $BuildResult" | Out-Host
  183. return $BuildResult
  184. }
  185. #
  186. # Build each variant, with corresponding .dll, .lib, and .pdb files:
  187. #
  188. $DidAnyDLLBuildFail = $false
  189. $DidAnyNugetBuildFail = $false
  190. # Ryan disabled WP8.0, because it doesn't appear to have mmdeviceapi.h that SDL_wasapi needs.
  191. # My assumption is that no one will miss this, but send patches otherwise! --ryan.
  192. # Build for Windows Phone 8.0, via VC++ 2012:
  193. #if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM")) { $DidAnyDLLBuildFail = $true }
  194. #if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyDLLBuildFail = $true }
  195. # Build for Windows Phone 8.1, via VC++ 2013:
  196. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM")) { $DidAnyDLLBuildFail = $true }
  197. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyDLLBuildFail = $true }
  198. # Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
  199. #
  200. # Win 8.0 auto-building was disabled on 2017-Feb-25, by David Ludwig <dludwig@pobox.com>.
  201. # Steam's OS-usage surveys indicate that Windows 8.0 use is pretty much nil, plus
  202. # Microsoft hasn't supported Windows 8.0 development for a few years now.
  203. # The commented-out lines below may still work on some systems, though.
  204. #
  205. #if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM")) { $DidAnyDLLBuildFail = $true }
  206. #if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32")) { $DidAnyDLLBuildFail = $true }
  207. #if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64")) { $DidAnyDLLBuildFail = $true }
  208. # Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
  209. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM")) { $DidAnyDLLBuildFail = $true }
  210. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32")) { $DidAnyDLLBuildFail = $true }
  211. if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64")) { $DidAnyDLLBuildFail = $true }
  212. # Build for Windows 10, via VC++ 2015
  213. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "ARM")) { $DidAnyDLLBuildFail = $true }
  214. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "Win32")) { $DidAnyDLLBuildFail = $true }
  215. if ( ! (Build-SDL-WinRT-Variant "SDL" "v140" "x64")) { $DidAnyDLLBuildFail = $true }
  216. # Build NuGet packages, if possible
  217. if ($DidAnyDLLBuildFail -eq $true) {
  218. Write-Warning -Message "Unable to build all variants. NuGet packages will not be built."
  219. $DidAnyNugetBuildFail = $true
  220. } else {
  221. $NugetPath = (Get-Command -CommandType Application nuget.exe | %{$_.Path}) 2> $null
  222. if ("$NugetPath" -eq "") {
  223. Write-Warning -Message "Unable to find nuget.exe. NuGet packages will not be built."
  224. $DidAnyNugetBuildFail = $true
  225. } else {
  226. Write-Host -ForegroundColor Cyan "Building SDL2 NuGet packages..."
  227. Write-Host -ForegroundColor Cyan "... via NuGet install: $NugetPath"
  228. $NugetOutputDir = "$PSScriptRoot\..\VisualC-WinRT\lib\nuget"
  229. Write-Host -ForegroundColor Cyan "... output directory: $NugetOutputDir"
  230. $SDLHGRevision = $($(hg log -l 1 --repository "$PSScriptRoot\.." | select-string "changeset") -Replace "changeset:\W*(\d+).*",'$1') 2>$null
  231. Write-Host -ForegroundColor Cyan "... HG Revision: $SDLHGRevision"
  232. # Base options to nuget.exe
  233. $NugetOptions = @("pack", "PACKAGE_NAME_WILL_GO_HERE", "-Output", "$NugetOutputDir")
  234. # Try attaching hg revision to NuGet package:
  235. $NugetOptions += "-Version"
  236. if ("$SDLHGRevision" -eq "") {
  237. Write-Warning -Message "Unable to find the Mercurial revision (maybe hg.exe can't be found?). NuGet packages will not have this attached to their name."
  238. $NugetOptions += "$SDLVersion-Unofficial"
  239. } else {
  240. $NugetOptions += "$SDLVersion.$SDLHGRevision-Unofficial"
  241. }
  242. # Create NuGet output dir, if not yet created:
  243. if ($(Test-Path "$NugetOutputDir") -eq $false) {
  244. New-Item "$NugetOutputDir" -type directory
  245. }
  246. # Package SDL2:
  247. $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2-WinRT.nuspec"
  248. &"$NugetPath" $NugetOptions -Symbols
  249. if ( ! $? ) { $DidAnyNugetBuildFail = $true }
  250. # Package SDL2main:
  251. $NugetOptions[1] = "$PSScriptRoot\..\VisualC-WinRT\SDL2main-WinRT-NonXAML.nuspec"
  252. &"$NugetPath" $NugetOptions
  253. if ( ! $? ) { $DidAnyNugetBuildFail = $true }
  254. }
  255. }
  256. # Let the script's caller know whether or not any errors occurred.
  257. # Exit codes compatible with Buildbot are used (1 for error, 0 for success).
  258. if ($DidAnyDLLBuildFail -eq $true) {
  259. Write-Error -Message "Unable to build all known variants of SDL2 for WinRT"
  260. exit 1
  261. } elseif ($DidAnyNugetBuildFail -eq $true) {
  262. Write-Warning -Message "Unable to build NuGet packages"
  263. exit 0 # Should NuGet package build failure lead to a non-failing result code instead?
  264. } else {
  265. exit 0
  266. }