fbt.ps1 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Push-Location $PSScriptRoot
  2. $firmware_path = ""
  3. $firmware_name = ""
  4. $FW_CDEF = ""
  5. if (('official-dev', 'off-dev', 'od').Contains($args[0])) {
  6. $firmware_path = "flipperzero-firmware_official_dev"
  7. $firmware_name = "Official Dev"
  8. $FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_DEV"
  9. }
  10. elseif (('official-stable', 'off-stbl', 'os').Contains($args[0])) {
  11. $firmware_path = "flipperzero-firmware_official_stable"
  12. $firmware_name = "Official Stable"
  13. $FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_STABLE"
  14. } elseif (('xtreme', 'xt', 'x', 'unleashed', 'un', 'u').Contains($args[0])) {
  15. $firmware_path = "flipperzero-firmware_xtreme"
  16. $firmware_name = "Xtreme \ Unleashed"
  17. $FW_CDEF = "TOTP_FIRMWARE_XTREME_UL"
  18. }
  19. else {
  20. throw "Unable to recognize which firmware to use"
  21. }
  22. Write-Host "Using $firmware_name firmware to run FBT"
  23. $commandline_scons = "$firmware_path/site_scons/commandline.scons"
  24. ((Get-Content -Path $commandline_scons -Raw) -replace 'applications_user','..') | Set-Content -Path $commandline_scons -NoNewline
  25. $i = 1
  26. $args_ls = @()
  27. $cpp_defines = @("(`"TOTP_TARGET_FIRMWARE`", `"$FW_CDEF`")")
  28. while ($i -lt $args.Count) {
  29. if ($args[$i] -eq '-D') {
  30. $define = $args[$i + 1].Split('=')
  31. if ($define.Length -gt 1) {
  32. $cpp_defines += "(`"$($define[0])`", `"$($define[1])`")"
  33. } else {
  34. $cpp_defines += "`"$($define[0])`""
  35. }
  36. $i = $i + 2
  37. } elseif ($args[$i] -eq '--clean') {
  38. $build_path = "$firmware_path/build"
  39. if (Test-Path -PathType Container $build_path) {
  40. Remove-Item "$build_path/*" -Recurse -Force
  41. }
  42. $i = $i + 1
  43. } else {
  44. $args_ls += $args[$i]
  45. $i = $i + 1
  46. }
  47. }
  48. if ($cpp_defines.Length -gt 0) {
  49. $cc_scons = "$firmware_path/site_scons/cc.scons"
  50. (Get-Content -Path $cc_scons -Raw) -replace "(CPPDEFINES\s*=\s*\[)(([^]]\r?\n?)*)(\])", "`$1`"_GNU_SOURCE`", $($cpp_defines -join ", ")`$4" | Set-Content -Path $cc_scons -NoNewline
  51. }
  52. $builtin_totp_path = "$firmware_path/applications/external/totp"
  53. if ((Test-Path -Path $builtin_totp_path) -eq $True) {
  54. Remove-Item $builtin_totp_path -Recurse
  55. }
  56. Push-Location $firmware_path
  57. ./fbt $args_ls
  58. Pop-Location
  59. Pop-Location