aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/windows/compile.ps1
blob: da3c6773189b9a0a99ce080d851ade0c1f89a2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# 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;
# 
# ==============================================================================
#  Authors:            Patrick Lehmann  (ported batch file to PowerShell)
#                      Brian Davis      (contributions to the batch file)
#                      Tristan Gingold  (initial batch file for compilations on Windows)
# 
#  PowerShell Script:  Script to compile GHDL for Windows
# 
# Description:
# ------------------------------------
#  This is a PowerShell script (executable) which:
#    - compiles GHDL and GHDLFilter
#    - analyses VHDL libraries
#    - installs GHDL into a directory (xcopy deploiment)
#
# ==============================================================================
#  Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
#  Copyright (C) 2015-2017 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.
# ==============================================================================

# .SYNOPSIS 
# GHDL for Windows - GHDL compile script
# Use 'compile.ps1 -Help' to see the integrated help page
# 
# .EXAMPLE
# #
# # Normal flow
# PS> .\compile.ps1 -Clean
# PS> .\compile.ps1 -Compile
# PS> .\compile.ps1 -Install
# 
# # Combine all commands in a single call
# PS>.\compile.ps1 -Clean -Compile -Install "C:\Tools\GHDL"
#
# # Install to user defined dir
# PS> .\compile.ps1 -Install "C:\Tools\GHDL"
#
# # Update or Uninstall
# PS> .\compile.ps1 -Update
# PS> .\compile.ps1 -Uninstall
# 
# # Create a Zip-file
# PS>.\compile.ps1 -Package -Zip 
#
[CmdletBinding()]
Param(
	# Clean up all files and directories
	[switch]$Clean,
		[switch]$Clean_GHDL,
		[switch]$Clean_Libraries,
		
	# Compile GHDL
	[switch]$Compile,
		[switch]$Compile_GHDL,
		[switch]$Compile_Libraries,

	# Create an installer package
	[switch]$Package,
		# Creates a zip-file for xcopy deployment
		[switch]$Zip,
		# Creates a self-extracting ps1-file for xcopy deployment
		[switch]$PS1,
	
	# Install all files into a directory (xcopy deployment)
	[switch]$Install = $false,
	[parameter(mandatory=$false, ValueFromRemainingArguments=$true)]
	[string]$InstallDir = "",
	# Update files
	[switch]$Update,
	# Uninstall all files from a directory
	[switch]$Uninstall,

	# register GHDL in PATH
	[Parameter(Mandatory=$false)]
	[ValidateSet("Machine", "User", "Session", "Remove", "Pass")]
	[String]$AddToPath = "",
	
	# Display this help"
	[switch]$Help
)

# configure script here
$RelPathToRoot =      "..\.."

