make.ps1 2.9 KB

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