forked from xt-sys/exectos
configure.ps1: Fix path handling and improve reliability
- Use $PSScriptRoot for reliable source directory detection - Use Join-Path for proper path construction - Validate BUILD_TYPE against Debug/Release - Fix CMake argument quoting - Use Write-Error for error messages
This commit is contained in:
@@ -4,48 +4,41 @@
|
|||||||
# DESCRIPTION: Project configuration script for preparing the build environment
|
# DESCRIPTION: Project configuration script for preparing the build environment
|
||||||
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
# DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
|
||||||
|
|
||||||
# Check XTchain
|
# Check XTchain
|
||||||
if (-not $env:XTCVER) {
|
if (-not $env:XTCVER) {
|
||||||
Write-Host "XTChain not detected or corrupted!"
|
Write-Error "XTChain not detected or corrupted!"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set target architecture
|
# Set target architecture defaulting to amd64
|
||||||
if ($env:TARGET) {
|
$ARCH = if ($env:TARGET) { $env:TARGET } else { "amd64" }
|
||||||
$ARCH = $env:TARGET
|
|
||||||
} else {
|
|
||||||
$ARCH = "amd64"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set target build type
|
# Set target build type defaulting to Debug
|
||||||
if (-not $env:BUILD_TYPE) {
|
$env:BUILD_TYPE = if ($env:BUILD_TYPE -in @("Debug", "Release")) { $env:BUILD_TYPE } else { "Debug" }
|
||||||
$env:BUILD_TYPE = "DEBUG"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set variables
|
# Set variables
|
||||||
$EXECTOS_SOURCE_DIR = (Get-Location).Path
|
$EXECTOS_SOURCE_DIR = $PSScriptRoot
|
||||||
$EXECTOS_BINARY_DIR = "build-$($ARCH)-$($env:BUILD_TYPE.ToLower())"
|
$EXECTOS_BINARY_DIR = Join-Path $EXECTOS_SOURCE_DIR "build-$ARCH-$($env:BUILD_TYPE.ToLower())"
|
||||||
|
|
||||||
# Create directories if needed
|
# Create build directory
|
||||||
if ($EXECTOS_SOURCE_DIR -eq (Get-Location).Path) {
|
if (-not (Test-Path $EXECTOS_BINARY_DIR)) {
|
||||||
Write-Host "Creating directories in $EXECTOS_BINARY_DIR"
|
Write-Host "Creating build directory: $EXECTOS_BINARY_DIR"
|
||||||
New-Item -ItemType Directory -Path $EXECTOS_BINARY_DIR -Force | Out-Null
|
New-Item -ItemType Directory -Path $EXECTOS_BINARY_DIR -Force | Out-Null
|
||||||
Set-Location -Path $EXECTOS_BINARY_DIR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set-Location $EXECTOS_BINARY_DIR
|
||||||
|
|
||||||
# Delete old cache
|
# Delete old cache
|
||||||
Remove-Item -Path "CMakeCache.txt" -ErrorAction SilentlyContinue
|
Remove-Item "CMakeCache.txt", "host-tools/CMakeCache.txt" -ErrorAction SilentlyContinue
|
||||||
Remove-Item -Path "host-tools/CMakeCache.txt" -ErrorAction SilentlyContinue
|
|
||||||
|
|
||||||
# Configure project using CMake
|
# Configure project using CMake
|
||||||
& cmake -G Ninja -DARCH:STRING=$($ARCH) -DBUILD_TYPE:STRING=$($env:BUILD_TYPE) $EXECTOS_SOURCE_DIR
|
& cmake -G Ninja "-DARCH:STRING=$ARCH" "-DBUILD_TYPE:STRING=$($env:BUILD_TYPE)" $EXECTOS_SOURCE_DIR
|
||||||
|
|
||||||
# Check if configuration succeeded
|
# Check if configuration succeeded
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "Configure script failed."
|
Write-Error "Configure script failed."
|
||||||
exit 1
|
exit 1
|
||||||
} else {
|
|
||||||
"$($ARCH)" | Out-File -Encoding ASCII -NoNewline build.arch
|
|
||||||
Write-Host "Configure script completed. Enter '$EXECTOS_BINARY_DIR' directory and execute 'xbuild' to build ExectOS."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ARCH | Out-File -Encoding ASCII -NoNewline "build.arch"
|
||||||
|
Write-Host "Configure completed. Run 'xbuild' to build ExectOS."
|
Reference in New Issue
Block a user