# save parameters and current working directory
$Script_ScriptDir =    $PSScriptRoot
$Script_WorkingDir =  Get-Location
$GHDLRootDir =        Convert-Path (Resolve-Path ($PSScriptRoot + "\" + $RelPathToRoot))

# set default values
$Hosting =            $true
$EnableDebug =        [bool]$PSCmdlet.MyInvocation.BoundParameters["Debug"]
$EnableVerbose =      [bool]$PSCmdlet.MyInvocation.BoundParameters["Verbose"] -or $EnableDebug

# load modules from GHDL's 'libraries' directory
Import-Module $PSScriptRoot\shared.psm1  -Verbose:$false -Debug:$false -ArgumentList "$Script_WorkingDir", $Hosting
Import-Module $PSScriptRoot\targets.psm1 -Verbose:$false -Debug:$false

# Display help if no command was selected
$Help = $Help -or (-not (
					$All -or 
					$Clean -or $Clean_GHDL -or $Clean_Libraries -or $Clean_Package_Zip -or
					$Compile -or $Compile_GHDL -or $Compile_Libraries -or
					$Package -or
					$Install -or $Update -or $Uninstall
				))

Write-Host "================================================================================" -ForegroundColor Magenta
Write-Host "GHDL for Windows - GHDL compile and bundle script" -ForegroundColor Magenta
Write-Host "================================================================================" -ForegroundColor Magenta

if ($Help)
{	Get-Help $MYINVOCATION.InvocationName -Detailed
	Exit-CompileScript
}

if ($All)
{	$Clean =              $true
	$Compile =            $true
	$Package =            $true
}
if ($Clean)
{	$Clean_GHDL =         $true
	$Clean_Libraries =    $true
	$Clean_Package_Zip =  $true
}
if ($Compile)
{	$Compile_GHDL =       $true
	$Compile_Libraries =  $true
}

# configure some variables: paths, executables, directory names, ...
$GHDLVersion =                Get-GHDLVersion $GHDLRootDir
$Backend =                    "mcode"
$WindowsDirName =             "dist\windows"    #\$Backend"
$BuildDirectoryName =         "build"
$BuildBackendDirectoryName =  "$BuildDirectoryName\$Backend"
$VHDLLibrariesDirectoryName = "lib"
$PackageDirectoryName =       "build\zip\$Backend"
$ZipPackageFileName =         "ghdl-$Backend-$GHDLVersion.zip"
$PS1PackageFileName =         "ghdl-$Backend-$GHDLVersion.installer.ps1"
$InstallerTemplateFileName =  "InstallerTemplate.ps1"
$DefaultInstallPath =         "C:\Program Files (x86)\GHDL"        # This is the default path for 32-bit applications (x86-32)

# construct directories
$GHDLWindowsDir =             "$GHDLRootDir\$WindowsDirName"
$GHDLBuildDir =               "$GHDLRootDir\$BuildBackendDirectoryName"
$GHDLVendorLibraryDir =       "$GHDLRootDir\libraries\vendors"
$GHDLCompiledLibraryDir =     "$GHDLRootDir\$BuildBackendDirectoryName\$VHDLLibrariesDirectoryName"
$GHDLZipPackageDir =          "$GHDLRootDir\$PackageDirectoryName"
$GHDLZipPackageFile =         "$GHDLZipPackageDir\$ZipPackageFileName"
$InstallerTemplateFile =      "$GHDLWindowsDir\$InstallerTemplateFileName"
$GHDLPS1PackageFile =         "$GHDLZipPackageDir\$PS1PackageFileName"

# construct files
$InstallDirFile =             "$BuildDirectoryName\InstallDir.conf"

$EnvPath_ContainerMapping = @{
	Machine = [EnvironmentVariableTarget]::Machine
	User =    [EnvironmentVariableTarget]::User
}

function Exit-Script
{	[CmdletBinding()]
	param(
		[int]$ExitCode = 0
	)
	cd $Script_WorkingDir
	# unload modules
	Remove-Module shared  -Verbose:$false -Debug:$false
	Remove-Module targets -Verbose:$false -Debug:$false
	exit $ExitCode
}

# GitHub user:            https://github.com/mkropat
# Gist account at GitHub: https://gist.github.com/mkropat
# Gist snippet URL:       https://gist.github.com/mkropat/c1226e0cc2ca941b23a9
function Add-EnvPath
{	param(
		[Parameter(Mandatory=$true)]
		[string] $Path,

		[ValidateSet("Machine", "User", "Session")]
		[string] $Container = "Session"
	)

	if ($Container -ne "Session")
	{	$containerType =  $EnvPath_ContainerMapping[$Container]
		$persistedPaths = [Environment]::GetEnvironmentVariable("Path", $containerType) -split ";"
		if ($persistedPaths -notcontains $Path)
		{	$persistedPaths = $persistedPaths + $Path | where { $_ }
			[Environment]::SetEnvironmentVariable("Path", $persistedPaths -join ";", $containerType)
		}
	}

	$envPaths = $env:Path -split ";"
	if ($envPaths -notcontains $Path)
	{	$envPaths = $envPaths + $Path | where { $_ }
		$env:Path = $envPaths -join ";"
	}
}

# GitHub user:            https://github.com/mkropat
# Gist account at GitHub: https://gist.github.com/mkropat
# Gist snippet URL:       https://gist.github.com/mkropat/c1226e0cc2ca941b23a9
function Remove-EnvPath
{	param (
		[Parameter(Mandatory=$true)]
		[string] $Path,

		[ValidateSet("Machine", "User", "Session")]
		[string] $Container = "Session"
	)

	if ($Container -ne "Session")
	{	$containerType =  $EnvPath_ContainerMapping[$Container]
		$persistedPaths = [Environment]::GetEnvironmentVariable("Path", $containerType) -split ";"
		if ($persistedPaths -contains $Path)
		{	$persistedPaths = $persistedPaths | where { $_ -and $_ -ne $Path }
			[Environment]::SetEnvironmentVariable("Path", $persistedPaths -join ";", $containerType)
		}
	}

	$envPaths = $env:Path -split ";"
	if ($envPaths -contains $Path)
	{	$envPaths = $envPaths | where { $_ -and $_ -ne $Path }
		$env:Path = $envPaths -join ";"
	}
}

# GitHub user:            https://github.com/mkropat
# Gist account at GitHub: https://gist.github.com/mkropat
# Gist snippet URL:       https://gist.github.com/mkropat/c1226e0cc2ca941b23a9
function Get-EnvPath
{	param (
		[Parameter(Mandatory=$true)]
		[ValidateSet("Machine", "User")]
		[string] $Container
	)

	$containerType = $EnvPath_ContainerMapping[$Container]
	[Environment]::GetEnvironmentVariable('Path', $containerType) -split ";" | where { $_ }
}


if ($false)
{	# Write-Host "Uninstalling GHDL $GHDLVersion for Windows..."

	# Write-Host "[ERROR]: This command is not implemented." -ForegroundColor Red
	Exit-Script -1
}  # Uninstall
else
{	# ============================================================================
	# Clean tasks
	# ============================================================================
	if ($Clean)
	{	Write-Host "Removing all created files and directories..."    }
	
	if ($Clean_GHDL)
	{	$Script_Path =         $GHDLWindowsDir + "\compile-ghdl.ps1"
		$Script_Parameters =  @(
			'-Clean',
			'-Hosted',
			'-Verbose:$EnableVerbose',
			'-Debug:$EnableDebug'
		)
		
		Write-Host "Running compile-ghdl.ps1 -Clean ..." -ForegroundColor DarkCyan
		Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		$InvokeExpr = "$Script_Path " + ($Script_Parameters -join " ")
		Invoke-Expression $InvokeExpr
		if ($LastExitCode -ne 0)
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "[ERROR]: While executing '$InvokeExpr'." -ForegroundColor Red
			Exit-Script -1
		}
		else
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "Completed compile-ghdl.ps1 " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
		}
	}  # Clean_GHDL
	if ($Clean_Libraries)
	{	if ($Clean_GHDL)
		{	Write-Host    }
		
		$Script_Path =        $GHDLWindowsDir + "\compile-libraries.ps1"
		$Script_Parameters =  @(
			'-Clean',
			'-Hosted',
			'-Verbose:$EnableVerbose',
			'-Debug:$EnableDebug'
		)
		
		Write-Host "Running compile-libraries.ps1 -Clean ..." -ForegroundColor DarkCyan
		Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		$InvokeExpr = "$Script_Path " + ($Script_Parameters -join " ")
		Invoke-Expression $InvokeExpr
		if ($LastExitCode -ne 0)
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "[ERROR]: While executing '$InvokeExpr'." -ForegroundColor Red
			Exit-Script -1
		}
		else
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "Completed compile-libraries.ps1 " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
		}
	}  # Clean_Libraries
	if ($Clean_Package_Zip)
	{	if ($Clean_GHDL -or $Clean_Libraries)
		{	Write-Host    }
	
		Write-Host "Running more clean-up tasks..." -ForegroundColor DarkCyan
		Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		Write-Host "Removing installer packages and temporary directories..." -ForegroundColor Yellow
		if (Test-Path -Path $GHDLZipPackageDir)
		{	Write-Host "  rmdir $GHDLZipPackageDir"
			Remove-Item $GHDLZipPackageDir -Force -Recurse -ErrorAction SilentlyContinue
			if ($? -eq $false)
			{	Write-Host "[ERROR]: While deleting '$GHDLZipPackageDir'." -ForegroundColor Red
				Exit-Script -1
			}
		}
		
		if (Test-Path -Path $GHDLZipPackageFile)
		{	Write-Host "  rm $GHDLZipPackageFile"
			Remove-Item $GHDLZipPackageFile -Force -Recurse -ErrorAction SilentlyContinue
			if ($? -eq $false)
			{	Write-Host "[ERROR]: While deleting '$GHDLZipPackageFile'." -ForegroundColor Red
				Exit-Script -1
			}
		}
		
		Write-Host
		Write-Host "Clean " -NoNewline
		Write-Host "[SUCCESSFUL]" -ForegroundColor Green
		Write-Host
	}  # Clean_Package_Zip
	
	# ============================================================================
	# Compile tasks
	# ============================================================================
	if ($Compile_GHDL)
	{	if ($Clean)
		{	Write-Host    }
			
		$Script_Path =        $GHDLWindowsDir + "\compile-ghdl.ps1"
		$Script_Parameters =  @()
		$Script_Parameters =  @(
			'-All',
			'-Hosted',
			'-Verbose:$EnableVerbose',
			'-Debug:$EnableDebug'
		)
		
		# Write-Host "Compiling GHDL $GHDLVersion for Windows..." -ForegroundColor DarkCyan
		# Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		
		Write-Host
		Write-Host "Running compile-ghdl.ps1 -All ..." -ForegroundColor DarkCyan
		Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		$InvokeExpr = "$Script_Path " + ($Script_Parameters -join " ")
		Invoke-Expression $InvokeExpr
		if ($LastExitCode -ne 0)
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "[ERROR]: While executing '$InvokeExpr'." -ForegroundColor Red
			Exit-Script -1
		}
		else
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "Completed compile-ghdl.ps1 " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
		}
	}  # Compile_GHDL
	if ($Compile_Libraries)
	{	if ($Compile_GHDL)
		{	Write-Host    }
		
		$Script_Path =        $GHDLWindowsDir + "\compile-libraries.ps1"
		$Script_Parameters =  @()
		$Script_Parameters =  @(
			'-Compile',
			'-Hosted',
			'-Verbose:$EnableVerbose',
			'-Debug:$EnableDebug'
		)
		
		# Write-Host "Compiling GHDL's libraries ..." -ForegroundColor DarkCyan
		# Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		
		$env:GHDL = "$GHDLBuildDir\ghdl.exe"
		Write-Host ("Setting env:GHDL to '" + $env:GHDL + "'")

		Write-Host
		Write-Host "Running compile-libraries.ps1 -Compile ..." -ForegroundColor DarkCyan
		Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
		$InvokeExpr = "$Script_Path " + ($Script_Parameters -join " ")
		Invoke-Expression $InvokeExpr
		if ($LastExitCode -ne 0)
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "[ERROR]: While executing '$InvokeExpr'." -ForegroundColor Red
			Exit-Script -1
		}
		else
		{	Write-Host "--------------------------------------------------------------------------------" -ForegroundColor DarkCyan
			Write-Host "Completed compile-libraries.ps1 " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
		}
	}  # Compile_GHDL
	
	# ============================================================================
	# Package tasks
	# ============================================================================
	if ($Package)
	{	Write-Host "Creating an installation package for GHDL $GHDLVersion for Windows"
		$Good = $false
	
		if ($Zip)
		{	Write-Host "Loading PowerShell Community Extensions (PSCX) " -NoNewline
			if ((Get-Module -ListAvailable | Where {$_.Name -like "PSCX"}).Version -ge "3.1.0.0")
			{	Import-Module Pscx -Verbose:$false
				Write-Host "[Done]" -ForegroundColor Green
			}
			else
			{	Write-Host "[FAILED]" -ForegroundColor RED  
				Exit-Script -1
			}
			
			Write-Host "Output format: zip-file"
			Write-Host "  Removing old directory '$GHDLZipPackageDir'."
			if (Test-Path -Path $GHDLZipPackageDir)
			{	Remove-Item $GHDLZipPackageDir -Force -Recurse -ErrorAction SilentlyContinue
				if ($? -eq $false)
				{	Write-Host "[ERROR]: While deleting '$GHDLZipPackageDir'." -ForegroundColor Red
					Exit-Script -1
				}
			}
			if (Test-Path -Path $GHDLZipPackageFile)
			{	Remove-Item $GHDLZipPackageFile -Force -Recurse -ErrorAction SilentlyContinue
				if ($? -eq $false)
				{	Write-Host "[ERROR]: While deleting '$GHDLZipPackageFile'." -ForegroundColor Red
					Exit-Script -1
				}
			}
		
			Write-Host "  Creating directory '$GHDLZipPackageDir' and sub-directories..."
			New-Item -ItemType directory -Path "$GHDLZipPackageDir"            -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$GHDLZipPackageDir\bin"        -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$GHDLZipPackageDir\include"    -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$GHDLZipPackageDir\lib"        -ErrorAction SilentlyContinue  | Out-Null
			
			Write-Host "  Gathering files..."
			# executables
			Copy-Item "$GHDLBuildDir\ghdl.exe"            "$GHDLZipPackageDir\bin\ghdl.exe" -ErrorAction SilentlyContinue
			# include files
			Copy-Item "$GHDLRootDir\src\grt\vpi_user.h"   "$GHDLZipPackageDir\include"      -ErrorAction SilentlyContinue
			# pre-compile scripts
			Copy-Item $GHDLVendorLibraryDir -Recurse      "$GHDLZipPackageDir\lib\vendors"  -ErrorAction SilentlyContinue
			# pre-compiled libraries
			Copy-Item $GHDLCompiledLibraryDir  -Recurse   "$GHDLZipPackageDir"              -ErrorAction SilentlyContinue

			Write-Host "  Compressing all files into '$GHDLZipPackageFile'..."
			$file = Get-ChildItem $GHDLZipPackageDir -Recurse | Write-Zip -IncludeEmptyDirectories -EntryPathRoot $GHDLZipPackageDir -OutputPath $GHDLZipPackageFile
			Write-Host "  $([math]::round(($file.Length / 1MB), 3)) MiB written to disk"
			 
			 Write-Host
			Write-Host "Creating package " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
			
			$Good = $true
		}
		
		if ($PS1)
		{	Write-Host "Creating a self-extracting PowerShell package for GHDL $GHDLVersion for Windows"
		
			if (-not (Test-Path -Path $GHDLZipPackageFile))
			{	Write-Host "[ERROR]: ZIP file '$GHDLZipPackageFile' does not exist." -ForegroundColor Red
				Exit-Script -1
			}
		
			# Read ZIP file and convert it to base64
			$ResolvedPath =                   Resolve-Path "$GHDLZipPackageFile"
			$CompressedFileContentAsBytes =   [System.IO.File]::ReadAllBytes("$ResolvedPath")
			$CompressedFileContentInBase64 =  [System.Convert]::ToBase64String($CompressedFileContentAsBytes)
			
			# Read a Installer template and add the base64 content
			$Installer = Get-Content $InstallerTemplateFile
			$Installer = $Installer -replace "# DATASECTION", "`$CompressedFileContentInBase64 = `"$CompressedFileContentInBase64`""
			$Installer | Out-File -FilePath $GHDLPS1PackageFile
					
			Write-Host
			Write-Host "Creating package " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
			
			$Good = $true
		}
		
		if (-not $Good)
		{	Write-Host "[ERROR]: No package format selected." -ForegroundColor Red
			Write-Host "Possible formats:"
			Write-Host "  - Zip-file (-Zip)"
			Write-Host
		}
	}
	# ============================================================================
	# Install tasks
	# ============================================================================
	if ($Install)
	{	Write-Host "Installing GHDL $GHDLVersion for Windows..."
		if ($InstallDir -eq "")
		{	if (Test-Path $InstallDirFile -PathType Leaf)
			{	Write-Host "  Reading installation path from '$InstallDirFile' ..."
				$InstallPath = Get-Content $InstallDirFile -Encoding Ascii
			}
			else
			{	$InstallPath = $DefaultInstallPath  }
		}
		else
		{	$InstallPath = $InstallDir      }
		$InstallPath = $InstallPath.TrimEnd("\")
		
		if ($Zip)
		{	Write-Host "Loading PowerShell Community Extensions (PSCX) " -NoNewline
			if ((Get-Module -ListAvailable | Where {$_.Name -like "PSCX"}).Version -ge "3.1.0.0")
			{	Import-Module Pscx -Verbose:$false
				Write-Host "[Done]" -ForegroundColor Green
			}
			else
			{	Write-Host "[FAILED]" -ForegroundColor RED  
				Exit-Script -1
			}
			
			Write-Host "  Installing from Zip-file..."
			
			Write-Host "[ERROR]: This command is not implemented." -ForegroundColor Red
		}
		else
		{	Write-Host "  Writing installation path to '$InstallDirFile'..."
			$InstallPath | Out-File -FilePath $InstallDirFile -Encoding Ascii
		
			if (Test-Path -Path $InstallPath)
			{	Write-Host "[ERROR]: Directory '$InstallPath' already exists." -ForegroundColor Red
				Exit-Script -1
			}
			Write-Host "  Install directory: $InstallPath"
			Write-Host "  Creating directory '$InstallPath' and sub-directories..."
			New-Item -ItemType directory -Path "$InstallPath"            -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$InstallPath\bin"        -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$InstallPath\include"    -ErrorAction SilentlyContinue  | Out-Null
			New-Item -ItemType directory -Path "$InstallPath\lib"        -ErrorAction SilentlyContinue  | Out-Null
			
			Write-Host "  Copying files..."
			# executables
			Copy-Item "$GHDLBuildDir\ghdl.exe"            "$InstallPath\bin\ghdl.exe" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
			# include files
			Copy-Item "$GHDLRootDir\src\grt\vpi_user.h"   "$InstallPath\include"      -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
			# pre-compile scripts
			Copy-Item $GHDLVendorLibraryDir -Recurse      "$InstallPath\lib"          -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
			# pre-compiled libraries
			Copy-Item $GHDLCompiledLibraryDir  -Recurse   "$InstallPath"              -Verbose:$EnableVerbose -ErrorAction SilentlyContinue

			while($true)
			{	Write-Host "  Install GHDL in PATH at machine level? [" -NoNewline -ForegroundColor DarkCyan
				Write-Host "M" -NoNewline -ForegroundColor Cyan
				Write-Host "achine/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "u" -NoNewline -ForegroundColor Cyan
				Write-Host "ser/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "s" -NoNewline -ForegroundColor Cyan
				Write-Host "ession/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "p" -NoNewline -ForegroundColor Cyan
				Write-Host "ass]: " -NoNewline -ForegroundColor DarkCyan
				$InstallInPath = (Read-Host).ToLower()
				if ($InstallInPath -in "m","u","s","p")
				{	break	}
				else
				{	Write-Host "[ERROR]: Unsupported choice: '$InstallInPath'." -ForegroundColor Red    }
			}
			
			if (($InstallInPath -eq "") -or ($InstallInPath -eq "m"))
			{	Write-Host "  Adding GHDL to PATH at machine level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "Machine"
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
			elseif ($InstallInPath -eq "u")
			{	Write-Host "  Adding GHDL to PATH at user level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "User"
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
			elseif ($InstallInPath -eq "s")
			{	Write-Host "  Adding GHDL to PATH at session level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
			
			Write-Host
			Write-Host "Installing files " -NoNewline
			Write-Host "[SUCCESSFUL]" -ForegroundColor Green
			Write-Host
			
			Exit-Script
		}  # Zip
	}  # Install
	elseif ($Update)
	{	Write-Host "Updating GHDL $GHDLVersion for Windows..."
		if (Test-Path $InstallDirFile -PathType Leaf)
		{	Write-Host "  Reading installation path from '$InstallDirFile' ..."
			$InstallPath = Get-Content $InstallDirFile -Encoding Ascii
		}
		else
		{	if ($InstallDir -eq "")
			{	   }
			else
			{	$InstallPath = $InstallDir      }
		}
		$InstallPath = $InstallPath.TrimEnd("\")
		
		Write-Host "  Install directory: $InstallPath"
		if (Test-Path -Path $InstallPath)
		{	Write-Host "  Cleaning up installation directory '$InstallPath'." -ForegroundColor Yellow
			Get-ChildItem -Path $InstallPath -Depth 0 | foreach { Remove-Item $_.FullName -Recurse -Force }
		}
		
		
		Write-Host "  Creating directory sub-directories in '$InstallPath' ..."
		New-Item -ItemType directory -Path "$InstallPath\bin"        -ErrorAction SilentlyContinue  | Out-Null
		New-Item -ItemType directory -Path "$InstallPath\include"    -ErrorAction SilentlyContinue  | Out-Null
		New-Item -ItemType directory -Path "$InstallPath\lib"        -ErrorAction SilentlyContinue  | Out-Null
		
		Write-Host "  Copying files..."
		# executables
		Copy-Item "$GHDLBuildDir\ghdl.exe"            "$InstallPath\bin\ghdl.exe" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
		# include files
		Copy-Item "$GHDLRootDir\src\grt\vpi_user.h"   "$InstallPath\include"      -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
		# pre-compile scripts
		Copy-Item $GHDLVendorLibraryDir -Recurse      "$InstallPath\lib"          -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
		# pre-compiled libraries
		Copy-Item $GHDLCompiledLibraryDir  -Recurse   "$InstallPath"              -Verbose:$EnableVerbose -ErrorAction SilentlyContinue

		if ($AddToPath -eq "")
		{	while($true)
			{	Write-Host "  Install GHDL in PATH at machine level? [" -NoNewline -ForegroundColor DarkCyan
				Write-Host "M" -NoNewline -ForegroundColor Cyan
				Write-Host "achine/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "u" -NoNewline -ForegroundColor Cyan
				Write-Host "ser/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "s" -NoNewline -ForegroundColor Cyan
				Write-Host "ession/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "r" -NoNewline -ForegroundColor Cyan
				Write-Host "emove/" -NoNewline -ForegroundColor DarkCyan
				Write-Host "p" -NoNewline -ForegroundColor Cyan
				Write-Host "ass]: " -NoNewline -ForegroundColor DarkCyan
				$InstallInPath = (Read-Host).ToLower()
				if ($InstallInPath -in "m","u","s","r","p")
				{	break	}
				else
				{	Write-Host "[ERROR]: Unsupported choice: '$InstallInPath'." -ForegroundColor Red    }
			}
		}
		elseif ($AddToPath -eq "Machine")
		{	$InstallInPath = "m"     }
		elseif ($AddToPath -eq "User")
		{	$InstallInPath = "u"     }
		elseif ($AddToPath -eq "Session")
		{	$InstallInPath = "s"     }
		elseif ($AddToPath -eq "Remove")
		{	$InstallInPath = "r"     }
		elseif ($AddToPath -eq "Pass")
		{	$InstallInPath = "p"     }
	
		if ($InstallInPath -ne "p")
		{	Write-Host "  Removing GHDL from PATH variables in Machine, User, Session ..." -ForegroundColor Yellow
			foreach ($container in @("Machine", "User"))
			{	foreach ($entry in (Get-EnvPath -Container $container))
				{	if ($entry.ToLower().Contains("ghdl"))
					{	Write-Host "    Removing '$entry' from $container level."
						Remove-EnvPath -Path $entry -Container $container
					}
				}
			}
			Remove-EnvPath -Path $entry -Container "Session"
			
			if (($InstallInPath -eq "") -or ($InstallInPath -eq "m"))
			{	Write-Host "  Adding GHDL to PATH at machine level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "Machine"
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
			elseif ($InstallInPath -eq "u")
			{	Write-Host "  Adding GHDL to PATH at user level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "User"
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
			elseif ($InstallInPath -eq "s")
			{	Write-Host "  Adding GHDL to PATH at session level."
				Add-EnvPath -Path "$InstallPath\bin" -Container "Session"
			}
		}
		
		Write-Host
		Write-Host "Updating files " -NoNewline
		Write-Host "[SUCCESSFUL]" -ForegroundColor Green
		Write-Host
		
		Exit-Script
	}  # Update
	elseif ($Uninstall)
	{	Write-Host "Uninstalling GHDL $GHDLVersion for Windows..."
		if (Test-Path $InstallDirFile -PathType Leaf)
		{	Write-Host "  Reading installation path from '$InstallDirFile' ..."
			$InstallPath = Get-Content $InstallDirFile -Encoding Ascii
		}
		else
		{	$InstallPath = $DefaultInstallPath    }
		
		Write-Host "  Install directory: $InstallPath"
		if (Test-Path -Path $InstallPath)
		{	Write-Host "  Removing installation directory '$InstallPath'." -ForegroundColor Yellow
			Remove-Item $InstallPath -Recurse -Force -ErrorAction SilentlyContinue
		}
		
		Write-Host "  Removing GHDL from PATH variables in Machine, User, Session ..." -ForegroundColor Yellow
		foreach ($container in @("Machine", "User"))
		{	foreach ($entry in (Get-EnvPath -Container $container))
			{	if ($entry.ToLower().Contains("ghdl"))
				{	Write-Host "    Removing '$entry' from $container level."
					Remove-EnvPath -Path $entry -Container $container
				}
			}
		}
		Remove-EnvPath -Path $entry -Container "Session"

		Write-Host
		Write-Host "Uninstalling files " -NoNewline
		Write-Host "[SUCCESSFUL]" -ForegroundColor Green
		Write-Host
		
		Exit-Script
	}  # Uninstall
	
}  # Clean
	
Exit-Script