SConstruct 2.5 KB

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