fbt.ps1 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. Push-Location $PSScriptRoot
  2. $firmware_path = ""
  3. $firmware_name = ""
  4. $FW_CDEF = ""
  5. if (('official-dev', 'off-dev', 'od', 'unleashed', 'un', 'u').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').Contains($args[0])) {
  15. $firmware_path = "flipperzero-firmware_xtreme"
  16. $firmware_name = "Xtreme"
  17. $FW_CDEF = "TOTP_FIRMWARE_XTREME"
  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. } else {
  38. $args_ls += $args[$i]
  39. $i = $i + 1
  40. }
  41. }
  42. if ($cpp_defines.Length -gt 0) {
  43. $cc_scons = "$firmware_path\site_scons\cc.scons"
  44. (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
  45. }
  46. $builtin_totp_path = "$firmware_path\applications\external\totp"
  47. if ((Test-Path -Path $builtin_totp_path) -eq $True) {
  48. Remove-Item $builtin_totp_path -Recurse
  49. }
  50. Push-Location $firmware_path
  51. ./fbt $args_ls
  52. Pop-Location
  53. Pop-Location