SConstruct 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. 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. try:
  48. subprocess.call(["wget", "https://gitee.com/phytium_embedded/phytium-standalone-sdk/raw/Standalone-Sdk_RT-thread/phytium_standalone_sdk_install.py"])
  49. except:
  50. print("Please refer to the ./README and manual download phytium_standalone_sdk_install.py, place in current folder")
  51. if os.path.exists(install_script_path):
  52. try:
  53. subprocess.call(["python", install_script_path])
  54. except:
  55. subprocess.call(["python3", install_script_path])
  56. if not is_phytium_sdk_installed():
  57. print("Error: phytium_standalone_sdk install failed")
  58. exit(0)
  59. else:
  60. print("Error: phytium_standalone_sdk_install.py is not exists, exit compilation")
  61. exit(0)
  62. install_phytium_sdk()
  63. # prepare building environment
  64. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  65. if not IS_EXPORTED: # if project is not exported, libraries and board need to manually add
  66. # include libraries
  67. objs.extend(SConscript(os.path.join(BSP_ROOT + '/libraries', 'SConscript')))
  68. # include board
  69. objs.extend(SConscript(os.path.join(BSP_ROOT + '/board', 'SConscript')))
  70. if GetDepend('RT_USING_SMART'):
  71. # use smart link.lds
  72. env['LINKFLAGS'] = env['LINKFLAGS'].replace('link.lds', 'link_smart.lds')
  73. # make a building
  74. DoBuilding(TARGET, objs)