1
+
#-----------------------------------------------------------------------------
2
+
#
3
+
# SRT - Secure, Reliable, Transport
4
+
# Copyright (c) 2021, Thierry Lelegard
5
+
#
6
+
# This Source Code Form is subject to the terms of the Mozilla Public
7
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8
+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
#
10
+
#-----------------------------------------------------------------------------
11
+
12
+
<#
13
+
.SYNOPSIS
14
+
15
+
Build the SRT static libraries installer for Windows.
16
+
17
+
.PARAMETER Version
18
+
19
+
Use the specified string as version number from libsrt. By default, if
20
+
the current commit has a tag, use that tag (initial 'v' removed). Otherwise,
21
+
the defaut version is a detailed version number (most recent version, number
22
+
of commits since then, short commit SHA).
23
+
24
+
.PARAMETER NoPause
25
+
26
+
Do not wait for the user to press <enter> at end of execution. By default,
27
+
execute a "pause" instruction at the end of execution, which is useful
28
+
when the script was run from Windows Explorer.
29
+
30
+
#>
31
+
[CmdletBinding()]
32
+
param(
33
+
[string]$Version = "",
34
+
[switch]$NoPause = $false
35
+
)
36
+
Write-Output "Building the SRT static libraries installer for Windows"
37
+
38
+
# Directory containing this script:
39
+
$ScriptDir = $PSScriptRoot
40
+
41
+
# The root of the srt repository is two levels up.
42
+
$RepoDir = (Split-Path -Parent (Split-Path -Parent $ScriptDir))
43
+
44
+
# Output directory for final installers:
45
+
$OutDir = "$ScriptDir\installers"
46
+
47
+
# Temporary directory for build operations:
48
+
$TmpDir = "$ScriptDir\tmp"
49
+
50
+
51
+
#-----------------------------------------------------------------------------
52
+
# A function to exit this script with optional error message, using -NoPause
53
+
#-----------------------------------------------------------------------------
54
+
55
+
function Exit-Script([string]$Message = "")
56
+
{
57
+
$Code = 0
58
+
if ($Message -ne "") {
59
+
Write-Output "ERROR: $Message"
60
+
$Code = 1
61
+
}
62
+
if (-not $NoPause) {
63
+
pause
64
+
}
65
+
exit $Code
66
+
}
67
+
68
+
69
+
#-----------------------------------------------------------------------------
70
+
# Build SRT version strings
71
+
#-----------------------------------------------------------------------------
72
+
73
+
# By default, let git format a decent version number.
74
+
if (-not $Version) {
75
+
$Version = (git describe --tags ) -replace '-g','-'
76
+
}
77
+
$Version = $Version -replace '^v',''
78
+
79
+
# Split version string in pieces and make sure to get at least four elements.
80
+
$VField = ($Version -split "[-\. ]") + @("0", "0", "0", "0") | Select-String -Pattern '^\d*$'
81
+
$VersionInfo = "$($VField[0]).$($VField[1]).$($VField[2]).$($VField[3])"
82
+
83
+
Write-Output "SRT version: $Version"
84
+
Write-Output "Windows version info: $VersionInfo"
85
+
86
+
87
+
#-----------------------------------------------------------------------------
88
+
# Initialization phase, verify prerequisites
89
+
#-----------------------------------------------------------------------------
90
+
91
+
# Locate OpenSSL root from local installation.
92
+
$SslRoot = @{
93
+
"x64" = "C:\Program Files\OpenSSL-Win64";
94
+
"Win32" = "C:\Program Files (x86)\OpenSSL-Win32"
95
+
}
96
+
97
+
# Verify OpenSSL directories.
98
+
$Missing = 0
99
+
foreach ($file in @($SslRoot["x64"], $SslRoot["Win32"])) {
100
+
if (-not (Test-Path $file)) {
101
+
Write-Output "**** Missing $file"
102
+
$Missing = $Missing + 1
103
+
}
104
+
}
105
+
if ($Missing -gt 0) {
106
+
Exit-Script "Missing $Missing OpenSSL files, use install-openssl.ps1 to install OpenSSL"
107
+
}
108
+
109
+
# Locate MSBuild and CMake, regardless of Visual Studio version.
110
+
Write-Output "Searching MSBuild ..."
111
+
$MSRoots = @("C:\Program Files*\MSBuild", "C:\Program Files*\Microsoft Visual Studio", "C:\Program Files*\CMake*")
112
+
$MSBuild = Get-ChildItem -Recurse -Path $MSRoots -Include MSBuild.exe -ErrorAction Ignore |
113
+
ForEach-Object { (Get-Command $_).FileVersionInfo } |
114
+
Sort-Object -Unique -Property FileVersion |
115
+
ForEach-Object { $_.FileName} |
116
+
Select-Object -Last 1
117
+
if (-not $MSBuild) {
118
+
Exit-Script "MSBuild not found"
119
+
}
120
+
121
+
Write-Output "Searching CMake ..."
122
+
$CMake = Get-ChildItem -Recurse -Path $MSRoots -Include cmake.exe -ErrorAction Ignore |
123
+
ForEach-Object { (Get-Command $_).FileVersionInfo } |
124
+
Sort-Object -Unique -Property FileVersion |
125
+
ForEach-Object { $_.FileName} |
126
+
Select-Object -Last 1
127
+
if (-not $CMake) {
128
+
Exit-Script "CMake not found, check option 'C++ CMake tools for Windows' in Visual Studio installer"
129
+
}
130
+
131
+
# Locate NSIS, the Nullsoft Scriptable Installation System.
132
+
Write-Output "Searching NSIS ..."
133
+
$NSIS = Get-Item "C:\Program Files*\NSIS\makensis.exe" | ForEach-Object { $_.FullName} | Select-Object -Last 1
134
+
if (-not $NSIS) {
135
+
Exit-Script "NSIS not found, use install-nsis.ps1 to install NSIS"
136
+
}
137
+
138
+
Write-Output "MSBuild: $MSBuild"
139
+
Write-Output "CMake: $CMake"
140
+
Write-Output "NSIS: $NSIS"
141
+
142
+
# Create the directories for builds when necessary.
143
+
[void](New-Item -Path $TmpDir -ItemType Directory -Force)
144
+
[void](New-Item -Path $OutDir -ItemType Directory -Force)
145
+
146
+
147
+
#-----------------------------------------------------------------------------
148
+
# Configure and build SRT library using CMake on two architectures.
149
+
#-----------------------------------------------------------------------------
150
+
151
+
foreach ($Platform in @("x64", "Win32")) {
152
+
153
+
# Build directory. Cleanup to force a fresh cmake config.
154
+
$BuildDir = "$TmpDir\build.$Platform"
155
+
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $BuildDir
156
+
[void](New-Item -Path $BuildDir -ItemType Directory -Force)
157
+
158
+
# Run CMake.
159
+
Write-Output "Configuring build for platform $Platform ..."
160
+
$SRoot = $SslRoot[$Platform]
161
+
& $CMake -S $RepoDir -B $BuildDir -A $Platform `
162
+
-DENABLE_STDCXX_SYNC=ON `
163
+
-DOPENSSL_ROOT_DIR="$SRoot" `
164
+
-DOPENSSL_LIBRARIES="$SRoot\lib\libssl_static.lib;$SRoot\lib\libcrypto_static.lib" `
165
+
-DOPENSSL_INCLUDE_DIR="$SRoot\include"
166
+
167
+
# Patch version string in version.h
168
+
Get-Content "$BuildDir\version.h" |
169
+
ForEach-Object {
170
+
$_ -replace "#define *SRT_VERSION_STRING .*","#define SRT_VERSION_STRING `"$Version`""
171
+
} |
172
+
Out-File "$BuildDir\version.new" -Encoding ascii
173
+
Move-Item "$BuildDir\version.new" "$BuildDir\version.h" -Force
174
+
175
+
# Compile SRT.
176
+
Write-Output "Building for platform $Platform ..."
177
+
foreach ($Conf in @("Release", "Debug")) {
178
+
& $MSBuild "$BuildDir\SRT.sln" /nologo /maxcpucount /property:Configuration=$Conf /property:Platform=$Platform /target:srt_static
179
+
}
180
+
}
181
+
182
+
# Verify the presence of compiled libraries.
183
+
Write-Output "Checking compiled libraries ..."
184
+
$Missing = 0
185
+
foreach ($Conf in @("Release", "Debug")) {
186
+
foreach ($Platform in @("x64", "Win32")) {
187
+
$Path = "$TmpDir\build.$Platform\$Conf\srt_static.lib"
188
+
if (-not (Test-Path $Path)) {
189
+
Write-Output "**** Missing $Path"
190
+
$Missing = $Missing + 1
191
+
}
192
+
}
193
+
}
194
+
if ($Missing -gt 0) {
195
+
Exit-Script "Missing $Missing files"
196
+
}
197
+
198
+
199
+
#-----------------------------------------------------------------------------
200
+
# Build the binary installer.
201
+
#-----------------------------------------------------------------------------
202
+
203
+
Write-Output "Building installer ..."
204
+
& $NSIS /V2 `
205
+
/DVersion="$Version" `
206
+
/DVersionInfo="$VersionInfo" `
207
+
/DOutDir="$OutDir" `
208
+
/DBuildRoot="$TmpDir" `
209
+
/DRepoDir="$RepoDir" `
210
+
"$ScriptDir\libsrt.nsi"
211
+
212
+
Exit-Script
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4