SConstruct 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import os
  2. import sys
  3. import rtconfig
  4. if os.getenv('RTT_ROOT'):
  5. RTT_ROOT = os.getenv('RTT_ROOT')
  6. else:
  7. RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
  8. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  9. from building import *
  10. env = Environment(TARGET_ARCH='x86')
  11. Export('RTT_ROOT')
  12. Export('rtconfig')
  13. if rtconfig.PLATFORM == 'cl':
  14. TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
  15. libs = Split('''
  16. winmm
  17. gdi32
  18. winspool
  19. comdlg32
  20. advapi32
  21. shell32
  22. ole32
  23. oleaut32
  24. uuid
  25. odbc32
  26. odbccp32
  27. ''')
  28. definitions = Split('''
  29. WIN32
  30. _DEBUG
  31. _CONSOLE
  32. MSVC
  33. ''')
  34. env.Append(CCFLAGS=rtconfig.CFLAGS)
  35. env.Append(LINKFLAGS=rtconfig.LFLAGS)
  36. env['LIBS']=libs
  37. env['CPPDEFINES']=definitions
  38. elif rtconfig.PLATFORM == 'mingw':
  39. libs = Split('''
  40. winmm
  41. gdi32
  42. winspool
  43. comdlg32
  44. advapi32
  45. shell32
  46. ole32
  47. oleaut32
  48. uuid
  49. odbc32
  50. odbccp32
  51. ''')
  52. TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
  53. DefaultEnvironment(tools=[])
  54. env = Environment(tools = ['mingw'],
  55. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  56. CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
  57. AR = rtconfig.AR, ARFLAGS = '-rc',
  58. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  59. env['LIBS']=libs
  60. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  61. elif rtconfig.CROSS_TOOL == 'clang-analyze':
  62. TARGET = 'rtthread'
  63. env = Environment(toolpath=[os.path.join(RTT_ROOT, 'tools', 'tools')],
  64. tools = [rtconfig.CROSS_TOOL])
  65. else:
  66. TARGET = 'rtthread'
  67. env['CC']=rtconfig.CC
  68. env.Append(CCFLAGS=rtconfig.CFLAGS)
  69. env.Append(LINKFLAGS=rtconfig.LFLAGS)
  70. env.Append(LIBS=['winmm'])
  71. # prepare building environment
  72. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
  73. def ObjRemove(objs, remove):
  74. for item in objs:
  75. # print(type(item), os.path.basename(str(item)) )
  76. if os.path.basename(str(item)) in remove:
  77. objs.remove(item)
  78. return
  79. def ProjectRemove(group, remove):
  80. global Projects
  81. for item in Projects:
  82. if item['name'] == group:
  83. for src in item['src']:
  84. if os.path.basename(str(src)) in remove:
  85. # print(type(src), os.path.basename(str(src)) )
  86. item['src'].remove(src)
  87. return
  88. ObjRemove(objs, ['components.obj', 'components.o', 'components.c'])
  89. ProjectRemove('Kernel', ['components.obj', 'components.o', 'components.c'])
  90. # build program -shared
  91. if GetDepend('RT_USING_MODULE'):
  92. # Remove module.c in $RTT_ROOT/src
  93. ObjRemove(objs, ['module.obj', 'module.o', 'module.c'])
  94. AddOption('--def',
  95. dest='def',
  96. action='store_true',
  97. default=False,
  98. help='create rtthread.def of rtthread.dll on windows')
  99. if GetOption('def'):
  100. if rtconfig.PLATFORM == 'mingw':
  101. env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS
  102. else:
  103. rtconfig.POST_ACTION = 'python createdef.py $TARGET rtthread.def'
  104. program = env.Program(TARGET, objs)
  105. else:
  106. if rtconfig.PLATFORM == 'cl':
  107. objs += ['rtthread.def']
  108. elif rtconfig.PLATFORM == 'mingw':
  109. rtconfig.POST_ACTION = 'del /Q rtthread.lib \n rename librtthread.a rtthread.lib\n'
  110. # rtconfig.POST_ACTION = 'lib /machine:i386 /def:rtthread.def /out:rtthread.lib'
  111. env.SharedLibrary("rtthread.dll", objs)
  112. program = env.Program(TARGET, 'dummy.c', LIBS='rtthread', LIBPATH='.')
  113. else:
  114. program = env.Program(TARGET, objs)
  115. # end building
  116. EndBuilding(TARGET, program)