248 lines
8.3 KiB
PowerShell
248 lines
8.3 KiB
PowerShell
#
|
|
# MODULE: XTchain
|
|
# LICENSE: See the COPYING.md in the top level directory
|
|
# FILE: xtclib.psm1
|
|
# DESCRIPTION: XTchain PowerShell module
|
|
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
|
#
|
|
|
|
# Module variables
|
|
$script:XTCVersion = $env:XTCVER
|
|
$script:XTCDirectory = $env:XTCDIR
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Prints XTChain banner
|
|
.DESCRIPTION
|
|
Displays the XTChain version banner with formatting
|
|
#>
|
|
function Show-XTCBanner {
|
|
[CmdletBinding()]
|
|
param()
|
|
|
|
$XTC_BANNER = "XT Toolchain v$script:XTCVersion for Windows"
|
|
|
|
Write-Host "################################################################################"
|
|
Write-Host
|
|
Write-Host (' ' * [math]::Floor((80 - $XTC_BANNER.Length) / 2) + $XTC_BANNER) -ForegroundColor Yellow
|
|
Write-Host
|
|
Write-Host "################################################################################"
|
|
Write-Host
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Sets the target architecture
|
|
.DESCRIPTION
|
|
Configures the TARGET environment variable based on the specified architecture
|
|
.PARAMETER Architecture
|
|
The target architecture (aarch64, arm64, arm, armv7, i386, i486, i586, i686, x86, amd64, x64, x86_64)
|
|
#>
|
|
function Set-XTCArchitecture {
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Architecture
|
|
)
|
|
|
|
switch -Regex ($Architecture.ToLower()) {
|
|
"aarch64|arm64" {
|
|
$env:TARGET = "aarch64"
|
|
}
|
|
"arm|armv7" {
|
|
$env:TARGET = "armv7"
|
|
}
|
|
"i386|i486|i586|i686|x86" {
|
|
$env:TARGET = "i686"
|
|
}
|
|
"amd64|x64|x86_64" {
|
|
$env:TARGET = "amd64"
|
|
}
|
|
default {
|
|
$env:TARGET = "UNKNOWN"
|
|
Write-Warning "Unknown architecture '$Architecture'. Set to UNKNOWN."
|
|
}
|
|
}
|
|
Write-Host "Target Architecture: $($env:TARGET)"
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Sets the build type
|
|
.DESCRIPTION
|
|
Configures the BUILD_TYPE environment variable
|
|
.PARAMETER BuildType
|
|
The build type (DEBUG or RELEASE)
|
|
#>
|
|
function Set-XTCBuildType {
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateSet("DEBUG", "RELEASE")]
|
|
[string]$BuildType
|
|
)
|
|
|
|
$env:BUILD_TYPE = $BuildType.ToUpper()
|
|
Write-Host "Target build type: $($env:BUILD_TYPE)"
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Shows XTChain help information
|
|
.DESCRIPTION
|
|
Displays available XTChain commands and their usage
|
|
#>
|
|
function Show-XTCHelp {
|
|
[CmdletBinding()]
|
|
param()
|
|
|
|
Show-XTCBanner
|
|
Write-Host "XTChain PowerShell Module Commands:"
|
|
Write-Host " * Show-XTCBanner - prints XTChain banner"
|
|
Write-Host " * Set-XTCArchitecture - sets the target CPU architecture"
|
|
Write-Host " * Set-XTCBuildType - sets build type [DEBUG/RELEASE]"
|
|
Write-Host " * Show-XTCHelp - prints this message"
|
|
Write-Host " * Show-XTCVersion - prints XTChain and its components version"
|
|
Write-Host " * Invoke-XTCBuild - builds an application with Ninja build system"
|
|
Write-Host
|
|
Write-Host "Legacy command aliases:"
|
|
Write-Host " * banner, charch, chbuild, help, version, xbuild"
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Displays version information for XTChain components
|
|
.DESCRIPTION
|
|
Shows version information for all XTChain tools and components
|
|
#>
|
|
function Show-XTCVersion {
|
|
[CmdletBinding()]
|
|
param()
|
|
|
|
# Check for minimal XTChain version with external tools
|
|
$XTCHAIN_EXTTOOLS = $false
|
|
if ((Test-Path "$script:XTCDirectory/bin/clang") -and
|
|
((Get-Command clang -ErrorAction SilentlyContinue).Source -eq "$script:XTCDirectory/bin/clang") -and
|
|
($script:XTCVersion -match "min")) {
|
|
|
|
$XTCHAIN_EXTTOOLS = $true
|
|
$requiredTools = @("clang", "clang++", "cmake", "lld-link", "ninja")
|
|
|
|
foreach ($tool in $requiredTools) {
|
|
if (!(Get-Command $tool -ErrorAction SilentlyContinue)) {
|
|
Write-Error "You are using minimal version of XTChain and '$tool' has been not found in your system!"
|
|
Write-Error "Please install all required tools."
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
Show-XTCBanner
|
|
Write-Host
|
|
|
|
# Display tool versions
|
|
try {
|
|
$clangVersion = (clang --version | Select-String -Pattern "version (\d+\.\d+\.\d+)").Matches.Groups[1].Value
|
|
$clangPath = (Get-Command clang).Source
|
|
Write-Host "LLVM/Clang Compiler: $clangVersion ($clangPath)"
|
|
} catch { Write-Warning "Could not retrieve Clang version" }
|
|
|
|
try {
|
|
$lldVersion = (lld-link --version | Select-String -Pattern "(\d+\.\d+\.\d+)").Matches.Groups[1].Value
|
|
$lldPath = (Get-Command lld-link).Source
|
|
Write-Host "LLVM/LLD Linker: $lldVersion ($lldPath)"
|
|
} catch { Write-Warning "Could not retrieve LLD version" }
|
|
|
|
try {
|
|
$widlVersion = (widl -V | Select-String -Pattern "version (\d+\.\d+)").Matches.Groups[1].Value
|
|
$widlPath = (Get-Command widl).Source
|
|
Write-Host "Wine IDL Compiler: $widlVersion ($widlPath)"
|
|
} catch { Write-Warning "Could not retrieve WIDL version" }
|
|
|
|
try {
|
|
$wmcVersion = (wmc -V | Select-String -Pattern "version (\d+\.\d+)").Matches.Groups[1].Value
|
|
$wmcPath = (Get-Command wmc).Source
|
|
Write-Host "Wine Message Compiler: $wmcVersion ($wmcPath)"
|
|
} catch { Write-Warning "Could not retrieve WMC version" }
|
|
|
|
try {
|
|
$wrcVersion = (wrc --version | Select-String -Pattern "version (\d+\.\d+)").Matches.Groups[1].Value
|
|
$wrcPath = (Get-Command wrc).Source
|
|
Write-Host "Wine Resource Compiler: $wrcVersion ($wrcPath)"
|
|
} catch { Write-Warning "Could not retrieve WRC version" }
|
|
|
|
try {
|
|
$xtcspeccVersion = (xtcspecc --help | Select-String -Pattern "Version (\d+\.\d+)").Matches.Groups[1].Value
|
|
$xtcspeccPath = (Get-Command xtcspecc).Source
|
|
Write-Host "XT SPEC Compiler: $xtcspeccVersion ($xtcspeccPath)"
|
|
} catch { Write-Warning "Could not retrieve XTCSPECC version" }
|
|
|
|
try {
|
|
$cmakeVersion = (cmake --version | Select-String -Pattern "version (\d+\.\d+\.\d+)").Matches.Groups[1].Value
|
|
$cmakePath = (Get-Command cmake).Source
|
|
Write-Host "CMake Build System: $cmakeVersion ($cmakePath)"
|
|
} catch { Write-Warning "Could not retrieve CMake version" }
|
|
|
|
try {
|
|
$ninjaVersion = (ninja --version)
|
|
$ninjaPath = (Get-Command ninja).Source
|
|
Write-Host "Ninja Build System: $ninjaVersion ($ninjaPath)"
|
|
} catch { Write-Warning "Could not retrieve Ninja version" }
|
|
|
|
Write-Host
|
|
|
|
# Set default values and display current configuration
|
|
$BUILD_TYPE = if ([string]::IsNullOrEmpty($env:BUILD_TYPE)) { 'DEBUG' } else { $env:BUILD_TYPE }
|
|
$TARGET = if ([string]::IsNullOrEmpty($env:TARGET)) { 'amd64' } else { $env:TARGET }
|
|
|
|
Set-XTCArchitecture -Architecture $TARGET
|
|
Set-XTCBuildType -BuildType $BUILD_TYPE
|
|
|
|
Write-Host
|
|
Write-Host
|
|
Write-Host "For a list of all supported commands, type 'Show-XTCHelp' or 'help'"
|
|
Write-Host "--------------------------------------------------------"
|
|
Write-Host
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Builds application using Ninja build system
|
|
.DESCRIPTION
|
|
Wrapper around ninja command with architecture validation
|
|
.PARAMETER Arguments
|
|
Arguments to pass to ninja
|
|
#>
|
|
function Invoke-XTCBuild {
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(ValueFromRemainingArguments = $true)]
|
|
[string[]]$Arguments
|
|
)
|
|
|
|
if (Test-Path "build.arch") {
|
|
$buildArch = Get-Content "build.arch" -Raw
|
|
$buildArch = $buildArch.Trim()
|
|
|
|
if ($buildArch -ne $env:TARGET) {
|
|
Write-Host "Build is configured for '$buildArch' while current target set to '$($env:TARGET)'!" -ForegroundColor Red
|
|
Write-Host "Cannot continue until conflict is resolved..." -ForegroundColor Red
|
|
return 1
|
|
}
|
|
}
|
|
|
|
& ninja @Arguments
|
|
return $LASTEXITCODE
|
|
}
|
|
|
|
# Legacy function aliases for backwards compatibility
|
|
Set-Alias -Name banner -Value Show-XTCBanner
|
|
Set-Alias -Name charch -Value Set-XTCArchitecture
|
|
Set-Alias -Name chbuild -Value Set-XTCBuildType
|
|
Set-Alias -Name help -Value Show-XTCHelp
|
|
Set-Alias -Name version -Value Show-XTCVersion
|
|
Set-Alias -Name xbuild -Value Invoke-XTCBuild
|
|
|
|
# Export functions and aliases
|
|
Export-ModuleMember -Function Show-XTCBanner, Set-XTCArchitecture, Set-XTCBuildType, Show-XTCHelp, Show-XTCVersion, Invoke-XTCBuild
|
|
Export-ModuleMember -Alias banner, charch, chbuild, help, version, xbuild |