build-scripts/winrt-build.ps1
author David Ludwig <dludwig@pobox.com>
Mon, 03 Nov 2014 08:58:49 -0500
changeset 9216 61cf772a4ed3
permissions -rw-r--r--
WinRT: added scripts to build Release copies of SDL for all WinRT variants

These variants include:
- Windows 8.0 for x86
- Windows 8.0 for x64
- Windows 8.0 for ARM
- Windows 8.1 for x86
- Windows 8.1 for x64
- Windows 8.1 for ARM
- Windows Phone 8.0 for x86 (for use with the Windows Phone emulator)
- Windows Phone 8.0 for ARM
- Windows Phone 8.1 for x86 (for use with the Windows Phone emulator)
- Windows Phone 8.1 for ARM
dludwig@9216
     1
#
dludwig@9216
     2
# winrt-build.ps1 -- A Powershell script to build all SDL/WinRT variants,
dludwig@9216
     3
#    across all WinRT platforms, in all of their supported, CPU architectures.
dludwig@9216
     4
#
dludwig@9216
     5
# Initial version written by David Ludwig <dludwig@pobox.com>
dludwig@9216
     6
#
dludwig@9216
     7
# This script can be launched from Windows Explorer by double-clicking
dludwig@9216
     8
# on winrt-build.bat
dludwig@9216
     9
#
dludwig@9216
    10
# Output will be placed in the following subdirectories of the SDL source
dludwig@9216
    11
# tree:
dludwig@9216
    12
#   * VisualC-WinRT\lib\  -- final .dll, .lib, and .pdb files
dludwig@9216
    13
#   * VisualC-WinRT\obj\  -- intermediate build files
dludwig@9216
    14
#
dludwig@9216
    15
# Recommended Dependencies:
dludwig@9216
    16
#   * Windows 8.1 or higher
dludwig@9216
    17
#   * Powershell 4.0 or higher (included as part of Windows 8.1)
dludwig@9216
    18
#   * Visual C++ 2012, for building Windows 8.0 and Windows Phone 8.0 binaries.
dludwig@9216
    19
#   * Visual C++ 2013, for building Windows 8.1 and Windows Phone 8.1 binaries
dludwig@9216
    20
#   * SDKs for Windows 8.0, Windows 8.1, Windows Phone 8.0, and
dludwig@9216
    21
#     Windows Phone 8.1, as needed
dludwig@9216
    22
#
dludwig@9216
    23
# Commom parameters/variables may include, but aren't strictly limited to:
dludwig@9216
    24
#   * PlatformToolset: the name of one of Visual Studio's build platforms.
dludwig@9216
    25
#     Different PlatformToolsets output different binaries.  One
dludwig@9216
    26
#     PlatformToolset exists for each WinRT platform.  Possible values
dludwig@9216
    27
#     may include:
dludwig@9216
    28
#       - "v110": Visual Studio 2012 build tools, plus the Windows 8.0 SDK
dludwig@9216
    29
#       - "v110_wp80": Visual Studio 2012 build tools, plus the Windows Phone 8.0 SDK
dludwig@9216
    30
#       - "v120": Visual Studio 2013 build tools, plus the Windows 8.1 SDK
dludwig@9216
    31
#       - "v120_wp81": Visual Studio 2013 build tools, plus the Windows Phone 8.1 SDK
dludwig@9216
    32
#   * VSProjectPath: the full path to a Visual Studio or Visual C++ project file
dludwig@9216
    33
#   * VSProjectName: the internal name of a Visual Studio or Visual C++ project
dludwig@9216
    34
#     file.  Some of Visual Studio's own build tools use this name when
dludwig@9216
    35
#     calculating paths for build-output.
dludwig@9216
    36
#   * Platform: a Visual Studio platform name, which often maps to a CPU
dludwig@9216
    37
#     CPU architecture.  Possible values may include: "Win32" (for 32-bit x86),
dludwig@9216
    38
