forked from xt-sys/xtchain
156 lines
4.6 KiB
PowerShell
156 lines
4.6 KiB
PowerShell
#
|
|
# PROJECT: XTchain
|
|
# LICENSE: See the COPYING.md in the top level directory
|
|
# FILE: scripts/xtchain.ps1
|
|
# DESCRIPTION: XTchain Entry Script
|
|
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
|
#
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Position = 0)]
|
|
[string]$TargetArchitecture = "amd64",
|
|
|
|
[Parameter(Position = 1)]
|
|
[string]$SourceDirectory = $PWD.Path
|
|
)
|
|
|
|
# Initialize XTchain environment
|
|
function Initialize-XTChain {
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Architecture,
|
|
[string]$SourcePath
|
|
)
|
|
|
|
# Get the absolute path to XTchain
|
|
$script:XTCDIR = (Get-Item -Path ".\").FullName
|
|
|
|
# Read XTchain version
|
|
$versionFile = Join-Path $script:XTCDIR "Version"
|
|
if (Test-Path $versionFile) {
|
|
$env:XTCVER = Get-Content $versionFile -Raw | ForEach-Object { $_.Trim() }
|
|
} else {
|
|
Write-Warning "Version file not found at $versionFile"
|
|
$env:XTCVER = "Unknown"
|
|
}
|
|
|
|
# Set XTchain directory environment variable
|
|
$env:XTCDIR = $script:XTCDIR
|
|
|
|
# Import XTchain module
|
|
$modulePath = Join-Path $script:XTCDIR "lib\xtchain\xtclib.psm1"
|
|
if (Test-Path $modulePath) {
|
|
Import-Module $modulePath -Force -Global
|
|
} else {
|
|
Write-Error "XTchain module not found at $modulePath"
|
|
return $false
|
|
}
|
|
|
|
# Set target architecture
|
|
$env:TARGET = $Architecture
|
|
|
|
# Validate source directory
|
|
if (-not (Test-Path $SourcePath)) {
|
|
Write-Error "Source directory does not exist: $SourcePath"
|
|
return $false
|
|
}
|
|
|
|
# Clean compiler environment variables
|
|
$env:HOST = $null
|
|
$env:CFLAGS = $null
|
|
$env:CXXFLAGS = $null
|
|
$env:LDFLAGS = $null
|
|
|
|
# Update PATH to include XTchain binaries
|
|
$xtcBinPath = Join-Path $script:XTCDIR "bin"
|
|
if (Test-Path $xtcBinPath) {
|
|
$env:PATH = "$xtcBinPath;" + $env:PATH
|
|
} else {
|
|
Write-Warning "XTchain bin directory not found at $xtcBinPath"
|
|
}
|
|
|
|
return $true
|
|
}
|
|
|
|
# Create fancy PowerLine-style prompt
|
|
function Set-XTChainPrompt {
|
|
[CmdletBinding()]
|
|
param()
|
|
|
|
function global:prompt {
|
|
try {
|
|
$promptText = " XT Toolchain "
|
|
$currentPath = (Get-Location).Path
|
|
$chevron = [char]0xE0B0
|
|
|
|
# Define prompt segments
|
|
$segments = @(
|
|
@{
|
|
Text = $promptText
|
|
BackgroundColor = "Blue"
|
|
ForegroundColor = "White"
|
|
},
|
|
@{
|
|
Text = " $currentPath "
|
|
BackgroundColor = "DarkCyan"
|
|
ForegroundColor = "White"
|
|
}
|
|
)
|
|
|
|
# Render segments
|
|
for ($index = 0; $index -lt $segments.Count; $index++) {
|
|
$segment = $segments[$index]
|
|
$nextBackground = if ($index + 1 -lt $segments.Count) {
|
|
$segments[$index + 1].BackgroundColor
|
|
} else {
|
|
"Default"
|
|
}
|
|
|
|
# Write segment text
|
|
Write-Host $segment.Text -NoNewLine -ForegroundColor $segment.ForegroundColor -BackgroundColor $segment.BackgroundColor
|
|
|
|
# Write separator
|
|
if ($nextBackground -ne "Default") {
|
|
Write-Host $chevron -NoNewLine -ForegroundColor $segment.BackgroundColor -BackgroundColor $nextBackground
|
|
} else {
|
|
Write-Host $chevron -NoNewLine -ForegroundColor $segment.BackgroundColor
|
|
}
|
|
}
|
|
|
|
return " "
|
|
}
|
|
catch {
|
|
# Fallback to simple prompt if PowerLine fails
|
|
return "XTC> "
|
|
}
|
|
}
|
|
}
|
|
|
|
# Main execution
|
|
try {
|
|
Write-Host "Initializing XTchain environment..." -ForegroundColor Green
|
|
|
|
if (-not (Initialize-XTChain -Architecture $TargetArchitecture -SourcePath $SourceDirectory)) {
|
|
Write-Error "Failed to initialize XTchain environment"
|
|
exit 1
|
|
}
|
|
|
|
# Display version information
|
|
Show-XTCVersion
|
|
|
|
# Set up the fancy prompt
|
|
Set-XTChainPrompt
|
|
|
|
# Change to source directory
|
|
Set-Location -Path $SourceDirectory
|
|
|
|
Write-Host "XTchain environment ready!" -ForegroundColor Green
|
|
Write-Host "Current directory: $(Get-Location)" -ForegroundColor Cyan
|
|
Write-Host "Target architecture: $env:TARGET" -ForegroundColor Cyan
|
|
Write-Host "Type 'Show-XTCHelp' or 'help' for available commands" -ForegroundColor Yellow
|
|
}
|
|
catch {
|
|
Write-Error "Failed to initialize XTchain: $_"
|
|
exit 1
|
|
} |