-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.ps1
More file actions
128 lines (122 loc) · 4.32 KB
/
make.ps1
File metadata and controls
128 lines (122 loc) · 4.32 KB
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
#!/usr/bin/env pwsh
##############################################################################################################
Function Show-Usage {
"
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
Options:
build Build program
" | Out-Host
}
Function Request-File {
While ($Input.MoveNext()) {
New-Variable -Name VAR -Option Constant -Value @{
Uri = $Input.Current
OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0]
}
Invoke-WebRequest @VAR
Return $VAR.OutFile
}
}
Function Install-Program {
While ($Input.MoveNext()) {
Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) {
'msi' {
& msiexec /passive /package $Input.Current | Out-Null
}
Default {
& ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null
}
}
Remove-Item $Input.Current
}
}
Function Build-Project {
@(
@{
Cmd = 'lazbuild'
Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe'
Path = "C:\Lazarus"
}
) | Where-Object { ! (Test-Path -Path $_.Path) } |
ForEach-Object {
$_.Url | Request-File | Install-Program
$Env:PATH+=";$($_.Path)"
(Get-Command $_.Cmd).Source | Out-Host
}
If (Test-Path -Path '.gitmodules') {
& git submodule update --init --recursive --force --remote | Out-Host
".... [[$($LastExitCode)]] git submodule update" | Out-Host
}
New-Variable -Name VAR -Option Constant -Value @{
Src = 'src'
Use = 'use'
Pkg = 'use\components.txt'
}
If (Test-Path -Path $VAR.Use) {
If (Test-Path -Path $VAR.Pkg) {
Get-Content -Path $VAR.Pkg |
Where-Object {
! (Test-Path -Path "$($VAR.Use)\$($_)") &&
! (& lazbuild --verbose-pkgsearch $_ ) &&
! (& lazbuild --add-package $_)
} | ForEach-Object {
Return @{
Uri = "https://packages.lazarus-ide.org/$($_).zip"
Path = "$($VAR.Use)\$($_)"
OutFile = (New-TemporaryFile).FullName
}
} | ForEach-Object -Parallel {
Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri
Expand-Archive -Path $_.OutFile -DestinationPath $_.Path
Remove-Item $_.OutFile
Return ".... download $($_.Uri)"
} | Out-Host
}
(Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName |
ForEach-Object {
& lazbuild --add-package-link $_ | Out-Null
Return ".... [$($LastExitCode)] add package link $($_)"
} | Out-Host
}
If (Test-Path -Path $Var.Src) {
Exit (
(Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName |
Sort-Object |
ForEach-Object {
$Output = (& lazbuild --build-all --recursive --no-write-project --build-mode='release' $_)
$Result = @(".... [$($LastExitCode)] build project $($_)")
$exitCode = Switch ($LastExitCode) {
0 {
$Result += $Output | Select-String -Pattern 'Linking'
0
}
Default {
$Result += $Output | Select-String -Pattern 'Error:', 'Fatal:'
1
}
}
$Result | Out-Host
Return $exitCode
} | Measure-Object -Sum
).Sum
}
}
Function Switch-Action {
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict #-Trace 1
Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath
If ($args.count -gt 0) {
Switch ($args[0]) {
'build' {
Build-Project
}
Default {
Show-Usage
}
}
} Else {
Show-Usage
}
}
##############################################################################################################
Switch-Action @args