SConstruct 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. if os.getenv('RTT_RTGUI'):
  9. RTT_RTGUI = os.getenv('RTT_RTGUI')
  10. else:
  11. # set the rtgui root directory by hand
  12. # empty string means use the RTGUI in svn
  13. RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui')
  14. sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
  15. from building import *
  16. env = Environment(TARGET_ARCH='x86')
  17. Export('RTT_ROOT')
  18. Export('rtconfig')
  19. if rtconfig.PLATFORM == 'cl':
  20. TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
  21. libs = Split('''
  22. winmm
  23. gdi32
  24. winspool
  25. comdlg32
  26. advapi32
  27. shell32
  28. ole32
  29. oleaut32
  30. uuid
  31. odbc32
  32. odbccp32
  33. ''')
  34. definitions = Split('''
  35. WIN32
  36. _DEBUG
  37. _CONSOLE
  38. MSVC
  39. _TIME_T_DEFINED
  40. ''')
  41. env.Append(CCFLAGS=rtconfig.CFLAGS)
  42. env.Append(LINKFLAGS=rtconfig.LFLAGS)
  43. env['LIBS']=libs
  44. env['CPPDEFINES']=definitions
  45. elif rtconfig.PLATFORM == 'mingw':
  46. libs = Split('''
  47. winmm
  48. gdi32
  49. winspool
  50. comdlg32
  51. advapi32
  52. shell32
  53. ole32
  54. oleaut32
  55. uuid
  56. odbc32
  57. odbccp32
  58. ''')
  59. TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT
  60. env = Environment(tools = ['mingw'],
  61. AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
  62. CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
  63. AR = rtconfig.AR, ARFLAGS = '-rc',
  64. LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
  65. env['LIBS']=libs
  66. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  67. elif rtconfig.CROSS_TOOL == 'clang-analyze':
  68. TARGET = 'rtthread'
  69. env = Environment(toolpath=[os.path.join(RTT_ROOT, 'tools', 'tools')],
  70. tools = [rtconfig.CROSS_TOOL])
  71. else:
  72. TARGET = 'rtthread'
  73. env['CC']=rtconfig.CC
  74. env.Append(CCFLAGS=rtconfig.CFLAGS)
  75. env.Append(LINKFLAGS=rtconfig.LFLAGS)
  76. env.Append(LIBS=['m'])
  77. # prepare building environment
  78. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui'])
  79. if GetDepend('RT_USING_RTGUI'):
  80. try:
  81. if RTT_RTGUI:
  82. objs += SConscript(os.path.join(RTT_RTGUI, 'SConscript'),
  83. variant_dir='build/components/rtgui',
  84. duplicate=0)
  85. objs = objs + SConscript(RTT_RTGUI+'/../../demo/examples/SConscript',
  86. variant_dir='build/examples/gui', duplicate=0)
  87. else:
  88. objs += SConscript(os.path.join(RTT_ROOT + '/components/rtgui', 'SConscript'),
  89. variant_dir='build/components/rtgui',
  90. duplicate=0)
  91. objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript',
  92. variant_dir='build/examples/gui', duplicate=0)
  93. except:
  94. print
  95. print 'RTGUI configuration is invalid!'
  96. print 'RT_USING_RTGUI is enabled in rtconfig.h, but scons cannot find '+\
  97. 'RTGUI source code. In order to eliminate this error, you can '+\
  98. 'add RTT_RTGUI in environment to point RTGUI source code, or '+\
  99. 'disable RT_USING_RTGUI in rtconfig.h'
  100. exit(-1);
  101. if GetDepend('RT_USING_TC'):
  102. objs = objs + SConscript(RTT_ROOT + '/examples/kernel/SConscript', variant_dir = 'build/tc/kernel', duplicate=0)
  103. def ObjRemove(objs, remove):
  104. for item in objs:
  105. # print type(item), os.path.basename(str(item))
  106. if os.path.basename(str(item)) in remove:
  107. objs.remove(item)
  108. return
  109. # build program -shared
  110. if GetDepend('RT_USING_MODULE'):
  111. # Remove module.c in $RTT_ROOT/src
  112. ObjRemove(objs, ['module.obj', 'module.o'])
  113. AddOption('--def',
  114. dest='def',
  115. action='store_true',
  116. default=False,
  117. help='create rthread.def of rtthread.dll on windows')
  118. if GetOption('def'):
  119. if rtconfig.PLATFORM != 'mingw':
  120. print "scons error: `--def' can only work with mingw"
  121. exit(1)
  122. env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS
  123. env.SharedLibrary("rtthread.dll", objs)
  124. program = ''
  125. else:
  126. if rtconfig.PLATFORM == 'cl':
  127. objs += ['rtthread.def']
  128. elif rtconfig.PLATFORM == 'mingw':
  129. rtconfig.POST_ACTION = 'del /Q rtthread.lib \n rename librtthread.a rtthread.lib\n'
  130. # rtconfig.POST_ACTION = 'lib /machine:i386 /def:rtthread.def /out:rtthread.lib'
  131. env.SharedLibrary("rtthread.dll", objs)
  132. program = env.Program(TARGET, 'dummy.c', LIBS='rtthread', LIBPATH='.')
  133. else:
  134. program = env.Program(TARGET, objs)
  135. # end building
  136. EndBuilding(TARGET, program)