|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +############################################################################################################## |
| 3 | + |
| 4 | +Function Show-Usage { |
| 5 | + Return " |
| 6 | +Usage: pwsh -File $($PSCommandPath) [OPTIONS] |
| 7 | +Options: |
| 8 | + build Build program |
| 9 | +" |
| 10 | +} |
| 11 | + |
| 12 | +Function Request-File { |
| 13 | + ForEach ($REPLY in $args) { |
| 14 | + $params = @{ |
| 15 | + Uri = $REPLY |
| 16 | + OutFile = (Split-Path -Path $REPLY -Leaf).Split('?')[0] |
| 17 | + } |
| 18 | + Invoke-WebRequest @params | Out-Null |
| 19 | + Return $params.OutFile |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +Function Install-Program { |
| 24 | + While ($Input.MoveNext()) { |
| 25 | + Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) { |
| 26 | + 'msi' { |
| 27 | + & msiexec /passive /package $Input.Current | Out-Host |
| 28 | + } |
| 29 | + 'exe' { |
| 30 | + & ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Host |
| 31 | + } |
| 32 | + } |
| 33 | + Remove-Item $Input.Current |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +Function Build-Project { |
| 38 | + $VAR = @{ |
| 39 | + Cmd = 'lazbuild' |
| 40 | + Url = 'https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Windows%2064%20bits/Lazarus%203.6/lazarus-3.6-fpc-3.2.2-win64.exe?viasf=1' |
| 41 | + Path = "C:\Lazarus" |
| 42 | + } |
| 43 | + Try { |
| 44 | + Get-Command $VAR.Cmd |
| 45 | + } Catch { |
| 46 | + Request-File $VAR.Url | Install-Program |
| 47 | + $env:PATH+=";$($VAR.Path)" |
| 48 | + Get-Command $VAR.Cmd |
| 49 | + } |
| 50 | + If ( Test-Path -Path 'use\components.txt' ) { |
| 51 | + & git submodule update --recursive --init | Out-Host |
| 52 | + & git submodule update --recursive --remote | Out-Host |
| 53 | + Get-Content -Path 'use\components.txt' | ForEach-Object { |
| 54 | + If ((-not (& lazbuild --verbose-pkgsearch $_ | Out-Null)) -and |
| 55 | + (-not (& lazbuild --add-package $_ | Out-Null)) -and |
| 56 | + (-not (Test-Path -Path 'use\components.txt'))) { |
| 57 | + $OutFile = Request-File "https://packages.lazarus-ide.org/$($_).zip" |
| 58 | + Expand-Archive -Path $OutFile -DestinationPath "use\$($_)" -Force |
| 59 | + Remove-Item $OutFile |
| 60 | + } |
| 61 | + } |
| 62 | + Get-ChildItem -Filter '*.lpk' -Recurse -File –Path 'use' | ForEach-Object { |
| 63 | + & lazbuild --add-package-link $_ | Out-Host |
| 64 | + } |
| 65 | + } |
| 66 | + Get-ChildItem -Filter '*.lpi' -Recurse -File –Path 'src' | ForEach-Object { |
| 67 | + & lazbuild --no-write-project --recursive --build-mode=release $_ | Out-Host |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +Function Switch-Action { |
| 72 | + $ErrorActionPreference = 'stop' |
| 73 | + Set-PSDebug -Strict -Trace 1 |
| 74 | + Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath |
| 75 | + If ($args.count -gt 0) { |
| 76 | + Switch ($args[0]) { |
| 77 | + 'build' { |
| 78 | + Build-Project |
| 79 | + } |
| 80 | + Default { |
| 81 | + Show-Usage |
| 82 | + } |
| 83 | + } |
| 84 | + } Else { |
| 85 | + Show-Usage |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +############################################################################################################## |
| 90 | +Switch-Action @args | Out-Null |
0 commit comments