axmol/setup.ps1

178 lines
6.3 KiB
PowerShell
Raw Normal View History

2023-07-06 12:18:33 +08:00
$myRoot = $PSScriptRoot
$AX_ROOT = $myRoot
2023-08-30 15:13:35 +08:00
function mkdirs([string]$path) {
if (!(Test-Path $path -PathType Container)) {
New-Item $path -ItemType Directory 1>$null
}
}
2023-07-06 20:24:41 +08:00
$build1kPath = Join-Path $myRoot '1k/build1k.ps1'
2023-07-06 12:18:33 +08:00
$prefix = Join-Path $myRoot 'tools/external'
if (!(Test-Path $prefix -PathType Container)) {
2023-08-30 15:13:35 +08:00
mkdirs $prefix
2023-07-06 12:18:33 +08:00
}
# setup toolchains: glslcc, cmake, ninja, ndk, jdk, ...
2023-08-30 08:34:33 +08:00
. $build1kPath -setupOnly -prefix $prefix
2023-07-06 12:18:33 +08:00
2023-08-30 08:34:33 +08:00
$AX_CONSOLE_ROOT = Join-Path $AX_ROOT 'tools/console'
2023-07-06 12:18:33 +08:00
# 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) {
[Environment]::SetEnvironmentVariable('AX_ROOT', $AX_ROOT, 'User')
}
$pathList = [System.Collections.ArrayList]$env:PATH.Split(';')
2023-08-30 08:34:33 +08:00
if ($pathList.IndexOf($AX_CONSOLE_ROOT) -eq -1) {
$pathList = [System.Collections.ArrayList][Environment]::GetEnvironmentVariable('PATH', 'User').Split(';')
2023-08-30 08:34:33 +08:00
$pathList.Insert(0, $AX_CONSOLE_ROOT)
2023-07-06 12:18:33 +08:00
$PATH = $pathList -join ';'
[Environment]::SetEnvironmentVariable('PATH', $PATH, 'User')
}
}
else {
2023-08-30 08:34:33 +08:00
# update pwsh profile
2023-07-06 12:18:33 +08:00
if (Test-Path $PROFILE -PathType Leaf) {
2023-07-08 12:37:02 +08:00
$profileContent = Get-Content $PROFILE -raw
2023-07-06 12:18:33 +08:00
}
else {
$profileContent = ''
}
2023-08-30 08:34:33 +08:00
$profileMods = 0
$matchRet = [Regex]::Match($profileContent,"env\:AX_ROOT\s+\=\s+.*")
if (!$matchRet.Success) {
$profileContent += "# Add environment variable AX_ROOT for axmol`n"
2023-07-06 12:18:33 +08:00
$profileContent += '$env:AX_ROOT = "{0}"{1}' -f $AX_ROOT, "`n"
2023-08-30 08:34:33 +08:00
++$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
2023-07-06 12:18:33 +08:00
}
2023-08-30 08:34:33 +08:00
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"
2023-08-30 12:40:27 +08:00
$profileContent += '$env:PATH = "${env:AX_ROOT}/tools/console:${env:PATH}"'
$profileContent += "`n"
2023-08-30 08:34:33 +08:00
++$profileMods
2023-07-06 12:18:33 +08:00
}
$profileDir = Split-Path $PROFILE -Parent
if (!(Test-Path $profileDir -PathType Container)) {
2023-08-30 15:13:35 +08:00
mkdirs $profileDir
2023-07-06 12:18:33 +08:00
}
2023-08-30 08:34:33 +08:00
if ($profileMods) {
2023-07-08 12:37:02 +08:00
Set-Content $PROFILE -Value $profileContent
}
2023-08-30 08:34:33 +08:00
# 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
}
2023-07-06 12:18:33 +08:00
}
2023-08-30 08:34:33 +08:00
2023-07-06 12:18:33 +08:00
if ($IsLinux) {
2023-08-30 15:13:35 +08:00
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)) {
2023-08-30 15:35:29 +08:00
$b1k.println("It will take few minutes")
2023-08-30 08:34:33 +08:00
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'
2023-09-01 10:31:34 +08:00
$DEPENDS += 'libbsd-dev'
2023-08-30 08:34:33 +08:00
$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
2023-08-30 15:13:35 +08:00
} elseif($(Get-Command 'pacman' -ErrorAction SilentlyContinue)) {
$DEPENDS = @(
'git',
'cmake',
'make',
'libx11',
'libxrandr',
'libxinerama',
'libxcursor',
'libxi',
'fontconfig',
'gtk3',
'vlc'
2023-08-30 15:13:35 +08:00
)
2023-08-30 15:35:29 +08:00
sudo pacman -S --needed --noconfirm @DEPENDS
2023-08-30 15:13:35 +08:00
}
else {
2023-08-30 21:02:51 +08:00
$b1k.println("Warning: current Linux distro isn't officially supported by axmol community")
2023-08-30 08:34:33 +08:00
}
2023-08-30 21:02:51 +08:00
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 -
2023-07-06 12:18:33 +08:00
}
}
2023-08-30 12:40:27 +08:00
$b1k.pause("setup successfully, please restart the terminal to make added system variables take effect")