#     "ARM", or "x64" (for 64-bit x86).
dludwig@9216
    39
#
dludwig@9216
    40
dludwig@9216
    41
dludwig@9216
    42
# Gets the .bat file that sets up an MSBuild environment, given one of
dludwig@9216
    43
# Visual Studio's, "PlatformToolset"s.
dludwig@9216
    44
function Get-MSBuild-Env-Launcher
dludwig@9216
    45
{
dludwig@9216
    46
    param(
dludwig@9216
    47
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset
dludwig@9216
    48
    )
dludwig@9216
    49
dludwig@9216
    50
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012
dludwig@9216
    51
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
dludwig@9216
    52
    }
dludwig@9216
    53
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012
dludwig@9216
    54
        return "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\vcvarsphoneall.bat"
dludwig@9216
    55
    }
dludwig@9216
    56
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013
dludwig@9216
    57
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    58
    }
dludwig@9216
    59
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013
dludwig@9216
    60
        return "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
dludwig@9216
    61
    }
dludwig@9216
    62
    return ""
dludwig@9216
    63
}
dludwig@9216
    64
dludwig@9216
    65
# Gets a string that identifies the build-variant of SDL/WinRT that is specific
dludwig@9216
    66
# to a particular Visual Studio PlatformToolset.
dludwig@9216
    67
function Get-SDL-WinRT-Variant-Name
dludwig@9216
    68
{
dludwig@9216
    69
    param(
dludwig@9216
    70
        [Parameter(Mandatory=$true,Position=1)][string]$PlatformToolset,
dludwig@9216
    71
dludwig@9216
    72
        # If true, append a string to this function's output, identifying the
dludwig@9216
    73
        # build-variant's minimum-supported version of Visual Studio.
dludwig@9216
    74
        [switch]$IncludeVSSuffix = $false
dludwig@9216
    75
    )
dludwig@9216
    76
dludwig@9216
    77
    if ($PlatformToolset -eq "v110") {      # Windows 8.0 (not Windows Phone), via VS 2012 project files
dludwig@9216
    78
        if ($IncludeVSSuffix) {
dludwig@9216
    79
            return "WinRT80_VS2012"
dludwig@9216
    80
        } else {
dludwig@9216
    81
            return "WinRT80"
dludwig@9216
    82
        }
dludwig@9216
    83
    }
dludwig@9216
    84
    if ($PlatformToolset -eq "v110_wp80") { # Windows Phone 8.0, via VS 2012 project files
dludwig@9216
    85
        if ($IncludeVSSuffix) {
dludwig@9216
    86
            return "WinPhone80_VS2012"
dludwig@9216
    87
        } else {
dludwig@9216
    88
            return "WinPhone80"
dludwig@9216
    89
        }
dludwig@9216
    90
    }
dludwig@9216
    91
    if ($PlatformToolset -eq "v120") {      # Windows 8.1 (not Windows Phone), via VS 2013 project files
dludwig@9216
    92
        if ($IncludeVSSuffix) {
dludwig@9216
    93
            return "WinRT81_VS2013"
dludwig@9216
    94
        } else {
dludwig@9216
    95
            return "WinRT81"
dludwig@9216
    96
        }
dludwig@9216
    97
    }
dludwig@9216
    98
    if ($PlatformToolset -eq "v120_wp81") { # Windows Phone 8.1, via VS 2013 project files
dludwig@9216
    99
        if ($IncludeVSSuffix) {
dludwig@9216
   100
            return "WinPhone81_VS2013"
dludwig@9216
   101
        } else {
dludwig@9216
   102
            return "WinPhone81"
dludwig@9216
   103
        }
dludwig@9216
   104
    }
dludwig@9216
   105
    return ""
dludwig@9216
   106
}
dludwig@9216
   107
dludwig@9216
   108
# Returns the internal name of a Visual Studio Project.
dludwig@9216
   109
