SConstruct 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import os
  2. import sys
  3. import rtconfig
  4. import platform
  5. import subprocess
  6. import uuid
  7. from rtconfig import RTT_ROOT
  8. import sys
  9. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  10. from building import *
  11. TARGET = 'rtthread.' + rtconfig.TARGET_EXT
  12. DefaultEnvironment(tools=[])
  13. env = Environment(tools = ['mingw'],
  14. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  15. CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
  16. CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
  17. AR = rtconfig.AR, ARFLAGS = '-rc',
  18. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  19. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  20. env['ASCOM'] = env['ASPPCOM']
  21. Export('RTT_ROOT')
  22. Export('rtconfig')
  23. rtconfig.CPU='c906'
  24. rtconfig.VENDOR="t-head"
  25. rtconfig.ARCH='risc-v'
  26. SDK_ROOT = os.path.abspath('../')
  27. if os.path.exists(SDK_ROOT + '/libraries'):
  28. libraries_path_prefix = SDK_ROOT + '/libraries'
  29. else:
  30. libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'
  31. SDK_LIB = libraries_path_prefix
  32. Export('SDK_LIB')
  33. # prepare building environment
  34. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  35. # set spawn
  36. def ourspawn(sh, escape, cmd, args, e):
  37. filename = str(uuid.uuid4())
  38. newargs = ' '.join(args[1:])
  39. cmdline = cmd + " " + newargs
  40. if (len(cmdline) > 16 * 1024):
  41. f = open(filename, 'w')
  42. f.write(' '.join(args[1:]).replace('\\', '/'))
  43. f.close()
  44. # exec
  45. cmdline = cmd + " @" + filename
  46. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  47. stderr=subprocess.PIPE, shell = False, env = e)
  48. data, err = proc.communicate()
  49. rv = proc.wait()
  50. def res_output(_output, _s):
  51. if len(_s):
  52. if isinstance(_s, str):
  53. _output(_s)
  54. elif isinstance(_s, bytes):
  55. _output(str(_s, 'UTF-8'))
  56. else:
  57. _output(str(_s))
  58. res_output(sys.stderr.write, err)
  59. res_output(sys.stdout.write, data)
  60. if os.path.isfile(filename):
  61. os.remove(filename)
  62. return rv
  63. if platform.system() == 'Windows':
  64. env['SPAWN'] = ourspawn
  65. hal_library = 'sunxi-hal'
  66. rtconfig.BSP_LIBRARY_TYPE = hal_library
  67. # include libraries
  68. objs.extend(SConscript(os.path.join(libraries_path_prefix, hal_library, 'SConscript'), variant_dir='build/libraries/sunxi-hal', duplicate=0))
  69. # include drivers
  70. objs.extend(SConscript(os.path.join(libraries_path_prefix, 'drivers', 'SConscript'), variant_dir='build/libraries/drivers', duplicate=0))
  71. # include libos
  72. objs.extend(SConscript(os.path.join(libraries_path_prefix, 'libos', 'SConscript'), variant_dir='build/libraries/libos', duplicate=0))
  73. if rtconfig.PLATFORM == 'gcc':
  74. env['LINKCOM'] = '$LINK -o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS -Wl,--start-group $_LIBFLAGS -Wl,--end-group'
  75. stack_size = 4096
  76. stack_lds = open('link_stacksize.lds', 'w')
  77. if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
  78. stack_lds.write('__STACKSIZE__ = %d;\n' % stack_size)
  79. stack_lds.close()
  80. # make a building
  81. DoBuilding(TARGET, objs)