forked from axmolengine/axmol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ps1
295 lines (255 loc) · 10.3 KB
/
setup.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# the setup script of axmol, for powershell <= 5.1,
# please execute command 'Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force' in PowerShell Terminal
$myRoot = $PSScriptRoot
$AX_ROOT = $myRoot
$pwsh_ver = $PSVersionTable.PSVersion.ToString()
function mkdirs([string]$path) {
if (!(Test-Path $path -PathType Container)) {
if ([System.Version]$pwsh_ver -ge [System.Version]'5.0.0.0') {
New-Item $path -ItemType Directory 1>$null
}
else {
mkdir $path
}
}
}
if ([System.Version]$pwsh_ver -lt [System.Version]'5.0.0.0') {
# try setup WMF5.1, require reboot, try run setup.ps1 several times
Write-Host "Installing WMF5.1 ..."
$osVer = [System.Environment]::OSVersion.Version
if ($osVer.Major -ne 6) {
throw "Unsupported OSVersion: $($osVer.ToString())"
}
if ($osVer.Minor -ne 1 -and $osVer -ne 3) {
throw "Only win7 SP1 or win8 supported"
}
$is_win7 = $osVer.Minor -eq 1
# [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 5.1 non-win10
$prefix = Join-Path (Get-Location).Path 'tmp'
mkdirs $prefix
$curl = (New-Object Net.WebClient)
# .net 4.5.2 prereq by WMF5.1
$pkg_out = Join-Path $prefix 'NDP452-KB2901907-x86-x64-AllOS-ENU.exe'
if (!(Test-Path $pkg_out -PathType Leaf)) {
Write-Host "Downloading $pkg_out ..."
$curl.DownloadFile('https://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe', $pkg_out)
if (!$?) {
del $pkg_out
}
}
.\tmp\NDP452-KB2901907-x86-x64-AllOS-ENU.exe /q /norestart
# WMF5.1: https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/setup/install-configure?view=powershell-7.3&source=recommendations#download-and-install-the-wmf-51-package
if ($is_win7) {
$wmf_pkg = 'Win7AndW2K8R2-KB3191566-x64.zip'
}
else {
$wmf_pkg = 'Win8.1AndW2K12R2-KB3191564-x64.msu'
}
$pkg_out = Join-Path $prefix "$wmf_pkg"
if (!(Test-Path $pkg_out -PathType Leaf)) {
Write-Host "Downloading $pkg_out ..."
$curl.DownloadFile("https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/$wmf_pkg", $pkg_out)
if (!$?) {
del $pkg_out
}
}
if ($is_win7) {
echo "Expanding $pkg_out to $prefix"
function Expand-Zip($Path, $DestinationPath) {
mkdirs $DestinationPath
$shell = new-object -com shell.application
$zip = $shell.NameSpace($Path)
foreach ($item in $zip.items()) {
$shell.Namespace($DestinationPath).copyhere($item)
}
}
Expand-Zip -Path $pkg_out -DestinationPath $prefix\WMF51
& "$prefix\WMF51\Install-WMF5.1.ps1"
}
else {
wusa.exe $pkg_out /quiet /norestart
}
throw "PowerShell 5.0+ required, installed is: $pwsh_ver, after install WMF5.1 and restart computer, try again"
}
$build1kPath = Join-Path $myRoot '1k/build1k.ps1'
$prefix = Join-Path $myRoot 'tools/external'
if (!(Test-Path $prefix -PathType Container)) {
mkdirs $prefix
}
# setup toolchains: glslcc, cmake, ninja, ndk, jdk, ...
. $build1kPath -setupOnly -prefix $prefix @args
$AX_CONSOLE_ROOT = Join-Path $AX_ROOT 'tools/console'
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables
$IsWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')
if ($IsWin) {
if ("$env:AX_ROOT" -ne "$AX_ROOT") {
$env:AX_ROOT = $AX_ROOT
[Environment]::SetEnvironmentVariable('AX_ROOT', $AX_ROOT, 'User')
}
# checking evaluated env:PATH with system + user
$isMeInPath = $env:PATH.IndexOf($AX_CONSOLE_ROOT) -ne -1
$oldCmdRoot = $null
$cmdInfo = Get-Command 'axmol' -ErrorAction SilentlyContinue
if ($cmdInfo) {
$cmdRootTmp = Split-Path $cmdInfo.Source -Parent
if ($cmdRootTmp -ne $AX_CONSOLE_ROOT) {
$oldCmdRoot = $cmdRootTmp
}
}
function RefreshPath ($strPathList) {
if ($strPathList) {
$pathList = [System.Collections.ArrayList]($strPathList.Split(';'))
}
else {
$pathList = New-Object System.Collections.ArrayList
}
if ($Global:oldCmdRoot) {
$pathList.Remove($Global:oldCmdRoot)
}
if ($Global:isMeInPath) {
if ($pathList[0] -ne $Global:AX_CONSOLE_ROOT) {
$pathList.Remove($Global:AX_CONSOLE_ROOT)
$pathList.Insert(0, $Global:AX_CONSOLE_ROOT)
}
}
else {
$pathList.Insert(0, $Global:AX_CONSOLE_ROOT)
}
return $pathList -join ';'
}
if (!$isMeInPath -or $oldCmdRoot) {
# Add console bin to User PATH
$strPathList = RefreshPath ([Environment]::GetEnvironmentVariable('PATH', 'User')) # we need get real pathList from CurrentUser
[Environment]::SetEnvironmentVariable('PATH', $strPathList, 'User')
# Re-eval env:PATH to system + users
$env:PATH = RefreshPath $env:PATH # sync to PowerShell Terminal
}
}
else {
# update pwsh profile
if (Test-Path $PROFILE -PathType Leaf) {
$profileContent = Get-Content $PROFILE -raw
}
else {
$profileContent = ''
}
$profileMods = 0
$matchRet = [Regex]::Match($profileContent, "env\:AX_ROOT\s+\=\s+.*")
if (!$matchRet.Success) {
$profileContent += "# Add environment variable AX_ROOT for axmol`n"
$profileContent += '$env:AX_ROOT = "{0}"{1}' -f $AX_ROOT, "`n"
++$profileMods
}
elseif ($env:AX_ROOT -ne $AX_ROOT) {
# contains AX_ROOT statement, but not equal us
Write-Host "Updating env AX_ROOT from ${env:AX_ROOT} to $AX_ROOT"
$profileContent = [Regex]::Replace($profileContent, "env\:AX_ROOT\s+\=\s+.*", "env:AX_ROOT = '$AX_ROOT'")
++$profileMods
}
if ($profileContent.IndexOf('$env:PATH = ') -eq -1 -or !($axmolCmdInfo = (Get-Command axmol -ErrorAction SilentlyContinue)) -or $axmolCmdInfo.Source -ne "$AX_CONSOLE_ROOT/axmol") {
$profileContent += "# Add axmol console tool to PATH`n"
$profileContent += '$env:PATH = "${env:AX_ROOT}/tools/console:${env:PATH}"'
$profileContent += "`n"
++$profileMods
}
$profileDir = Split-Path $PROFILE -Parent
if (!(Test-Path $profileDir -PathType Container)) {
mkdirs $profileDir
}
if ($profileMods) {
Set-Content $PROFILE -Value $profileContent
}
# update ~/.bashrc, ~/.zshrc
function updateUnixProfile($profileFile) {
$profileMods = 0
$profileContent = Get-Content $profileFile -raw
$matchRet = [Regex]::Match($profileContent, "export AX_ROOT\=.*")
if (!$matchRet.Success) {
$profileContent += "# Add environment variable AX_ROOT for axmol`n"
$profileContent += 'export AX_ROOT="{0}"{1}' -f $AX_ROOT, "`n"
++$profileMods
}
else {
$stmtLine = 'export AX_ROOT="{0}"' -f $AX_ROOT
if ($matchRet.Value -ne $stmtLine) {
$profileContent = [Regex]::Replace($profileContent, "export AX_ROOT\=.*", $stmtLine)
}
}
if ($profileContent.IndexOf('export PATH=$AX_ROOT/tools/console:')) {
$profileContent += "# Add axmol console tool to PATH`n"
$profileContent += 'export PATH=$AX_ROOT/tools/console:$PATH' -f "`n"
++$profileMods
}
if ($profileMods) {
Set-Content $profileFile -Value $profileContent
}
}
if (Test-Path ~/.bashrc -PathType Leaf) {
updateUnixProfile ~/.bashrc
}
if (Test-Path ~/.zshrc -PathType Leaf) {
updateUnixProfile ~/.zshrc
}
# update macos launchctl
if ($IsMacOS) {
# for GUI app, android studio can find AX_ROOT
launchctl setenv AX_ROOT $env:AX_ROOT
}
}
if ($IsLinux) {
Write-Host "Are you continue install linux dependencies for axmol? (y/n) " -NoNewline
$answer = Read-Host
if ($answer -like 'y*') {
if ($(Get-Command 'dpkg' -ErrorAction SilentlyContinue)) {
$b1k.println("It will take few minutes")
sudo apt update
# for vm, libxxf86vm-dev also required
$DEPENDS = @()
$DEPENDS += 'libx11-dev'
$DEPENDS += 'automake'
$DEPENDS += 'libtool'
$DEPENDS += 'cmake'
$DEPENDS += 'libxmu-dev'
$DEPENDS += 'libglu1-mesa-dev'
$DEPENDS += 'libgl2ps-dev'
$DEPENDS += 'libxi-dev'
$DEPENDS += 'libzip-dev'
$DEPENDS += 'libpng-dev'
$DEPENDS += 'libfontconfig1-dev'
$DEPENDS += 'libgtk-3-dev'
$DEPENDS += 'binutils'
# $DEPENDS += 'libbsd-dev'
$DEPENDS += 'libasound2-dev'
$DEPENDS += 'libxxf86vm-dev'
$DEPENDS += 'libvlc-dev', 'libvlccore-dev', 'vlc'
# if vlc encouter codec error, install
# sudo apt install ubuntu-restricted-extras
sudo apt install --allow-unauthenticated --yes $DEPENDS > /dev/null
}
elseif ($(Get-Command 'pacman' -ErrorAction SilentlyContinue)) {
$DEPENDS = @(
'git',
'cmake',
'make',
'libx11',
'libxrandr',
'libxinerama',
'libxcursor',
'libxi',
'fontconfig',
'gtk3',
'vlc'
)
sudo pacman -S --needed --noconfirm @DEPENDS
}
else {
$b1k.println("Warning: current Linux distro isn't officially supported by axmol community")
}
b1k_print "Installing axmol freetype into linux system directory ..."
Set-Location "$AX_ROOT/thirdparty/freetype"
cmake -B build '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_INSTALL_PREFIX=/usr' '-DDISABLE_FORCE_DEBUG_POSTFIX=ON' '-DFT_DISABLE_HARFBUZZ=ON' '-DFT_DISABLE_BROTLI=ON' '-DFT_DISABLE_BZIP2=ON' '-DBUILD_SHARED_LIBS=ON'
sudo cmake --build build --config Release --target install
Set-Location -
}
}
$b1k.pause("setup successfully, please restart the terminal to make added system variables take effect")