aboutsummaryrefslogtreecommitdiffstats
path: root/dist/mcode/windows
diff options
context:
space:
mode:
Diffstat (limited to 'dist/mcode/windows')
-rw-r--r--dist/mcode/windows/compile.ps1362
-rw-r--r--dist/mcode/windows/complib.ps115
-rw-r--r--dist/mcode/windows/shared.psm1147
-rw-r--r--dist/mcode/windows/targets.psm1465
4 files changed, 802 insertions, 187 deletions
diff --git a/dist/mcode/windows/compile.ps1 b/dist/mcode/windows/compile.ps1
index b75ffb6ac..5021d01fc 100644
--- a/dist/mcode/windows/compile.ps1
+++ b/dist/mcode/windows/compile.ps1
@@ -36,219 +36,211 @@
# ==============================================================================
<#
.SYNOPSIS
- GHDL for Windows - GHDL compile script
- Use 'compile.ps1 -Help' to see the integrated help page
+ GHDL for Windows - GHDL compile script
+ Use 'compile.ps1 -Help' to see the integrated help page
.EXAMPLE
- C:\PS> .\compile.ps1 -Verbose -Compile
+ C:\PS> .\compile.ps1 -Clean -Compile
#>
# define script parameters
[CmdletBinding()]
Param(
- # compile GHDL
- [switch]$Compile,
+ # compile ALL
+ [switch]$All = $false,
+
+ # compile main targets
+ [switch]$Compile = $false,
+ # compile GHDL (simulator)
+ [switch]$GHDL = $false,
+ [switch]$Test = $false,
+
+ # compile TOOLS
+ [switch]$Tools = $false,
+ # compile Filter (helper)
+ [switch]$Filter = $false,
+
+ # build options
+ [switch]$Release = $false,
# clean up all files and directories
- [switch]$Clean,
+ [switch]$Clean = $false,
# display this help"
- [switch]$Help
+ [switch]$Help = $false
)
# configure script here
$Script_RelPathToRoot = "..\..\.."
-$GHDLVersion = "0.33dev"
# save parameters and current working directory
-$Script_Parameters = $args
-$Script_ScriptDir = $PSScriptRoot
-$Script_WorkingDir = Get-Location
-$GHDLRootDir_AbsPath = Convert-Path (Resolve-Path ($PSScriptRoot + "\" + $Script_RelPathToRoot))
-
-# configure some variables: paths, executables, directory names, ...
-$SourceDirName = "src"
-$BuildDirName = "dist\mcode\build"
-
-# TODO:
-# check if:
-# - program are installed / auto find programs / auto find paths
-# - program version
-$GCCExecutable = "gcc.exe"
-$GNATExecutable = "gnatmake.exe"
-$StripExecutable = "strip.exe"
-$GHDLExecutable = "ghdl.exe"
-$GHDLFilterExecutable = "ghdlfilter.exe"
-
-# construct directories
-$SourceDir = $GHDLRootDir_AbsPath + "\" + $SourceDirName
-$BuildDir = $GHDLRootDir_AbsPath + "\" + $BuildDirName
+$Script_Parameters = $args
+$Script_WorkingDir = Get-Location
+$GHDLRootDir = Convert-Path (Resolve-Path ($PSScriptRoot + "\" + $Script_RelPathToRoot))
# set default values
-$Script_ExitCode = 0
-if ($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent) { $Script_EnableDebug = $true }
-if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) { $Script_EnableVerbose = $true }
+$Script_ExitCode = 0
+$BuildRelease = "Development" # "Release"
+
+if ($All)
+{ $Compile = $true
+ $Tools = $true
+}
+if ($Compile)
+{ $GHDL = $true
+ $Test = $true
+}
+if ($Tools)
+{ $Filter = $true
+}
+
+if ($Release)
+{ $BuildRelease = "Release" }
+else
+{ $BuildRelease = "Development" }
-# Compiler flags
-$CFlags = @() # start with an empty array
-$CFlags += '-O' # optimize; level ?
-$CFlags += '-g' # enable debug symbols
+$NoCommand = -not ($Clean -or $All -or $Compile -or $Tools -or $GHDL -or $Test -or $Filter)
+if ($NoCommand)
+{ $Help = $true }
-Write-Host "GHDL for Windows - GHDL and tools compile script" -ForegroundColor Yellow
-Write-Host
+Write-Host "================================================================================" -ForegroundColor Magenta
+Write-Host "GHDL for Windows - GHDL and tools compile script" -ForegroundColor Magenta
+Write-Host "================================================================================" -ForegroundColor Magenta
+# if command is help or no command was given => display help page(s)
if ($Help)
- { Write-Host "Usage:"
- Write-Host " compile.ps1 [-Verbose] [-Debug] (-Help|-Compile|-Clean)" -ForegroundColor Gray
- Write-Host
- Write-Host "Options:"
- Write-Host " -Verbose enable detailed messages"
- Write-Host " -Debug enable debug messages"
- Write-Host
- Write-Host "Commands:"
- Write-Host " -Help display this help"
- Write-Host " -Compile compile all library files"
- Write-Host " -Clean clean up all files and directories"
- } # Help
-elseif ($Clean)
- { Write-Host "Removing all created files and directories..."
- Write-Host " rmdir $BuildDir"
-
- Remove-Item $BuildDir -Force -Recurse -ErrorAction SilentlyContinue
- } # Clean
-elseif ($Compile)
- { Write-Host "Compiling GHDL $GHDLVersion for Windows"
- Write-Host "Preparing..."
-
- # create build directory if it does not exist
- if (Test-Path -Path $BuildDir)
- { Write-Host " Directory '$BuildDir' already exists."}
- else
- { Write-Host " Creating directory '$BuildDir'."
- [void](New-Item -ItemType directory -Path $BuildDir -ErrorAction SilentlyContinue)
- }
-
- # change working directory to BuildDir
- Write-Host " cd $BuildDir"
- Set-Location $BuildDir
-
- Write-Host
- Write-Host "Start compilation..."
- # list all files to be compiled; add additional CFlags if needed
- $SourceFiles = @()
- $SourceFiles += New-Object PSObject -Property @{File="grt\grt-cbinding.c"; CFlags=@()}
- $SourceFiles += New-Object PSObject -Property @{File="grt\grt-cvpi.c"; CFlags=@()}
- $SourceFiles += New-Object PSObject -Property @{File="grt\config\clock.c"; CFlags=@()}
- $SourceFiles += New-Object PSObject -Property @{File="grt\config\win32.c"; CFlags=@('-DWITH_GNAT_RUN_TIME')}
- $SourceFiles += New-Object PSObject -Property @{File="ortho\mcode\memsegs_c.c"; CFlags=@()}
-
- # compile c files
- foreach ($SourceFile in $SourceFiles)
- { $Parameters = @()
- $Parameters += '-c'
- $Parameters += $CFlags
- $Parameters += $SourceFile.CFlags
- $Parameters += $SourceDir + "\" + $SourceFile.File
-
- Write-Host (" compiling: " + $SourceFile.File)
- if ($Script_EnableDebug)
- { Write-Host (" file: " + $SourceDir + "\" + $SourceFile.File)
- Write-Host (" call: " + $GCCExecutable + " " + ($Parameters -join ' '))
- }
-
- # call compiler
- & $GCCExecutable $Parameters
- if ($LastExitCode -ne 0)
- { $Script_ExitCode = 1
- Write-Host " ERROR while compiling" -ForegroundColor Red
- }
- }
-
- if ($Script_ExitCode -eq 0)
- { # compile with GNAT
- $Parameters = @()
- $Parameters += $CFlags
- $Parameters += '-gnatn'
-
- # add source include paths
- $Parameters += '-aI' + $GHDLRootDir_AbsPath + '\dist\mcode\windows'
- $Parameters += '-aI' + $SourceDir
- $Parameters += '-aI' + $SourceDir + '\ghdldrv'
- $Parameters += '-aI' + $SourceDir + '\psl'
- $Parameters += '-aI' + $SourceDir + '\grt'
- $Parameters += '-aI' + $SourceDir + '\ortho'
- $Parameters += '-aI' + $SourceDir + '\ortho\mcode'
- $Parameters += '-aI' + $SourceDir + '\vhdl'
- $Parameters += '-aI' + $SourceDir + '\vhdl\translate'
- $Parameters += 'ghdl_jit'
-
- # add output filename
- $Parameters += '-o'
- $Parameters += $GHDLExecutable
-
- # add linker parameters
- $Parameters += '-largs'
- $Parameters += 'grt-cbinding.o'
- $Parameters += 'clock.o'
- $Parameters += 'grt-cvpi.o'
- $Parameters += 'memsegs_c.o'
- $Parameters += 'win32.o'
- $Parameters += '-ldbghelp'
- $Parameters += '-largs'
- $Parameters += '-Wl,--stack,8404992'
-
- # call compiler (GNAT)
- Write-Host " compiling with GNAT"
- if ($Script_EnableDebug)
- { #Write-Host (" file: " + $SourceDir + "\" + $SourceFile.File)
- Write-Host (" call: " + $GNATExecutable + " " + ($Parameters -join ' '))
- }
-
- & $GNATExecutable $Parameters
- if ($LastExitCode -ne 0)
- { $Script_ExitCode = 1
- Write-Host " ERROR while compiling" -ForegroundColor Red }
- }
-
- if ($Script_ExitCode -eq 0)
- { #
- Write-Host " stripping executable..."
- & $StripExecutable $GHDLExecutable
- }
+{ Write-Host "Usage:"
+ Write-Host " compile.ps1 (-Help|-Clean|-All|-Compile|-Tools|-GHDL|-Test|-Filter)" -ForegroundColor Gray
+ Write-Host
+ Write-Host "Options:"
+ Write-Host " -Release build in release mode"
+ # Write-Host " -Debug enable debug messages"
+ # Write-Host
+ Write-Host "Commands:"
+ Write-Host " -Help display this help"
+ Write-Host " -All compile all targets"
+ Write-Host " -Compile compile all main targets"
+ Write-Host " -Tools compile all tool targets"
+ Write-Host " -GHDL compile ghdl.exe"
+ Write-Host " -Filter compile filter.exe"
+ Write-Host " -Clean clean up all files and directories"
+ Write-Host
+
+ exit 0
+} # Help
+
+# load modules
+Import-Module $PSScriptRoot\shared.psm1
+Import-Module $PSScriptRoot\targets.psm1
+
+# grep GHDL version string from Ada source file
+$GHDLVersion = Get-GHDLVersion $GHDLRootDir
+
+# gather git information
+$Git_IsGitRepo = Test-GitRepository
+if ($Git_IsGitRepo)
+{ $Git_Branch_Name = & git rev-parse --abbrev-ref HEAD
+ $Git_Commit_DataString = & git log -1 --format=%cd --date=short
+ $Git_Commit_ShortHash = & git rev-parse --short HEAD
+}
+
+Write-Host " Version: $GHDLVersion"
+Write-Host " Release: $BuildRelease"
+if ($Git_IsGitRepo)
+{ Write-Host " Git branch: $Git_Branch_Name"
+ Write-Host " Git commit: $Git_Commit_DataString ($Git_Commit_ShortHash)"
+}
+Write-Host
- if ($Script_ExitCode -eq 0)
- { # compile with GNAT
- $Parameters = @()
- $Parameters += $CFlags
+function Write-TargetResult($error)
+{ if ($error)
+ { Write-Host " [FAILED]" -ForegroundColor Red }
+ # else
+ # { Write-Host " [DONE]" -ForegroundColor Green }
+}
+
+if ($BuildRelease -eq "Release")
+{ $BuildDir = $GHDLRootDir + "\dist\mcode\build" }
+elseif ($BuildRelease -eq "Development")
+{ $BuildDir = $GHDLRootDir + "\dist\mcode\build" }
+else
+{ Write-Host "[ERROR]: Unknown build setting '$BuildRelease'." -ForegroundColor Red
+ exit 1
+}
- # add source include paths
- $Parameters += '-aI' + $GHDLRootDir_AbsPath + '\dist\mcode\windows'
- $Parameters += 'ghdlfilter'
+# ==============================================================================
+# Main Target: Clean
+# ==============================================================================
+if ($Clean)
+{ $error = Invoke-Clean $BuildDir
+ Write-TargetResult $error
+} # Clean
- # add output filename
- $Parameters += '-o'
- $Parameters += $GHDLFilterExecutable
- # call compiler (GNAT)
- Write-Host " compiling with GNAT"
- if ($Script_EnableDebug)
- { #Write-Host (" file: " + $SourceDir + "\" + $SourceFile.File)
- Write-Host (" call: " + $GNATExecutable + " " + ($Parameters -join ' '))
- }
+# ==============================================================================
+# Main Target: GHDL
+# ==============================================================================
+if ($GHDL)
+{ # create a build directory
+ $error = Invoke-CreateBuildDirectory $BuildDir
+ Write-TargetResult $error
+
+ # patch the version file if it's no release build
+ if ((-not $error) -and ($BuildRelease -eq "Development") -and $Git_IsGitRepo)
+ { $error = Invoke-PatchVersionFile $GHDLRootDir $Git_Branch_Name $Git_Commit_DataString $Git_Commit_ShortHash
+ Write-TargetResult $error
+ }
+
+ # build C source files
+ if (-not $error)
+ { $error = Invoke-CompileCFiles $GHDLRootDir $BuildDir
+ Write-TargetResult $error
+ }
+
+ # build Ada source files
+ if (-not $error)
+ { $error = Invoke-CompileGHDLAdaFiles $GHDLRootDir $BuildDir
+ Write-TargetResult $error
+ }
+
+ # strip result
+ if (-not $error)
+ { $error = Invoke-StripGHDLExecutable $BuildDir
+ Write-TargetResult $error
+ }
+
+ # restore the version file if it was patched
+ if ((-not $error) -and ($BuildRelease -eq "Development") -and $Git_IsGitRepo)
+ { $error = Restore-PatchedVersionFile $GHDLRootDir
+ Write-TargetResult $error
+ }
+} # Compile
+
+if ($Test)
+{ # running ghdl
+ $error = Test-GHDLVersion $BuildDir
+ Write-TargetResult $error
+} # Test
- & $GNATExecutable $Parameters
- if ($LastExitCode -ne 0)
- { $Script_ExitCode = 1
- Write-Host " ERROR while compiling" -ForegroundColor Red }
- }
- } # compile
-else
- { Write-Host "ERROR: missing argument(s)" -ForegroundColor Red
- Write-Host
- Write-Host "Usage:"
- Write-Host " compile.ps1 [-Verbose] [-Debug] (-Help|-Compile|-Clean)" -ForegroundColor Gray
- Write-Host
- } # unknown command
+# ==============================================================================
+# Tool Target: Filter
+# ==============================================================================
+if ($Filter)
+{ # create a build directory
+ $error = Invoke-CreateBuildDirectory $BuildDir
+ Write-TargetResult $error
+
+ # build Ada source files
+ if (-not $error)
+ { $error = Invoke-CompileFilterAdaFiles $GHDLRootDir $BuildDir
+ Write-TargetResult $error
+ }
+} # Tools
+
+
+# unload PowerShell modules
+Remove-Module shared
+Remove-Module targets
# restore working directory if changed
Set-Location $Script_WorkingDir
diff --git a/dist/mcode/windows/complib.ps1 b/dist/mcode/windows/complib.ps1
index 7a622da30..7bdcd00c3 100644
--- a/dist/mcode/windows/complib.ps1
+++ b/dist/mcode/windows/complib.ps1
@@ -78,7 +78,7 @@ $GHDLRootDir_AbsPath = Convert-Path (Resolve-Path ($PSScriptRoot + "\" + $Script
#$VHDLDestLibraryDirName = "lib"
$GHDLExecutable = $GHDLRootDir_AbsPath + "\dist\mcode\build\ghdl.exe"
-$GHDLFilterExecutable = $GHDLRootDir_AbsPath + "\dist\mcode\build\ghdlfilter.exe"
+$GHDLFilterExecutable = $GHDLRootDir_AbsPath + "\dist\mcode\build\filter.exe"
# construct directories
$VHDLSourceLibraryDir = $GHDLRootDir_AbsPath + "\libraries" # + $VHDLSourceLibraryDirName
@@ -603,7 +603,7 @@ elseif ($Compile)
$VHDLSrcLibrary = "vital2000"
foreach ($SourceFile in $SourceFiles[$VHDLSrcLibrary])
- { Write-Host " file: v93\$SourceFile.v93"
+ { Write-Host " file: v93\$SourceFile.vhd"
if ($Script_EnableVerbose) { Write-Host " copy: $SourceFile" }
Copy-Item "$VHDLSourceLibraryDir\$VHDLSrcLibrary\$SourceFile.vhdl" "$SourceFile.vhd"
@@ -710,6 +710,17 @@ elseif ($Compile)
if ($Script_EnableVerbose) { Write-Host (" ghdl analyse (" + ($GHDLParameters -join " ") + ")") }
& $GHDLExecutable $GHDLParameters
}
+
+ $VHDLSrcLibrary = "vital2000"
+ foreach ($SourceFile in $SourceFiles[$VHDLSrcLibrary])
+ { Write-Host " file: v08\$SourceFile.vhd"
+ if ($Script_EnableVerbose) { Write-Host " copy: $SourceFile" }
+ Copy-Item "$VHDLSourceLibraryDir\$VHDLSrcLibrary\$SourceFile.vhdl" "$SourceFile.vhd"
+
+ $GHDLParameters = @("-a", "-C", "-frelaxed-rules", "--std=08", "-P..\std", "--work=$VHDLDestLibrary", "$SourceFile.vhd")
+ if ($Script_EnableVerbose) { Write-Host (" ghdl analyse (" + ($GHDLParameters -join " ") + ")") }
+ & $GHDLExecutable $GHDLParameters
+ }
}
# ==============================================================================
# vXX
diff --git a/dist/mcode/windows/shared.psm1 b/dist/mcode/windows/shared.psm1
new file mode 100644
index 000000000..13ec46ada
--- /dev/null
+++ b/dist/mcode/windows/shared.psm1
@@ -0,0 +1,147 @@
+# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
+# vim: tabstop=2:shiftwidth=2:noexpandtab
+# kate: tab-width 2; replace-tabs off; indent-width 2;
+#
+# ==============================================================================
+# PowerShell Module: The module provides common CmdLets for ...
+#
+# Authors: Patrick Lehmann
+#
+# Description:
+# ------------------------------------
+# This PowerShell module provides CommandLets (CmdLets) to ...
+#
+# ==============================================================================
+# Copyright (C) 2016 Patrick Lehmann
+#
+# GHDL is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GHDL; see the file COPYING. If not, write to the Free
+# Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+# ==============================================================================
+function Restore-NativeCommandStream
+{ <#
+ .SYNOPSIS
+ This CmdLet gathers multiple ErrorRecord objects and reconstructs outputs
+ as a single line.
+
+ .DESCRIPTION
+ This CmdLet collects multiple ErrorRecord objects and emits one String
+ object per line.
+
+ .PARAMETER InputObject
+ A object stream is required as an input.
+ #>
+ [CmdletBinding()]
+ param(
+ [Parameter(ValueFromPipeline=$true)]
+ $InputObject
+ )
+
+ begin
+ { $LineRemainer = "" }
+
+ process
+ { if (-not $InputObject)
+ { Write-Host "Empty pipeline!" }
+ elseif ($InputObject -is [System.Management.Automation.ErrorRecord])
+ { if ($InputObject.FullyQualifiedErrorId -eq "NativeCommandError")
+ { Write-Output $InputObject.ToString() }
+ elseif ($InputObject.FullyQualifiedErrorId -eq "NativeCommandErrorMessage")
+ { $NewLine = $LineRemainer + $InputObject.ToString()
+ while (($NewLinePos = $NewLine.IndexOf("`n")) -ne -1)
+ { Write-Output $NewLine.Substring(0, $NewLinePos)
+ $NewLine = $NewLine.Substring($NewLinePos + 1)
+ }
+ $LineRemainer = $NewLine
+ }
+ }
+ elseif ($InputObject -is [String])
+ { Write-Output $InputObject }
+ else
+ { Write-Host "Unsupported object in pipeline stream" }
+ }
+
+ end
+ { if ($LineRemainer -ne "")
+ { Write-Output $LineRemainer }
+ }
+}
+
+function Write-ColoredGHDLLine
+{ <#
+ .SYNOPSIS
+ This CmdLet colors GHDL output lines.
+
+ .DESCRIPTION
+ This CmdLet colors GHDL output lines. Warnings are prefixed with 'WARNING: '
+ in yellow and errors are prefixed with 'ERROR: ' in red.
+
+ .PARAMETER InputObject
+ A object stream is required as an input.
+
+ .PARAMETER SuppressWarnings
+ Skip warning messages. (Show errors only.)
+ #>
+ [CmdletBinding()]
+ param(
+ [Parameter(ValueFromPipeline=$true)]
+ $InputObject,
+
+ [Parameter(Position=1)]
+ [switch]$SuppressWarnings = $false
+ )
+
+ begin
+ { $ErrorRecordFound = $false }
+
+ process
+ { if (-not $InputObject)
+ { Write-Host "Empty pipeline!" }
+ elseif ($InputObject -is [String])
+ { if ($InputObject -match ":\d+:\d+:\swarning:")
+ { if (-not $SuppressWarnings)
+ { Write-Host "WARNING: " -NoNewline -ForegroundColor Yellow
+ Write-Host $InputObject
+ }
+ }
+ elseif ($InputObject -match ":\d+:\d+:\s")
+ { $ErrorRecordFound = $true
+ Write-Host "ERROR: " -NoNewline -ForegroundColor Red
+ Write-Host $InputObject
+ }
+ else
+ { Write-Host $InputObject }
+ }
+ else
+ { Write-Host "Unsupported object in pipeline stream" }
+ }
+
+ end
+ { $ErrorRecordFound }
+}
+
+function Test-GitRepository
+{ <#
+ .SYNOPSIS
+ Returns true, if the current working directy is under git control.
+ #>
+
+ git rev-parse 2>&1 | Out-Null
+ return $LastExitCode -eq 0
+}
+
+# export functions
+Export-ModuleMember -Function 'Restore-NativeCommandStream'
+Export-ModuleMember -Function 'Write-ColoredGHDLLine'
+Export-ModuleMember -Function 'Test-GitRepository'
diff --git a/dist/mcode/windows/targets.psm1 b/dist/mcode/windows/targets.psm1
new file mode 100644
index 000000000..db6f970a8
--- /dev/null
+++ b/dist/mcode/windows/targets.psm1
@@ -0,0 +1,465 @@
+# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
+# vim: tabstop=2:shiftwidth=2:noexpandtab
+# kate: tab-width 2; replace-tabs off; indent-width 2;
+#
+# ==============================================================================
+# PowerShell Module: The module provides build targets for GHDL.
+#
+# Authors: Patrick Lehmann
+#
+# Description:
+# ------------------------------------
+# This PowerShell module provides build targets for GHDL.
+#
+# ==============================================================================
+# Copyright (C) 2016 Patrick Lehmann
+#
+# GHDL is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any later
+# version.
+#
+# GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GHDL; see the file COPYING. If not, write to the Free
+# Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+# ==============================================================================
+
+# TODO:
+# check if:
+# - program are installed / auto find programs / auto find paths
+# - program version
+
+# configure compiler tools
+$GCCExecutable = "gcc.exe"
+$GNATMakeExecutable = "gnatmake.exe"
+$StripExecutable = "strip.exe"
+
+# configure output file
+$GHDLExecutableName = "ghdl.exe"
+$FilterExecutable = "filter.exe"
+
+# configure directory structure
+$CommonSourceDirName = "src"
+$WinMcodeSourceDirName = "dist\mcode\windows"
+# $WinLLVMSourceDirName = "dist\llvm\windows"
+$WinMcodeBuildDirName = "dist\mcode\build"
+# $WinLLVMBuildDirName = "dist\llvm\build"
+
+# construct file paths
+$VersionFileName = "version.ads"
+
+
+function Invoke-Clean
+{ <#
+ .SYNOPSIS
+ This CommandLet removes all generated files.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console.
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+
+ Write-Host "Executing build target 'Clean' ..." -ForegroundColor Yellow
+ if ($Quiet -eq $false)
+ { Write-Host " Removing all created files and directories..."
+ Write-Host " rmdir $BuildDirectory"
+ }
+ Remove-Item $BuildDirectory -Force -Recurse -ErrorAction SilentlyContinue
+
+ return $false
+} # Invoke-Clean
+
+function Invoke-CreateBuildDirectory
+{ <#
+ .SYNOPSIS
+ This CommandLet creates a build directory if not existent, yet.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console.
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+
+ Write-Host "Executing build target 'CreateBuildDirectory' ..." -ForegroundColor Yellow
+ if (Test-Path -Path $BuildDirectory)
+ { if ($Quiet -eq $false)
+ { Write-Host " Directory '$BuildDirectory' already exists." }
+ }
+ else
+ { if ($Quiet -eq $false)
+ { Write-Host " Creating new directory '$BuildDirectory'." }
+
+ [void](New-Item -ItemType directory -Path $BuildDirectory -ErrorAction SilentlyContinue)
+ }
+
+ return $false
+} # Invoke-CreateBuildDirectory
+
+function Get-GHDLVersion
+{ <#
+ .SYNOPSIS
+ Returns the GHDL version string.
+ .PARAMETER GHDLRootDir
+ The repository root directory.
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir
+ )
+ # construct DirectoryPaths
+ $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+ # construct FilePaths
+ $VersionFilePath = $SourceDirectory + "\" + $VersionFileName
+
+ if (-not (Test-Path -Path $VersionFilePath))
+ { Write-Host " Version file '$VersionFilePath' does not exists." -ForegroundColor Red
+ return ""
+ }
+ $FileContent = Get-Content -Path $VersionFilePath
+ foreach ($Line in $FileContent)
+ { if ($Line -match 'Ghdl_Ver(.+?)\"(.+?)\";')
+ { return $Matches[2] }
+ }
+ return ""
+}
+
+function Invoke-PatchVersionFile
+{ <#
+ .SYNOPSIS
+ This CommandLet patches the version file to include the git patch state.
+ .PARAMETER GHDLRootDir
+ The repository root directory.
+ .PARAMETER GitBranchName
+ The branch's name, where HEAD is located.
+ .PARAMETER GitCommitDataString
+ The DateTime when HEAD was commited.
+ .PARAMETER GitCommitHash
+ The Hash of HEAD.
+ .PARAMETER Quiet
+ Disable outputs to the host console.
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir,
+ [string] $GitBranchName = "unknown",
+ [string] $GitCommitDataString = "unknown",
+ [string] $GitCommitHash = "........",
+ [switch] $Quiet = $false
+ )
+ # construct DirectoryPaths
+ $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+ # construct FilePaths
+ $CurrentVersionFilePath = $SourceDirectory + "\" + $VersionFileName
+ $OriginalVersionFilePath = $SourceDirectory + "\" + $VersionFileName + ".bak"
+
+ Write-Host "Executing build target 'PatchVersionFile' ..." -ForegroundColor Yellow
+
+ if (-not (Test-Path -Path $CurrentVersionFilePath))
+ { Write-Host " Version file '$CurrentVersionFilePath' does not exists." -ForegroundColor Red
+ return $true
+ }
+ if ($Quiet -eq $false)
+ { Write-Host " Patching '$CurrentVersionFilePath'." }
+ $FileContent = Get-Content -Path $CurrentVersionFilePath -Encoding Ascii
+ $FileContent = $FileContent -Replace "\s\(\d+\)\s", " (commit: $GitCommitDataString; git branch: $GitBranchName'; hash: $GitCommitHash) "
+
+ Move-Item $CurrentVersionFilePath $OriginalVersionFilePath -Force
+ $FileContent | Out-File $CurrentVersionFilePath -Encoding Ascii
+
+ return $false
+} # Invoke-PatchVersionFile
+
+function Restore-PatchedVersionFile
+{ <#
+ .SYNOPSIS
+ This CommandLet restores the original version file.
+ .PARAMETER GHDLRootDir
+ The repository root directory.
+ .PARAMETER Quiet
+ Disable outputs to the host console.
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir,
+ [switch] $Quiet = $false
+ )
+ # construct DirectoryPaths
+ $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+ # construct FilePaths
+ $CurrentVersionFilePath = $SourceDirectory + "\" + $VersionFileName
+ $OriginalVersionFilePath = $SourceDirectory + "\" + $VersionFileName + ".bak"
+
+ Write-Host "Executing build target 'PatchedVersionFile' ..." -ForegroundColor Yellow
+
+ if (-not (Test-Path -Path "$CurrentVersionFilePath"))
+ { Write-Host " Version file '$CurrentVersionFilePath' does not exists." -ForegroundColor Red
+ return $true
+ }
+ if ($Quiet -eq $false)
+ { Write-Host " Restoring '$CurrentVersionFilePath'." }
+ Move-Item $OriginalVersionFilePath $CurrentVersionFilePath -Force
+ return $false
+} # Restore-PatchedVersionFile
+
+function Get-CFlags
+{ <#
+ .SYNOPSIS
+ Returns common ANSI C compiler flags for GCC.
+ #>
+ return @(
+ "-O1", # optimize; level 1
+ "-g" # enable debug symbols
+ )
+}
+
+function Invoke-CompileCFiles
+{ <#
+ .SYNOPSIS
+ This CommandLet compiles all C files with GCC.
+ .PARAMETER GHDLRootDir
+ The repository root directory.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir,
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+ # construct DirectoryPaths
+ $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+
+ Set-Location $BuildDirectory
+ Write-Host "Executing build target 'CompileCFiles' ..." -ForegroundColor Yellow
+
+ # list all files to be compiled; add additional CFlags if needed
+ $SourceFiles = @()
+ $SourceFiles += New-Object PSObject -Property @{File="grt\grt-cbinding.c"; CFlags=@()}
+ $SourceFiles += New-Object PSObject -Property @{File="grt\grt-cvpi.c"; CFlags=@()}
+ $SourceFiles += New-Object PSObject -Property @{File="grt\config\clock.c"; CFlags=@()}
+ $SourceFiles += New-Object PSObject -Property @{File="grt\config\win32.c"; CFlags=@('-DWITH_GNAT_RUN_TIME')}
+ $SourceFiles += New-Object PSObject -Property @{File="ortho\mcode\memsegs_c.c"; CFlags=@()}
+
+ # compile C files
+ foreach ($SourceFile in $SourceFiles)
+ { $Parameters = @()
+ $Parameters += "-c" # compile only
+ $Parameters += Get-CFlags # append common CFlags
+ $Parameters += $SourceFile.CFlags
+ $Parameters += $SourceDirectory + "\" + $SourceFile.File
+
+ # call C compiler
+ $InvokeExpr = "$GCCExecutable " + ($Parameters -join " ") + " 2>&1"
+
+ Write-Host (" compiling: " + $SourceFile.File)
+ Write-Debug " call: $InvokeExpr"
+ $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine
+ if ($LastExitCode -ne 0)
+ { return $true }
+ }
+
+ return $false
+} # Invoke-CompileCFiles
+
+
+function Invoke-CompileGHDLAdaFiles
+{ <#
+ .SYNOPSIS
+ This CommandLet compiles all Ada files with GNAT.
+ .PARAMETER GHDLRootDir
+ The repository root directory.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir,
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+ # construct DirectoryPaths
+ $CommonSourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+ $WinMcodeSourceDirectory = $GHDLRootDir + "\" + $WinMcodeSourceDirName
+
+ Set-Location $BuildDirectory
+ Write-Host "Executing build target 'CompileGHDLAdaFiles' ..." -ForegroundColor Yellow
+
+ $Parameters = @()
+ $Parameters += Get-CFlags # append common CFlags
+ $Parameters += '-gnatn'
+
+ # append all source paths
+ $Parameters += '-aI' + $WinMcodeSourceDirectory
+ $Parameters += '-aI' + $CommonSourceDirectory
+ $Parameters += '-aI' + $CommonSourceDirectory + '\ghdldrv'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\psl'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\grt'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\ortho'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\ortho\mcode'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\vhdl'
+ $Parameters += '-aI' + $CommonSourceDirectory + '\vhdl\translate'
+
+ # top level
+ $Parameters += 'ghdl_jit'
+
+ # add output filename
+ $Parameters += '-o'
+ $Parameters += $GHDLExecutableName
+
+ # append linker parameters
+ $Parameters += '-largs'
+ $Parameters += 'grt-cbinding.o'
+ $Parameters += 'clock.o'
+ $Parameters += 'grt-cvpi.o'
+ $Parameters += 'memsegs_c.o'
+ $Parameters += 'win32.o'
+ $Parameters += '-ldbghelp'
+ $Parameters += '-largs'
+ # $Parameters += '-Wl,--stack,8404992'
+
+ # call Ada compiler (GNAT)
+ $InvokeExpr = "$GNATMakeExecutable " + ($Parameters -join " ") + " 2>&1"
+
+ Write-Host " compiling with GNAT"
+ Write-Debug " call: $InvokeExpr"
+ $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine
+ return ($LastExitCode -ne 0)
+} # Invoke-CompileGHDLAdaFiles
+
+function Invoke-CompileFilterAdaFiles
+{ <#
+ .SYNOPSIS
+ This CommandLet compiles all Ada files with GNAT.
+ .PARAMETER SourceDirectory
+ The directory where all source files are located.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $GHDLRootDir,
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+ # construct DirectoryPaths
+ $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName
+
+ Set-Location $BuildDirectory
+ Write-Host "Executing build target 'CompileFilterAdaFiles' ..." -ForegroundColor Yellow
+
+ $Parameters = @()
+ $Parameters += Get-CFlags # append common CFlags
+ $Parameters += '-gnatn'
+
+ # append all source paths
+ $Parameters += '-aI' + $SourceDirectory + '\..\dist\mcode\windows'
+
+ # top level
+ $Parameters += 'ghdlfilter'
+
+ # add output filename
+ $Parameters += '-o'
+ $Parameters += $FilterExecutable
+
+ # call Ada compiler (GNAT)
+ $InvokeExpr = "$GNATMakeExecutable " + ($Parameters -join " ") + " 2>&1"
+
+ Write-Host " compiling with GNAT"
+ Write-Debug " call: $InvokeExpr"
+ $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGHDLLine
+ return ($LastExitCode -ne 0)
+} # Invoke-CompileFilterAdaFiles
+
+function Invoke-StripGHDLExecutable
+{ <#
+ .SYNOPSIS
+ This CommandLet strips the result files.
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+
+ Set-Location $BuildDirectory
+ Write-Host "Executing build target 'StripGHDLExecutable' ..." -ForegroundColor Yellow
+
+ # call striping tool (strip)
+ Write-Host " stripping '$GHDLExecutableName'"
+ Write-Debug " call: $StripExecutable $GHDLExecutableName"
+ & $StripExecutable $GHDLExecutableName
+ return ($LastExitCode -ne 0)
+} # Invoke-StripGHDLExecutable
+
+function Test-GHDLVersion
+{ <#
+ .SYNOPSIS
+ This CommandLet executes ghdl to read the version information
+ .PARAMETER BuildDirectory
+ The directory where all generated files are stored.
+ .PARAMETER Quiet
+ Disable outputs to the host console
+ #>
+ [CmdletBinding()]
+ param(
+ [string] $BuildDirectory,
+ [switch] $Quiet = $false
+ )
+
+ Set-Location $BuildDirectory
+ Write-Host "Executing build target 'GHDLVersion' ..." -ForegroundColor Yellow
+
+ if (-not (Test-Path -Path $GHDLExecutableName))
+ { Write-Host " GHDL executable '$GHDLExecutableName' does not exists." -ForegroundColor Red
+ return $true
+ }
+
+ # call ghdl
+ $InvokeExpr = "$GHDLExecutableName --version 2>&1"
+
+ Write-Host " executing '$GHDLExecutableName'"
+ Write-Host " call: $InvokeExpr"
+ Write-Host "----------------------------------------"
+ Invoke-Expression $InvokeExpr | Restore-NativeCommandStream
+ Write-Host "----------------------------------------"
+ return ($LastExitCode -ne 0)
+} # Test-GHDLVersion
+
+
+# export functions
+Export-ModuleMember -Function 'Get-GHDLVersion'
+Export-ModuleMember -Function 'Invoke-Clean'
+Export-ModuleMember -Function 'Invoke-CreateBuildDirectory'
+Export-ModuleMember -Function 'Invoke-PatchVersionFile'
+Export-ModuleMember -Function 'Restore-PatchedVersionFile'
+Export-ModuleMember -Function 'Invoke-CompileCFiles'
+Export-ModuleMember -Function 'Invoke-CompileGHDLAdaFiles'
+Export-ModuleMember -Function 'Invoke-CompileFilterAdaFiles'
+Export-ModuleMember -Function 'Invoke-StripGHDLExecutable'
+Export-ModuleMember -Function 'Test-GHDLVersion'