SConstruct 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.Append(CCFLAGS=rtconfig.CFLAGS)
  71. env.Append(LINKFLAGS=rtconfig.LFLAGS)
  72. env.Append(LIBS=['m'])
  73. # prepare building environment
  74. objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False, remove_components=['rtgui'])
  75. if GetDepend('RT_USING_RTGUI'):
  76. sdl_lib = ['SDL', 'SDLmain']
  77. sdl_lib_path = [os.path.abspath('SDL/lib/x86')]
  78. sdl_include_path = [os.path.abspath('SDL/include')]
  79. env.Append(LIBS=sdl_lib)
  80. env.Append(LIBPATH=sdl_lib_path)
  81. env.Append(CPPPATH=sdl_include_path)
  82. if RTT_RTGUI:
  83. objs += SConscript(os.path.join(RTT_RTGUI, 'SConscript'),
  84. variant_dir='build/components/rtgui',
  85. duplicate=0)
  86. objs = objs + SConscript(RTT_RTGUI+'/../../demo/examples/SConscript',
  87. variant_dir='build/examples/gui', duplicate=0)
  88. else:
  89. objs += SConscript(os.path.join(RTT_ROOT + '/components/rtgui', 'SConscript'),
  90. variant_dir='build/components/rtgui',
  91. duplicate=0)
  92. objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript',
  93. variant_dir='build/examples/gui', duplicate=0)
  94. if GetDepend('RT_USING_TC'):
  95. objs = objs + SConscript(RTT_ROOT + '/examples/kernel/SConscript', variant_dir = 'build/tc/kernel', duplicate=0)
  96. def ObjRemove(objs, remove):
  97. for item in objs:
  98. # print type(item), os.path.basename(str(item))
  99. if os.path.basename(str(item)) in remove:
  100. objs.remove(item)
  101. return
  102. # build program -shared
  103. if GetDepend('RT_USING_MODULE'):
  104. # Remove module.c in $RTT_ROOT/src
  105. ObjRemove(objs, ['module.obj', 'module.o'])
  106. AddOption('--def',
  107. dest='def',
  108. action='store_true',
  109. default=False,
  110. help='create rthread.def of rtthread.dll on windows')
  111. if GetOption('def'):
  112. if rtconfig.PLATFORM != 'mingw':
  113. print "scons error: `--def' can only work with mingw"
  114. exit(1)
  115. env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS
  116. env.SharedLibrary("rtthread.dll", objs)
  117. program = ''
  118. else:
  119. if rtconfig.PLATFORM == 'cl':
  120. objs += ['rtthread.def']
  121. elif rtconfig.PLATFORM == 'mingw':
  122. rtconfig.POST_ACTION = 'del /Q rtthread.lib \n rename librtthread.a rtthread.lib\n'
  123. # rtconfig.POST_ACTION = 'lib /machine:i386 /def:rtthread.def /out:rtthread.lib'
  124. env.SharedLibrary("rtthread.dll", objs)
  125. program = env.Program(TARGET, 'dummy.c', LIBS='rtthread', LIBPATH='.')
  126. else:
  127. program = env.Program(TARGET, objs)
  128. # end building
  129. EndBuilding(TARGET, program)