#
dludwig@9216
   110
# The internal name of a VS Project is encoded inside the project file
dludwig@9216
   111
# itself, inside a set of <ProjectName></ProjectName> XML tags.
dludwig@9216
   112
function Get-VS-ProjectName
dludwig@9216
   113
{
dludwig@9216
   114
    param(
dludwig@9216
   115
        [Parameter(Mandatory=$true,Position=1)]$VSProjectPath
dludwig@9216
   116
    )
dludwig@9216
   117
dludwig@9216
   118
    # For now, just do a regex for the project name:
dludwig@9216
   119
    $matches = (Get-Content $VSProjectPath | Select-String -Pattern ".*<ProjectName>([^<]+)<.*").Matches
dludwig@9216
   120
    foreach ($match in $matches) {
dludwig@9216
   121
        if ($match.Groups.Count -ge 1) {
dludwig@9216
   122
            return $match.Groups[1].Value
dludwig@9216
   123
        }
dludwig@9216
   124
    }
dludwig@9216
   125
    return $null
dludwig@9216
   126
}
dludwig@9216
   127
dludwig@9216
   128
# Build a specific variant of SDL/WinRT
dludwig@9216
   129
function Build-SDL-WinRT-Variant
dludwig@9216
   130
{
dludwig@9216
   131
    #
dludwig@9216
   132
    # Read in arguments:
dludwig@9216
   133
    #
dludwig@9216
   134
    param (
dludwig@9216
   135
        # name of an SDL project file, minus extensions and
dludwig@9216
   136
        # platform-identifying suffixes
dludwig@9216
   137
        [Parameter(Mandatory=$true,Position=1)][string]$SDLProjectName,
dludwig@9216
   138
dludwig@9216
   139
        [Parameter(Mandatory=$true,Position=2)][string]$PlatformToolset,
dludwig@9216
   140
dludwig@9216
   141
        [Parameter(Mandatory=$true,Position=3)][string]$Platform
dludwig@9216
   142
    )
dludwig@9216
   143
dludwig@9216
   144
    #
dludwig@9216
   145
    # Derive other properties from read-in arguments:
dludwig@9216
   146
    #
dludwig@9216
   147
dludwig@9216
   148
    # The .bat file to setup a platform-appropriate MSBuild environment:
dludwig@9216
   149
    $BatchFileForMSBuildEnv = Get-MSBuild-Env-Launcher $PlatformToolset
dludwig@9216
   150
dludwig@9216
   151
    # The full path to the VS Project that'll be built:
dludwig@9216
   152
    $VSProjectPath = "$PSScriptRoot\..\VisualC-WinRT\$(Get-SDL-WinRT-Variant-Name $PlatformToolset -IncludeVSSuffix)\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset).vcxproj"
dludwig@9216
   153
dludwig@9216
   154
    # The internal name of the VS Project, used in some post-build steps:
dludwig@9216
   155
    $VSProjectName = Get-VS-ProjectName $VSProjectPath
dludwig@9216
   156
dludwig@9216
   157
    # Where to place output binaries (.dll, .lib, and .pdb files):
dludwig@9216
   158
    $OutDir = "$PSScriptRoot\..\VisualC-WinRT\lib\$PlatformToolset\$Platform"
dludwig@9216
   159
dludwig@9216
   160
    # Where to place intermediate build files:
dludwig@9216
   161
    $IntermediateDir = "$PSScriptRoot\..\VisualC-WinRT\obj\$SDLProjectName-$(Get-SDL-WinRT-Variant-Name $PlatformToolset)\$Platform"
dludwig@9216
   162
dludwig@9216
   163
    #
dludwig@9216
   164
    # Build the VS Project:
dludwig@9216
   165
    #
dludwig@9216
   166
    cmd.exe /c " ""$BatchFileForMSBuildEnv"" x86 & msbuild ""$VSProjectPath"" /p:Platform=$Platform /p:OutDir=""$OutDir\\"" /p:IntDir=""$IntermediateDir\\""" | Out-Host
dludwig@9216
   167
    $BuildResult = $?
dludwig@9216
   168
dludwig@9216
   169
    #
dludwig@9216
   170
    # Move .dll files into place.  This fixes a problem whereby MSBuild may
dludwig@9216
   171
    # put output files into a sub-directory of $OutDir, rather than $OutDir
dludwig@9216
   172
    # itself.
dludwig@9216
   173
    #
dludwig@9216
   174
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   175
        Move-Item -Force "$OutDir\$VSProjectName\*" "$OutDir"
dludwig@9216
   176
    }
