aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/vendors/shared.psm1
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@tu-dresden.de>2016-06-22 19:18:55 +0200
committerPatrick Lehmann <Patrick.Lehmann@tu-dresden.de>2016-06-22 19:18:55 +0200
commite4e537afc5ba96e8732e86a213d566922f8c553a (patch)
treeb164cb0b7ed287499dbdd8cb1c5466f0da10089e /libraries/vendors/shared.psm1
parent0c1c22053f3372a7d0b185c7c44f83799f0b08e5 (diff)
downloadghdl-e4e537afc5ba96e8732e86a213d566922f8c553a.tar.gz
ghdl-e4e537afc5ba96e8732e86a213d566922f8c553a.tar.bz2
ghdl-e4e537afc5ba96e8732e86a213d566922f8c553a.zip
Reworked vendor library compile scripts for Windows.
Diffstat (limited to 'libraries/vendors/shared.psm1')
-rw-r--r--libraries/vendors/shared.psm1322
1 files changed, 322 insertions, 0 deletions
diff --git a/libraries/vendors/shared.psm1 b/libraries/vendors/shared.psm1
index 9685f1f00..97a196fd3 100644
--- a/libraries/vendors/shared.psm1
+++ b/libraries/vendors/shared.psm1
@@ -31,6 +31,315 @@
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# ==============================================================================
+
+[CmdletBinding()]
+param(
+ [Parameter(Mandatory=$true)][string]$VendorToolName,
+ [Parameter(Mandatory=$true)][string]$WorkingDir
+)
+
+$Module_VendorToolName = $VendorToolName
+$Module_WorkingDir = $WorkingDir
+
+function Exit-CompileScript
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER ExitCode
+ ExitCode of this script run
+ #>
+ [CmdletBinding()]
+ param(
+ [int]$ExitCode = 0
+ )
+
+ cd $Module_WorkingDir
+
+ # unload modules
+ Remove-Module config
+ Remove-Module shared
+
+ if ($ExitCode -eq 0)
+ { exit 0 }
+ else
+ { Write-Host "[DEBUG]: HARD EXIT" -ForegroundColor Cyan
+ exit $ExitCode
+ }
+}
+
+function Get-SourceDirectory
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER Source
+ Undocumented
+ .PARAMETER EnvSource
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [string]$Source,
+ [string]$EnvSource
+ )
+
+ if ($Source -ne "")
+ { $SourceDirectory = $Source } # TODO: remove trailing backslashes
+ elseif ($EnvSource -ne "")
+ { $SourceDirectory = $EnvSource }
+ else
+ { $SourceDirectory = (Get-VendorToolInstallationDirectory) + "\" + (Get-VendorToolSourceDirectory) }
+
+ if ($SourceDirectory -eq "")
+ { Write-Host "[ERROR]: $Module_VendorToolName is not configured in '$ScriptDir\config.psm1'." -ForegroundColor Red
+ Write-Host " Use adv. options '-Source' and '-Output' or configure 'config.psm1'." -ForegroundColor Red
+ Exit-CompileScript -1
+ }
+ elseif (-not (Test-Path $SourceDirectory -PathType Container))
+ { Write-Host "[ERROR]: Path '$SourceDirectory' does not exist." -ForegroundColor Red
+ Exit-CompileScript -1
+ }
+
+ return Convert-Path (Resolve-Path $SourceDirectory)
+}
+
+function Get-DestinationDirectory
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER Output
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [string]$Output
+ )
+ if ($Output -ne "")
+ { $DestinationDirectory = $Output } # TODO: remove trailing backslashes
+ else
+ { $DestinationDirectory = Get-VendorToolDestinationDirectory }
+
+ if ($DestinationDirectory -eq "")
+ { Write-Host "[ERROR]: $Module_VendorToolName is not configured in '$ScriptDir\config.psm1'." -ForegroundColor Red
+ Write-Host " Use adv. options '-Source' and '-Output' or configure 'config.psm1'." -ForegroundColor Red
+ Exit-CompileScript -1
+ }
+
+ # if ($DestinationDirectory.IsAbsolute())
+ # { $DestinationDirectory = "$Module_WorkingDir\$DestinationDirectory" }
+
+ return $DestinationDirectory
+}
+
+function Get-GHDLBinary
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER GHDL
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [string]$GHDL
+ )
+
+ if ($GHDL -ne "")
+ { $GHDLBinary = $GHDL }
+ elseif (Test-Path env:GHDL)
+ { $GHDLBinary = $env:GHDL }
+ else
+ { $GHDLBinary = "ghdl.exe" }
+
+ if (-not (Test-Path $GHDLBinary -PathType Leaf))
+ { Write-Host "Use adv. options '-GHDL' to set the GHDL executable." -ForegroundColor Red
+ Exit-CompileScript -1
+ }
+
+ return $GHDLBinary
+}
+
+
+function Get-VHDLVariables
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER VHDL93
+ Undocumented
+ .PARAMETER VHDL2008
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [bool]$VHDL93 = $false,
+ [bool]$VHDL2008 = $true
+ )
+
+ if ($VHDL93)
+ { $VHDLVersion = "v93"
+ $VHDLStandard = "93c"
+ $VHDLFlavor = "synopsys"
+ }
+ elseif ($VHDL2008)
+ { $VHDLVersion = "v08"
+ $VHDLStandard = "08"
+ $VHDLFlavor = "standard"
+ }
+ else
+ { $VHDLVersion = "v93"
+ $VHDLStandard = "93c"
+ $VHDLFlavor = "synopsys"
+ }
+ return $VHDLVersion,$VHDLStandard,$VHDLFlavor
+}
+
+function New-DestinationDirectory
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER DestinationDirectory
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)][string]$DestinationDirectory
+ )
+
+ if (Test-Path $DestinationDirectory -PathType Container)
+ { Write-Host "Vendor directory '$DestinationDirectory' already exists." -ForegroundColor Yellow }
+ elseif (Test-Path $DestinationDirectory -PathType Leaf)
+ { Write-Host "[ERROR]: Vendor directory '$DestinationDirectory' already exists as a file." -ForegroundColor Red
+ Exit-CompileScript -1
+ }
+ else
+ { Write-Host "Creating vendor directory: '$DestinationDirectory'." -ForegroundColor Yellow
+ mkdir "$DestinationDirectory" -ErrorAction SilentlyContinue | Out-Null
+ }
+}
+
+function Start-PackageCompilation
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER GHDLBinary
+ Undocumented
+ .PARAMETER GHDLOptions
+ Undocumented
+ .PARAMETER Library
+ Undocumented
+ .PARAMETER SourceFiles
+ Undocumented
+ .PARAMETER HaltOnError
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)][string]$GHDLBinary,
+ [Parameter(Mandatory=$true)][string[]]$GHDLOptions,
+ [Parameter(Mandatory=$true)][string]$DestinationDirectory,
+ [Parameter(Mandatory=$true)][string]$Library,
+ [Parameter(Mandatory=$true)][string]$VHDLVersion,
+ [Parameter(Mandatory=$true)][string[]]$SourceFiles,
+ [Parameter(Mandatory=$true)][bool]$HaltOnError
+ )
+ $LibraryDirectory="$DestinationDirectory/$Library/$VHDLVersion"
+ mkdir $LibraryDirectory -ErrorAction SilentlyContinue | Out-Null
+ echo $LibraryDirectory
+ cd $LibraryDirectory
+ Write-Host "Compiling library '$Library' ..." -ForegroundColor Yellow
+ $ErrorCount = 0
+ foreach ($File in $SourceFiles)
+ { Write-Host "Analyzing package file '$File'" -ForegroundColor Cyan
+ $InvokeExpr = "$GHDLBinary " + ($GHDLOptions -join " ") + " --work=$Library " + $File + " 2>&1"
+ $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings
+ if ($LastExitCode -ne 0)
+ { $ErrorCount += 1
+ if ($HaltOnError)
+ { break }
+ }
+ }
+
+ cd $DestinationDirectory
+ # return $ErrorCount
+}
+
+function Start-PrimitiveCompilation
+{ <#
+ .SYNOPSIS
+ Undocumented
+
+ .DESCRIPTION
+ Undocumented
+
+ .PARAMETER GHDLBinary
+ Undocumented
+ .PARAMETER GHDLOptions
+ Undocumented
+ .PARAMETER Library
+ Undocumented
+ .PARAMETER SourceFiles
+ Undocumented
+ .PARAMETER HaltOnError
+ Undocumented
+ #>
+ [CmdletBinding()]
+ param(
+ [Parameter(Mandatory=$true)][string]$GHDLBinary,
+ [Parameter(Mandatory=$true)][string[]]$GHDLOptions,
+ [Parameter(Mandatory=$true)][string]$DestinationDirectory,
+ [Parameter(Mandatory=$true)][string]$Library,
+ [Parameter(Mandatory=$true)][string]$VHDLVersion,
+ [Parameter(Mandatory=$true)][string[]]$SourceFiles,
+ [Parameter(Mandatory=$true)][bool]$HaltOnError
+ )
+ $LibraryDirectory="$DestinationDirectory/$Library/$VHDLVersion"
+ mkdir $LibraryDirectory -ErrorAction SilentlyContinue | Out-Null
+ echo $LibraryDirectory
+ cd $LibraryDirectory
+ Write-Host "Compiling library '$Library' ..." -ForegroundColor Yellow
+ $ErrorCount = 0
+ foreach ($File in $SourceFiles)
+ { Write-Host "Analyzing primitive file '$File'" -ForegroundColor Cyan
+ $InvokeExpr = "$GHDLBinary " + ($GHDLOptions -join " ") + " --work=$Library " + $File + " 2>&1"
+ $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine $SuppressWarnings
+ if ($LastExitCode -ne 0)
+ { $ErrorCount += 1
+ if ($HaltOnError)
+ { break }
+ }
+ }
+
+ cd $DestinationDirectory
+ # return $ErrorCount
+}
+
+
function Restore-NativeCommandStream
{ <#
.SYNOPSIS
@@ -131,5 +440,18 @@ function Write-ColoredGHDLLine
{ $ErrorRecordFound }
}
+Export-ModuleMember -Function 'Exit-CompileScript'
+
+Export-ModuleMember -Function 'Get-SourceDirectory'
+Export-ModuleMember -Function 'Get-DestinationDirectory'
+Export-ModuleMember -Function 'Get-GHDLBinary'
+
+Export-ModuleMember -Function 'Get-VHDLVariables'
+
+Export-ModuleMember -Function 'New-DestinationDirectory'
+Export-ModuleMember -Function 'Start-PackageCompilation'
+Export-ModuleMember -Function 'Start-PrimitiveCompilation'
+
+
Export-ModuleMember -Function 'Restore-NativeCommandStream'
Export-ModuleMember -Function 'Write-ColoredGHDLLine'