SConstruct 4.2 KB

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