-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake.ps1
119 lines (113 loc) · 3.95 KB
/
make.ps1
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
#!/usr/bin/env pwsh
##############################################################################################################
Function Show-Usage {
"
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
Options:
build Build program
" | Out-Host
}
Function Request-File {
While ($Input.MoveNext()) {
$VAR = @{
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
}
$Env:Ext = '0'
$Env:Src = 'src'
$Env:Use = 'use'
$Env:Pkg = 'use\components.txt'
If (Test-Path -Path $Env:Use) {
If (Test-Path -Path $Env:Pkg) {
Get-Content -Path $Env:Pkg |
Where-Object {
! (Test-Path -Path "$($Env:Use)\$($_)") &&
! (& lazbuild --verbose-pkgsearch $_ ) &&
! (& lazbuild --add-package $_)
} | ForEach-Object {
Return @{
Uri = "https://packages.lazarus-ide.org/$($_).zip"
Path = "$($Env: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 $Env:Use).FullName |
ForEach-Object {
& lazbuild --add-package-link $_ | Out-Null
Return ".... [$($LastExitCode)] add package link $($_)"
} | Out-Host
}
(Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Env:Src).FullName |
Sort-Object |
ForEach-Object {
$Output = (& lazbuild --build-all --recursive --no-write-project --build-mode='release' $_)
$Result = @(".... [$($LastExitCode)] build project $($_)")
If ($LastExitCode -eq 0) {
$Result += $Output | Select-String -Pattern 'Linking'
} Else {
$Env:Ext = [Int]$Env:Ext + 1
$Result += $Output | Select-String -Pattern 'Error:', 'Fatal:'
}
$Result | Out-Host
}
Exit [Int]$Env:Ext
}
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 | Out-Null