SConstruct 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import sys
  3. import rtconfig
  4. import platform
  5. import subprocess
  6. from rtconfig import RTT_ROOT
  7. import sys
  8. def generate_ldscript(input, output):
  9. if not os.path.exists(input):
  10. print('Error: file', input, 'not found')
  11. return
  12. if os.path.exists(output):
  13. os.remove(output)
  14. if rtconfig.PLATFORM == 'gcc':
  15. gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
  16. # gcc -E -P -x c $input -o $output
  17. if (platform.system() == 'Windows'):
  18. child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  19. else:
  20. child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  21. child.communicate()
  22. print(output, 'is generated from', input)
  23. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  24. from building import *
  25. TARGET = 'rtthread.' + rtconfig.TARGET_EXT
  26. DefaultEnvironment(tools=[])
  27. env = Environment(tools = ['mingw'],
  28. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  29. CC = rtconfig.CC, CCFLAGS = 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('rtconfig')
  37. # prepare building environment
  38. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
  39. generate_ldscript('link.lds', 'link.lds.generated')
  40. # make a building
  41. DoBuilding(TARGET, objs)
  42. Clean(TARGET, 'link.lds.generated')
  43. Clean(TARGET, 'build')