-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
make.ps1
105 lines (99 loc) · 3.34 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
#!/usr/bin/env pwsh
##############################################################################################################
Function Show-Usage {
Return "
Usage: pwsh -File $($PSCommandPath) [OPTIONS]
Options:
build Build program
"
}
Function Request-File {
ForEach ($REPLY in $args) {
$params = @{
Uri = $REPLY
OutFile = (Split-Path -Path $REPLY -Leaf).Split('?')[0]
}
Invoke-WebRequest @params | Out-Null
Return $params.OutFile
}
}
Function Install-Program {
While ($Input.MoveNext()) {
Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) {
'msi' {
& msiexec /passive /package $Input.Current | Out-Host
}
'exe' {
& ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Host
}
}
Remove-Item $Input.Current
}
}
Function Build-Project {
$VAR = @{
Use = 'use'
Cmd = 'lazbuild'
Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe'
Path = "C:\Lazarus"
}
Try {
Get-Command $VAR.Cmd
} Catch {
"Install $($VAR.Path)" | Out-Host
Request-File $VAR.Url | Install-Program
$env:PATH+=";$($VAR.Path)"
Get-Command $VAR.Cmd
}
If (Test-Path -Path $($VAR.Use)) {
& git submodule update --init --recursive --force --remote | Out-Host
$COMPONENTS = "$($VAR.Use)\components.txt"
If (Test-Path -Path $COMPONENTS) {
'Download packages:' | Out-Host
Get-Content -Path $COMPONENTS | ForEach-Object {
If ((! (& $VAR.Cmd --verbose-pkgsearch $_ )) &&
(! (& $VAR.Cmd --add-package $_)) &&
(! (Test-Path -Path "$($VAR.Use)\$($_)"))) {
" download package $($_)" | Out-Host
$OutFile = Request-File "https://packages.lazarus-ide.org/$($_).zip"
Expand-Archive -Path $OutFile -DestinationPath "$($VAR.Use)\$($_)" -Force
Remove-Item $OutFile
}
}
}
'Add dependencies:' | Out-Host
Get-ChildItem -Filter '*.lpk' -Recurse -File –Path 'use'| Sort-Object | ForEach-Object {
" add dependence $($_)" | Out-Host
& $VAR.Cmd --add-package-link $_ | Out-Host
}
}
'Build projects:' | Out-Host
Get-ChildItem -Filter '*.lpi' -Recurse -File –Path 'peazip-sources'| Sort-Object | ForEach-Object {
" build project $($_)" | Out-Host
If (! (& $VAR.Cmd --no-write-project --recursive $_)) {
& $VAR.Cmd --no-write-project --recursive $_ | Out-Host
$exitCode = $LastExitCode
Throw $exitCode
}
}
"Done!" | Out-Host
}
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