dludwig@9216
   177
dludwig@9216
   178
    #
dludwig@9216
   179
    # Clean up unneeded files in $OutDir:
dludwig@9216
   180
    #
dludwig@9216
   181
    if (Test-Path "$OutDir\$VSProjectName\") {
dludwig@9216
   182
        Remove-Item -Recurse "$OutDir\$VSProjectName"
dludwig@9216
   183
    }
dludwig@9216
   184
    Remove-Item "$OutDir\*.exp"
dludwig@9216
   185
    Remove-Item "$OutDir\*.ilk"
dludwig@9216
   186
    Remove-Item "$OutDir\*.pri"
dludwig@9216
   187
dludwig@9216
   188
    #
dludwig@9216
   189
    # All done.  Indicate success, or failure, to the caller:
dludwig@9216
   190
    #
dludwig@9216
   191
    #echo "RESULT: $BuildResult" | Out-Host
dludwig@9216
   192
    return $BuildResult
dludwig@9216
   193
}
dludwig@9216
   194
dludwig@9216
   195
dludwig@9216
   196
#
dludwig@9216
   197
# Build each variant, with corresponding .dll, .lib, and .pdb files:
dludwig@9216
   198
#
dludwig@9216
   199
$DidAnyFail = $false
dludwig@9216
   200
dludwig@9216
   201
# Build for Windows Phone 8.0, via VC++ 2012:
dludwig@9216
   202
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "ARM"))   { $DidAnyFail = $true }
dludwig@9216
   203
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110_wp80" "Win32")) { $DidAnyFail = $true }
dludwig@9216
   204
dludwig@9216
   205
# Build for Windows Phone 8.1, via VC++ 2013:
dludwig@9216
   206
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "ARM"))   { $DidAnyFail = $true }
dludwig@9216
   207
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120_wp81" "Win32")) { $DidAnyFail = $true }
dludwig@9216
   208
dludwig@9216
   209
# Build for Windows 8.0 and Windows RT 8.0, via VC++ 2012:
dludwig@9216
   210
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "ARM"))        { $DidAnyFail = $true }
dludwig@9216
   211
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "Win32"))      { $DidAnyFail = $true }
dludwig@9216
   212
if ( ! (Build-SDL-WinRT-Variant "SDL" "v110" "x64"))        { $DidAnyFail = $true }
dludwig@9216
   213
dludwig@9216
   214
# Build for Windows 8.1 and Windows RT 8.1, via VC++ 2013:
dludwig@9216
   215
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "ARM"))        { $DidAnyFail = $true }
dludwig@9216
   216
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "Win32"))      { $DidAnyFail = $true }
dludwig@9216
   217
if ( ! (Build-SDL-WinRT-Variant "SDL" "v120" "x64"))        { $DidAnyFail = $true }
dludwig@9216
   218
dludwig@9216
   219
# Let the script's caller know whether or not any errors occurred.
dludwig@9216
   220
# Exit codes compatible with Buildbot are used (1 for error, 0 for success).
dludwig@9216
   221
if ($DidAnyFail -eq $true) {
dludwig@9216
   222
    exit 1
dludwig@9216
   223
} else {
dludwig@9216
   224
    exit 0
dludwig@9216
   225
}