SConstruct 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.path.join(os.getcwd(),'..','..','..')
  11. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  12. try:
  13. from building import *
  14. except Exception as e:
  15. print('Cannot found RT-Thread root directory, please check RTT_ROOT')
  16. exit(-1)
  17. if RTT_ROOT == 'rt-thread':
  18. IS_EXPORTED = True # if kenrel and bsp has been exported by export_project.py
  19. # setup Phytium BSP Root Path
  20. if IS_EXPORTED:
  21. BSP_ROOT = '.'
  22. else:
  23. BSP_ROOT = os.path.join(RTT_ROOT ,'bsp','phytium')
  24. TARGET = 'rtthread_a64.' + rtconfig.TARGET_EXT
  25. DefaultEnvironment(tools=[])
  26. env = Environment(tools = ['mingw'],
  27. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  28. CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
  29. CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
  30. AR = rtconfig.AR, ARFLAGS = '-rc',
  31. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  32. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  33. env['ASCOM'] = env['ASPPCOM']
  34. os.environ["BSP_ROOT"] = BSP_ROOT
  35. os.environ["SDK_DIR"] = os.path.join(BSP_ROOT,'libraries','phytium_standalone_sdk')
  36. Export('RTT_ROOT')
  37. Export('BSP_ROOT')
  38. Export('rtconfig')
  39. def is_phytium_sdk_installed():
  40. py_target_folder = os.path.join(BSP_ROOT,"libraries","phytium_standalone_sdk")
  41. return os.path.exists(py_target_folder)
  42. def install_phytium_sdk():
  43. if is_phytium_sdk_installed():
  44. return 0
  45. install_script_path = os.path.join(BSP_ROOT,"libraries","phytium_standalone_sdk_install.py")
  46. if os.path.exists(install_script_path):
  47. try:
  48. subprocess.call(["python", install_script_path])
  49. except:
  50. subprocess.call(["python3", install_script_path])
  51. if not is_phytium_sdk_installed():
  52. print("Error: phytium_standalone_sdk install failed")
  53. exit(0)
  54. else:
  55. print("Error: phytium_standalone_sdk_install.py is not exists, exit compilation")
  56. exit(0)
  57. install_phytium_sdk()
  58. # prepare building environment
  59. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  60. if not IS_EXPORTED: # if project is not exported, libraries and board need to manually add
  61. # include libraries
  62. objs.extend(SConscript(os.path.join(BSP_ROOT,'libraries','SConscript')))
  63. # include board
  64. objs.extend(SConscript(os.path.join(BSP_ROOT,'board','SConscript')))
  65. # make a building
  66. DoBuilding(TARGET, objs)