build_as_lib.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from os.path import realpath
  2. Import("env") # type: ignore
  3. menv=env # type: ignore
  4. src_filter = [
  5. '+<*.cpp>',
  6. '+<helpers/*.cpp>',
  7. '+<helpers/sensors>',
  8. '+<helpers/radiolib/*.cpp>',
  9. '+<helpers/ui/MomentaryButton.cpp>',
  10. '+<helpers/ui/buzzer.cpp>',
  11. ]
  12. # add build and include dirs according to CPPDEFINES
  13. for item in menv.get("CPPDEFINES", []):
  14. # PLATFORM HANDLING
  15. if item == "STM32_PLATFORM":
  16. src_filter.append("+<helpers/stm32/*>")
  17. elif item == "ESP32":
  18. src_filter.append("+<helpers/esp32/*>")
  19. elif item == "NRF52_PLATFORM":
  20. src_filter.append("+<helpers/nrf52/*>")
  21. elif item == "RP2040_PLATFORM":
  22. src_filter.append("+<helpers/rp2040/*>")
  23. # DISPLAY HANDLING
  24. elif isinstance(item, tuple) and item[0] == "DISPLAY_CLASS":
  25. display_class = item[1]
  26. src_filter.append(f"+<helpers/ui/{display_class}.cpp>")
  27. if (display_class == "ST7789Display") :
  28. src_filter.append(f"+<helpers/ui/OLEDDisplay.cpp>")
  29. src_filter.append(f"+<helpers/ui/OLEDDisplayFonts.cpp>")
  30. # VARIANTS HANDLING
  31. elif isinstance(item, tuple) and item[0] == "MC_VARIANT":
  32. variant_name = item[1]
  33. src_filter.append(f"+<../variants/{variant_name}>")
  34. # INCLUDE EXAMPLE CODE IN BUILD (to provide your own support files without touching the tree)
  35. elif isinstance(item, tuple) and item[0] == "BUILD_EXAMPLE":
  36. example_name = item[1]
  37. src_filter.append(f"+<../examples/{example_name}/*.cpp>")
  38. # EXCLUDE A SOURCE FILE FROM AN EXAMPLE (must be placed after example name or boom)
  39. elif isinstance(item, tuple) and item[0] == "EXCLUDE_FROM_EXAMPLE":
  40. exclude_name = item[1]
  41. if example_name is None:
  42. print("***** PLEASE DEFINE EXAMPLE FIRST *****")
  43. break
  44. src_filter.append(f"-<../examples/{example_name}/{exclude_name}>")
  45. # DEAL WITH UI VARIANT FOR AN EXAMPLE
  46. elif isinstance(item, tuple) and item[0] == "MC_UI_FLAVOR":
  47. ui_flavor = item[1]
  48. if example_name is None:
  49. print("***** PLEASE DEFINE EXAMPLE FIRST *****")
  50. break
  51. src_filter.append(f"+<../examples/{example_name}/{ui_flavor}/*.cpp>")
  52. menv.Replace(SRC_FILTER=src_filter)
  53. #print (menv.Dump())