make.ps1 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\components.txt' ) {
  47. & git submodule update --recursive --init | Out-Host
  48. & git submodule update --recursive --remote | Out-Host
  49. Get-Content -Path 'use\components.txt' | ForEach-Object {
  50. If ((! (& lazbuild --verbose-pkgsearch $_)) &&
  51. (! (& lazbuild --add-package $_)) &&
  52. (! (Test-Path -Path "use\$($_)"))) {
  53. $OutFile = Request-File "https://packages.lazarus-ide.org/$($_).zip"
  54. Expand-Archive -Path $OutFile -DestinationPath "use\$($_)" -Force
  55. Remove-Item $OutFile
  56. }
  57. }
  58. Get-ChildItem -Filter '*.lpk' -Recurse -File –Path 'use' | ForEach-Object {
  59. & lazbuild --add-package-link $_ | Out-Host
  60. }
  61. }
  62. Get-ChildItem -Filter '*.lpi' -Recurse -File –Path 'src' | ForEach-Object {
  63. & lazbuild --no-write-project --recursive --build-mode=release $_ | Out-Host
  64. }
  65. }
  66. Function Switch-Action {
  67. $ErrorActionPreference = 'stop'
  68. Set-PSDebug -Strict -Trace 1
  69. Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath
  70. If ($args.count -gt 0) {
  71. Switch ($args[0]) {
  72. 'build' {
  73. Build-Project
  74. }
  75. Default {
  76. Show-Usage
  77. }
  78. }
  79. } Else {
  80. Show-Usage
  81. }
  82. }
  83. ##############################################################################################################
  84. Switch-Action @args