simulator.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #
  2. # simulator.py
  3. # PlatformIO pre: script for simulator builds
  4. #
  5. import pioutil
  6. if pioutil.is_pio_build():
  7. # Get the environment thus far for the build
  8. env = pioutil.env
  9. #print(env.Dump())
  10. #
  11. # Give the binary a distinctive name
  12. #
  13. env['PROGNAME'] = "MarlinSimulator"
  14. #
  15. # Check for a valid GCC and available OpenGL on macOS
  16. #
  17. emsg = ''
  18. fatal = 0
  19. import sys
  20. if sys.platform == 'darwin':
  21. import shutil
  22. gcc = shutil.which('gcc')
  23. if gcc == '' or gcc == '/usr/bin/gcc':
  24. if gcc == '':
  25. emsg = "\u001b[31mNo GCC found in your configured shell PATH."
  26. elif gcc == '/usr/bin/gcc':
  27. emsg = "\u001b[31mCan't build Marlin Native on macOS using the included version of GCC (clang)."
  28. emsg += "\n\u001b[31mSee 'native.ini' for instructions to install GCC with MacPorts or Homebrew."
  29. fatal = 1
  30. else:
  31. #
  32. # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS')
  33. #
  34. env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ]
  35. # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa
  36. xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
  37. mesa_path = "/opt/local/include/GL/gl.h"
  38. import os.path
  39. if os.path.exists(xcode_path):
  40. env['BUILD_FLAGS'] += [ "-F" + xcode_path ]
  41. emsg = "\u001b[33mUsing OpenGL framework headers from Xcode.app"
  42. elif os.path.exists(mesa_path):
  43. env['BUILD_FLAGS'] += [ '-D__MESA__' ]
  44. emsg = f"\u001b[33mUsing OpenGL header from {mesa_path}"
  45. else:
  46. emsg = "\u001b[31mNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h."
  47. fatal = 1
  48. # Print error message, if any
  49. if emsg: print(f"\n\n{emsg}\n\n")
  50. # Break out of the PIO build immediately
  51. if fatal: sys.exit(1)