-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
226 lines (172 loc) · 9.09 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# This script will download and build Rasterbar-libtorrent in both debug and
# release configurations.
$PACKAGES_DIRECTORY = Join-Path $PSScriptRoot "packages"
$OUTPUT_DIRECTORY = Join-Path $PSScriptRoot "bin"
$VERSION = "0.0.0"
$OPENSSL_PACKAGE_DIRECTORY = Join-Path $PACKAGES_DIRECTORY "hadouken.openssl.0.1.3"
if (Test-Path Env:\APPVEYOR_BUILD_VERSION) {
$VERSION = $env:APPVEYOR_BUILD_VERSION
}
# 7zip configuration section
$7ZIP_VERSION = "9.20"
$7ZIP_DIRECTORY = Join-Path $PACKAGES_DIRECTORY "7zip-$7ZIP_VERSION"
$7ZIP_TOOL = Join-Path $7ZIP_DIRECTORY "7za.exe"
$7ZIP_PACKAGE_FILE = "7za$($7ZIP_VERSION.replace('.', '')).zip"
$7ZIP_DOWNLOAD_URL = "http://downloads.sourceforge.net/project/sevenzip/7-Zip/$7ZIP_VERSION/$7ZIP_PACKAGE_FILE"
# Boost configuration section
$BOOST_VERSION = "1.57.0"
$BOOST_DIRECTORY = Join-Path $PACKAGES_DIRECTORY "boost_$($BOOST_VERSION.replace('.', '_'))"
$BOOST_PACKAGE_FILE = "boost_$($BOOST_VERSION.replace('.', '_')).7z"
$BOOST_DOWNLOAD_URL = "http://downloads.sourceforge.net/project/boost/boost/$BOOST_VERSION/$BOOST_PACKAGE_FILE"
# Libtorrent configuration section
$LIBTORRENT_VERSION = "1.0.4"
$LIBTORRENT_DIRECTORY = Join-Path $PACKAGES_DIRECTORY "libtorrent-rasterbar-$LIBTORRENT_VERSION"
$LIBTORRENT_PACKAGE_FILE = "libtorrent-rasterbar-$LIBTORRENT_VERSION.tar.gz"
$LIBTORRENT_DOWNLOAD_URL = "http://downloads.sourceforge.net/project/libtorrent/libtorrent/$LIBTORRENT_PACKAGE_FILE"
# Nuget configuration section
$NUGET_FILE = "nuget.exe"
$NUGET_TOOL = Join-Path $PACKAGES_DIRECTORY $NUGET_FILE
$NUGET_DOWNLOAD_URL = "https://nuget.org/$NUGET_FILE"
function Download-File {
param (
[string]$url,
[string]$target
)
$webClient = new-object System.Net.WebClient
$webClient.DownloadFile($url, $target)
}
function Extract-File {
param (
[string]$file,
[string]$target
)
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($file, $target)
}
# Create packages directory if it does not exist
if (!(Test-Path $PACKAGES_DIRECTORY)) {
New-Item -ItemType Directory -Path $PACKAGES_DIRECTORY | Out-Null
}
# Download 7zip
if (!(Test-Path (Join-Path $PACKAGES_DIRECTORY $7ZIP_PACKAGE_FILE))) {
Write-Host "Downloading $7ZIP_PACKAGE_FILE"
Download-File $7ZIP_DOWNLOAD_URL (Join-Path $PACKAGES_DIRECTORY $7ZIP_PACKAGE_FILE)
}
# Download Boost
if (!(Test-Path (Join-Path $PACKAGES_DIRECTORY $BOOST_PACKAGE_FILE))) {
Write-Host "Downloading $BOOST_PACKAGE_FILE"
Download-File $BOOST_DOWNLOAD_URL (Join-Path $PACKAGES_DIRECTORY $BOOST_PACKAGE_FILE)
}
# Download Libtorrent
if (!(Test-Path (Join-Path $PACKAGES_DIRECTORY $LIBTORRENT_PACKAGE_FILE))) {
Write-Host "Downloading $LIBTORRENT_PACKAGE_FILE"
Download-File $LIBTORRENT_DOWNLOAD_URL (Join-Path $PACKAGES_DIRECTORY $LIBTORRENT_PACKAGE_FILE)
}
# Download Nuget
if (!(Test-Path $NUGET_TOOL)) {
Write-Host "Downloading $NUGET_FILE"
Download-File $NUGET_DOWNLOAD_URL $NUGET_TOOL
}
# Unpack 7zip
if (!(Test-Path $7ZIP_DIRECTORY)) {
Write-Host "Unpacking $7ZIP_PACKAGE_FILE"
Extract-File (Join-Path $PACKAGES_DIRECTORY $7ZIP_PACKAGE_FILE) $7ZIP_DIRECTORY
}
# Unpack Boost (may take a while)
if (!(Test-Path $BOOST_DIRECTORY)) {
Write-Host "Unpacking $BOOST_PACKAGE_FILE (this may take a while)"
$pkg = Join-Path $PACKAGES_DIRECTORY $BOOST_PACKAGE_FILE
& "$7ZIP_TOOL" x $pkg -o"$PACKAGES_DIRECTORY"
}
# Unpack Libtorrent
if (!(Test-Path $LIBTORRENT_DIRECTORY)) {
Write-Host "Unpacking $LIBTORRENT_PACKAGE_FILE"
$tmp = Join-Path $PACKAGES_DIRECTORY $LIBTORRENT_PACKAGE_FILE
& "$7ZIP_TOOL" x $tmp -o"$PACKAGES_DIRECTORY"
& "$7ZIP_TOOL" x $tmp.replace('.gz', '') -o"$PACKAGES_DIRECTORY"
}
# Install support package OpenSSL
& "$NUGET_TOOL" install hadouken.openssl -Version 0.1.3 -OutputDirectory "$PACKAGES_DIRECTORY"
function Build-Boost {
Push-Location $BOOST_DIRECTORY
# Bootstrap Boost only if we do not have b2 already
if (!(Test-Path b2.exe)) {
cmd /c bootstrap.bat
}
Start-Process ".\b2.exe" -ArgumentList "toolset=msvc-12.0 link=shared runtime-link=shared --with-chrono --with-thread" -Wait -NoNewWindow
Pop-Location
}
Build-Boost
function Compile-Libtorrent {
param (
[string]$platform,
[string]$configuration
)
Push-Location $LIBTORRENT_DIRECTORY
$b2 = Join-Path $BOOST_DIRECTORY "b2.exe"
$openssl_include = Join-Path $OPENSSL_PACKAGE_DIRECTORY "$platform/$configuration/include"
$openssl_lib = Join-Path $OPENSSL_PACKAGE_DIRECTORY "$platform/$configuration/lib"
Start-Process "$b2" -ArgumentList "-sBOOST_ROOT=""$BOOST_DIRECTORY"" toolset=msvc-12.0 include=""$openssl_include"" library-path=""$openssl_lib"" variant=$configuration boost=source boost-link=shared dht=on i2p=on encryption=openssl link=shared runtime-link=shared deprecated-functions=off debug-symbols=on" -Wait -NoNewWindow
Pop-Location
}
function Output-Libtorrent {
param (
[string]$platform,
[string]$configuration
)
pushd $LIBTORRENT_DIRECTORY
$t = Join-Path $OUTPUT_DIRECTORY "$platform\$configuration"
$out = "bin\msvc-12.0\$configuration\boost-link-shared\boost-source\deprecated-functions-off\encryption-openssl\threading-multi"
if ($configuration -eq "release")
{
$out = "bin\msvc-12.0\$configuration\boost-link-shared\boost-source\debug-symbols-on\deprecated-functions-off\encryption-openssl\threading-multi"
}
# Copy output files
xcopy /y "$out\*.lib" "$OUTPUT_DIRECTORY\$platform\lib\$configuration\*"
xcopy /y "$out\*.dll" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "$out\*.pdb" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
popd
}
function Output-Boost {
param (
[string]$platform,
[string]$configuration
)
Push-Location $BOOST_DIRECTORY
# Copy chrono
xcopy /y "bin.v2\libs\chrono\build\msvc-12.0\$configuration\threading-multi\*.dll" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\chrono\build\msvc-12.0\$configuration\threading-multi\*.pdb" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\chrono\build\msvc-12.0\$configuration\threading-multi\*.lib" "$OUTPUT_DIRECTORY\$platform\lib\$configuration\*"
# Copy thread
xcopy /y "bin.v2\libs\thread\build\msvc-12.0\$configuration\threading-multi\*.dll" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\thread\build\msvc-12.0\$configuration\threading-multi\*.pdb" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\thread\build\msvc-12.0\$configuration\threading-multi\*.lib" "$OUTPUT_DIRECTORY\$platform\lib\$configuration\*"
$extra = ""
if ($configuration -eq "release")
{
$extra = "debug-symbols-on\"
}
# Copy date_time
xcopy /y "bin.v2\libs\date_time\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.dll" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\date_time\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.pdb" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\date_time\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.lib" "$OUTPUT_DIRECTORY\$platform\lib\$configuration\*"
# Copy system
xcopy /y "bin.v2\libs\system\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.dll" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\system\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.pdb" "$OUTPUT_DIRECTORY\$platform\bin\$configuration\*"
xcopy /y "bin.v2\libs\system\build\msvc-12.0\$configuration\boost-link-shared\boost-source\$($extra)deprecated-functions-off\encryption-openssl\threading-multi\*.lib" "$OUTPUT_DIRECTORY\$platform\lib\$configuration\*"
Pop-Location
}
Compile-Libtorrent "win32" "debug"
Output-Libtorrent "win32" "debug"
Compile-Libtorrent "win32" "release"
Output-Libtorrent "win32" "release"
Output-Boost "win32" "debug"
Output-Boost "win32" "release"
# Output headers
xcopy /y "$(Join-Path $LIBTORRENT_DIRECTORY include)\*" "$(Join-Path $OUTPUT_DIRECTORY win32\include)\*" /E
xcopy /y "$(Join-Path $BOOST_DIRECTORY boost)\*" "$(Join-Path $OUTPUT_DIRECTORY win32\include)\boost\*" /E
# Package with NuGet
copy hadouken.libtorrent.nuspec $OUTPUT_DIRECTORY
pushd $OUTPUT_DIRECTORY
Start-Process "$NUGET_TOOL" -ArgumentList "pack hadouken.libtorrent.nuspec -Properties version=$VERSION" -Wait -NoNewWindow
popd