SConstruct 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import os
  2. import sys
  3. import rtconfig
  4. import subprocess
  5. IS_EXPORTED = False
  6. # setup RT-Thread Root Path
  7. if os.getenv('RTT_ROOT'):
  8. RTT_ROOT = os.getenv('RTT_ROOT')
  9. else:
  10. RTT_ROOT = os.getcwd() + '/../../..'
  11. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  12. try:
  13. from building import *
  14. except:
  15. print('Cannot found RT-Thread root directory, please check RTT_ROOT')
  16. print(RTT_ROOT)
  17. exit(-1)
  18. if RTT_ROOT == 'rt-thread':
  19. IS_EXPORTED = True # if kenrel and bsp has been exported by export_project.py
  20. # setup Phytium BSP Root Path
  21. if IS_EXPORTED:
  22. BSP_ROOT = '.'
  23. else:
  24. BSP_ROOT = RTT_ROOT + '/bsp/phytium'
  25. TARGET = 'rtthread_a64.' + rtconfig.TARGET_EXT
  26. DefaultEnvironment(tools=[])
  27. env = Environment(tools = ['mingw'],
  28. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  29. CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
  30. CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
  31. AR = rtconfig.AR, ARFLAGS = '-rc',
  32. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  33. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  34. env['ASCOM'] = env['ASPPCOM']
  35. Export('RTT_ROOT')
  36. Export('BSP_ROOT')
  37. Export('rtconfig')
  38. def is_phytium_sdk_installed():
  39. py_target_folder = os.getcwd() + "/../libraries/phytium_standalone_sdk"
  40. return os.path.exists(py_target_folder)
  41. def install_phytium_sdk():
  42. if is_phytium_sdk_installed():
  43. return 0
  44. print("Checking for the presence of phytium_standalone_sdk_install.py script...")
  45. sconstruct_dir = os.getcwd()
  46. install_script_path = os.path.join(sconstruct_dir, "phytium_standalone_sdk_install.py")
  47. if os.path.exists(install_script_path):
  48. subprocess.call(["rm","-rf", install_script_path])
  49. try:
  50. subprocess.call(["wget", "https://gitee.com/phytium_embedded/phytium-standalone-sdk/raw/Standalone-Sdk_RT-thread/phytium_standalone_sdk_install.py"])
  51. except:
  52. print("Please refer to the ./README and manual download phytium_standalone_sdk_install.py, place in current folder")
  53. if os.path.exists(install_script_path):
  54. try:
  55. subprocess.call(["python", install_script_path])
  56. except:
  57. subprocess.call(["python3", install_script_path])
  58. if not is_phytium_sdk_installed():
  59. print("Error: phytium_standalone_sdk install failed")
  60. exit(0)
  61. else:
  62. print("Error: phytium_standalone_sdk_install.py is not exists, exit compilation")
  63. exit(0)
  64. install_phytium_sdk()
  65. # prepare building environment
  66. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  67. if not IS_EXPORTED: # if project is not exported, libraries and board need to manually add
  68. # include libraries
  69. objs.extend(SConscript(os.path.join(BSP_ROOT + '/libraries', 'SConscript')))
  70. # include board
  71. objs.extend(SConscript(os.path.join(BSP_ROOT + '/board', 'SConscript')))
  72. # make a building
  73. DoBuilding(TARGET, objs)