SConstruct 2.6 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_a32.' + 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. os.environ["BSP_ROOT"] = BSP_ROOT
  36. os.environ["SDK_DIR"] = os.path.join(BSP_ROOT,'libraries','phytium_standalone_sdk')
  37. Export('RTT_ROOT')
  38. Export('BSP_ROOT')
  39. Export('rtconfig')
  40. def is_phytium_sdk_installed():
  41. py_target_folder = os.getcwd() + "/../libraries/phytium_standalone_sdk"
  42. return os.path.exists(py_target_folder)
  43. def install_phytium_sdk():
  44. if is_phytium_sdk_installed():
  45. return 0
  46. install_script_path = os.getcwd() + "/../libraries/phytium_standalone_sdk_install.py"
  47. if os.path.exists(install_script_path):
  48. try:
  49. subprocess.call(["python", install_script_path])
  50. except:
  51. subprocess.call(["python3", install_script_path])
  52. if not is_phytium_sdk_installed():
  53. print("Error: phytium_standalone_sdk install failed")
  54. exit(0)
  55. else:
  56. print("Error: phytium_standalone_sdk_install.py is not exists, exit compilation")
  57. exit(0)
  58. install_phytium_sdk()
  59. # prepare building environment
  60. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  61. if not IS_EXPORTED: # if project is not exported, libraries and board need to manually add
  62. # include libraries
  63. objs.extend(SConscript(os.path.join(BSP_ROOT + '/libraries', 'SConscript')))
  64. # include board
  65. objs.extend(SConscript(os.path.join(BSP_ROOT + '/board', 'SConscript')))
  66. if GetDepend('RT_USING_SMART'):
  67. # use smart link.lds
  68. env['LINKFLAGS'] = env['LINKFLAGS'].replace('link.lds', 'link_smart.lds')
  69. # make a building
  70. DoBuilding(TARGET, objs)