1import os 2import sys 3import rtconfig 4 5if os.getenv('RTT_ROOT'): 6 RTT_ROOT = os.getenv('RTT_ROOT') 7else: 8 RTT_ROOT = os.path.normpath(os.getcwd() + '/../..') 9 10sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] 11from building import * 12 13env = Environment(TARGET_ARCH='x86') 14 15Export('RTT_ROOT') 16Export('rtconfig') 17 18if rtconfig.PLATFORM == 'cl': 19 TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT 20 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 ''') 40 env.Append(CFLAGS=rtconfig.CFLAGS) 41 env.Append(LINKFLAGS=rtconfig.LFLAGS) 42 env['LIBS']=libs 43 env['CPPDEFINES']=definitions 44elif rtconfig.PLATFORM == 'mingw': 45 libs = Split(''' 46 winmm 47 gdi32 48 winspool 49 comdlg32 50 advapi32 51 shell32 52 ole32 53 oleaut32 54 uuid 55 odbc32 56 odbccp32 57 ''') 58 TARGET = 'rtthread-win32.' + rtconfig.TARGET_EXT 59 DefaultEnvironment(tools=[]) 60 env = Environment(tools = ['mingw'], 61 AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, 62 CC = rtconfig.CC, CFLAGS = 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) 67elif rtconfig.CROSS_TOOL == 'clang-analyze': 68 TARGET = 'rtthread' 69 env = Environment(toolpath=[os.path.join(RTT_ROOT, 'tools', 'tools')], 70 tools = [rtconfig.CROSS_TOOL]) 71else: 72 TARGET = 'rtthread' 73 env['CC']=rtconfig.CC 74 env.Append(CFLAGS=rtconfig.CFLAGS) 75 env.Append(LINKFLAGS=rtconfig.LFLAGS) 76 if sys.platform == 'win32': 77 env.Append(LIBS=['winmm']) 78 79# prepare building environment 80 81objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) 82 83def ObjRemove(objs, remove): 84 for item in objs: 85 # print(type(item), os.path.basename(str(item)) ) 86 if os.path.basename(str(item)) in remove: 87 objs.remove(item) 88 return 89 90def ProjectRemove(group, remove): 91 global Projects 92 for item in Projects: 93 if item['name'] == group: 94 for src in item['src']: 95 if os.path.basename(str(src)) in remove: 96 # print(type(src), os.path.basename(str(src)) ) 97 item['src'].remove(src) 98 return 99 100if rtconfig.CPU != 'posix': 101 ObjRemove(objs, ['components.obj', 'components.o', 'components.c']) 102 ProjectRemove('Kernel', ['components.obj', 'components.o', 'components.c']) 103 104# build program -shared 105if GetDepend('RT_USING_MODULE'): 106 # Remove module.c in $RTT_ROOT/src 107 ObjRemove(objs, ['module.obj', 'module.o', 'module.c']) 108 109 AddOption('--def', 110 dest='def', 111 action='store_true', 112 default=False, 113 help='create rtthread.def of rtthread.dll on windows') 114 if GetOption('def'): 115 if rtconfig.PLATFORM == 'mingw': 116 env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS 117 else: 118 rtconfig.POST_ACTION = 'python createdef.py $TARGET rtthread.def' 119 120 program = env.Program(TARGET, objs) 121 else: 122 if rtconfig.PLATFORM == 'cl': 123 objs += ['rtthread.def'] 124 elif rtconfig.PLATFORM == 'mingw': 125 rtconfig.POST_ACTION = 'del /Q rtthread.lib \n rename librtthread.a rtthread.lib\n' 126 # rtconfig.POST_ACTION = 'lib /machine:i386 /def:rtthread.def /out:rtthread.lib' 127 env.SharedLibrary("rtthread.dll", objs) 128 program = env.Program(TARGET, 'dummy.c', LIBS='rtthread', LIBPATH='.') 129 130else: 131 program = env.Program(TARGET, objs) 132 133# end building 134EndBuilding(TARGET, program) 135