SConstruct 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import os
  2. import sys
  3. import rtconfig
  4. import platform
  5. import subprocess
  6. import uuid
  7. if os.path.exists('rt-thread'):
  8. RTT_ROOT = os.path.normpath(os.getcwd() + '/rt-thread')
  9. else:
  10. RTT_ROOT = os.path.normpath(os.getcwd() + '../../../../rt-thread')
  11. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  12. try:
  13. from building import *
  14. except Exception as e:
  15. print("Error message:", e.message)
  16. print('Cannot found RT-Thread root directory, please check RTT_ROOT')
  17. print(RTT_ROOT)
  18. sys.exit(-1)
  19. TARGET = 'rtthread.' + rtconfig.TARGET_EXT
  20. DefaultEnvironment(tools=[])
  21. env = Environment(tools = ['mingw'],
  22. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  23. CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
  24. CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
  25. AR = rtconfig.AR, ARFLAGS = '-rc',
  26. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  27. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  28. if rtconfig.PLATFORM in ['iccarm']:
  29. env.Replace(CCCOM = ['$CC $CFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
  30. env.Replace(ARFLAGS = [''])
  31. env.Replace(LINKCOM = env["LINKCOM"] + ' --map project.map')
  32. Export('RTT_ROOT')
  33. Export('rtconfig')
  34. SDK_ROOT = os.path.abspath('./')
  35. if os.path.exists(SDK_ROOT + '/libraries'):
  36. libraries_path_prefix = SDK_ROOT + '/libraries'
  37. else:
  38. libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/../../libraries'
  39. SDK_LIB = libraries_path_prefix
  40. Export('SDK_LIB')
  41. rtconfig.BSP_LIBRARY_TYPE = None
  42. # prepare building environment
  43. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
  44. # set spawn
  45. def ourspawn(sh, escape, cmd, args, e):
  46. filename = str(uuid.uuid4())
  47. newargs = ' '.join(args[1:])
  48. cmdline = cmd + " " + newargs
  49. if (len(cmdline) > 16 * 1024):
  50. f = open(filename, 'w')
  51. f.write(' '.join(args[1:]).replace('\\', '/'))
  52. f.close()
  53. # exec
  54. cmdline = cmd + " @" + filename
  55. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  56. stderr=subprocess.PIPE, shell = False, env = e)
  57. data, err = proc.communicate()
  58. rv = proc.wait()
  59. def res_output(_output, _s):
  60. if len(_s):
  61. if isinstance(_s, str):
  62. _output(_s)
  63. elif isinstance(_s, bytes):
  64. _output(str(_s, 'UTF-8'))
  65. else:
  66. _output(str(_s))
  67. res_output(sys.stderr.write, err)
  68. res_output(sys.stdout.write, data)
  69. if os.path.isfile(filename):
  70. os.remove(filename)
  71. return rv
  72. # 解决env-scons不能链接长路径问题
  73. if platform.system() == 'Windows':
  74. env['SPAWN'] = ourspawn
  75. if os.path.exists(os.path.join(os.getcwd(), "libraries")):
  76. # tinyusb package
  77. objs.extend(SConscript(os.path.join('libraries/components/tinyusb', '', 'SConscript')))
  78. else:
  79. # tinyusb package
  80. objs.extend(SConscript(os.path.join('../../../libraries/components/tinyusb', '', 'SConscript')))
  81. # include drivers
  82. objs.extend(SConscript(os.path.join(libraries_path_prefix, 'HAL_Drivers', 'SConscript')))
  83. # make a building
  84. DoBuilding(TARGET, objs)