building.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. import os
  2. import sys
  3. import string
  4. from SCons.Script import *
  5. from utils import _make_path_relative
  6. BuildOptions = {}
  7. Projects = []
  8. Rtt_Root = ''
  9. Env = None
  10. class Win32Spawn:
  11. def spawn(self, sh, escape, cmd, args, env):
  12. # deal with the cmd build-in commands which cannot be used in
  13. # subprocess.Popen
  14. if cmd == 'del':
  15. for f in args[1:]:
  16. try:
  17. os.remove(f)
  18. except Exception as e:
  19. print 'Error removing file: %s' % e
  20. return -1
  21. return 0
  22. import subprocess
  23. newargs = string.join(args[1:], ' ')
  24. cmdline = cmd + " " + newargs
  25. startupinfo = subprocess.STARTUPINFO()
  26. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  27. # Make sure the env is constructed by strings
  28. _e = {k: str(v) for k, v in env.items()}
  29. # Windows(tm) CreateProcess does not use the env passed to it to find
  30. # the executables. So we have to modify our own PATH to make Popen
  31. # work.
  32. old_path = os.environ['PATH']
  33. os.environ['PATH'] = _e['PATH']
  34. try:
  35. proc = subprocess.Popen(cmdline, env=_e,
  36. startupinfo=startupinfo, shell=False)
  37. except Exception as e:
  38. print 'Error in calling:\n%s' % cmdline
  39. print 'Exception: %s: %s' % (e, os.strerror(e.errno))
  40. return e.errno
  41. finally:
  42. os.environ['PATH'] = old_path
  43. return proc.wait()
  44. def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
  45. import SCons.cpp
  46. import rtconfig
  47. global BuildOptions
  48. global Projects
  49. global Env
  50. global Rtt_Root
  51. Env = env
  52. Rtt_Root = root_directory
  53. # add compability with Keil MDK 4.6 which changes the directory of armcc.exe
  54. if rtconfig.PLATFORM == 'armcc':
  55. if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
  56. if rtconfig.EXEC_PATH.find('bin40') > 0:
  57. rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin')
  58. Env['LINKFLAGS']=Env['LINKFLAGS'].replace('RV31', 'armcc')
  59. # reset AR command flags
  60. env['ARCOM'] = '$AR --create $TARGET $SOURCES'
  61. env['LIBPREFIX'] = ''
  62. env['LIBSUFFIX'] = '.lib'
  63. env['LIBLINKPREFIX'] = ''
  64. env['LIBLINKSUFFIX'] = '.lib'
  65. env['LIBDIRPREFIX'] = '--userlibpath '
  66. # patch for win32 spawn
  67. if env['PLATFORM'] == 'win32':
  68. win32_spawn = Win32Spawn()
  69. win32_spawn.env = env
  70. env['SPAWN'] = win32_spawn.spawn
  71. if env['PLATFORM'] == 'win32':
  72. os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
  73. else:
  74. os.environ['PATH'] = rtconfig.EXEC_PATH + ":" + os.environ['PATH']
  75. # add program path
  76. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  77. # add library build action
  78. act = SCons.Action.Action(BuildLibInstallAction, 'Install compiled library... $TARGET')
  79. bld = Builder(action = act)
  80. Env.Append(BUILDERS = {'BuildLib': bld})
  81. # parse rtconfig.h to get used component
  82. PreProcessor = SCons.cpp.PreProcessor()
  83. f = file('rtconfig.h', 'r')
  84. contents = f.read()
  85. f.close()
  86. PreProcessor.process_contents(contents)
  87. BuildOptions = PreProcessor.cpp_namespace
  88. # add copy option
  89. AddOption('--copy',
  90. dest='copy',
  91. action='store_true',
  92. default=False,
  93. help='copy rt-thread directory to local.')
  94. AddOption('--copy-header',
  95. dest='copy-header',
  96. action='store_true',
  97. default=False,
  98. help='copy header of rt-thread directory to local.')
  99. AddOption('--cscope',
  100. dest='cscope',
  101. action='store_true',
  102. default=False,
  103. help='Build Cscope cross reference database. Requires cscope installed.')
  104. AddOption('--clang-analyzer',
  105. dest='clang-analyzer',
  106. action='store_true',
  107. default=False,
  108. help='Perform static analyze with Clang-analyzer. '+\
  109. 'Requires Clang installed.\n'+\
  110. 'It is recommended to use with scan-build like this:\n'+\
  111. '`scan-build scons --clang-analyzer`\n'+\
  112. 'If things goes well, scan-build will instruct you to invoke scan-view.')
  113. if GetOption('clang-analyzer'):
  114. # perform what scan-build does
  115. env.Replace(
  116. CC = 'ccc-analyzer',
  117. CXX = 'c++-analyzer',
  118. # skip as and link
  119. LINK = 'true',
  120. AS = 'true',)
  121. env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
  122. # only check, don't compile. ccc-analyzer use CCC_CC as the CC.
  123. # fsyntax-only will give us some additional warning messages
  124. env['ENV']['CCC_CC'] = 'clang'
  125. env.Append(CFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'])
  126. env['ENV']['CCC_CXX'] = 'clang++'
  127. env.Append(CXXFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'])
  128. # remove the POST_ACTION as it will cause meaningless errors(file not
  129. # found or something like that).
  130. rtconfig.POST_ACTION = ''
  131. # add build library option
  132. AddOption('--buildlib',
  133. dest='buildlib',
  134. type='string',
  135. help='building library of a component')
  136. AddOption('--cleanlib',
  137. dest='cleanlib',
  138. action='store_true',
  139. default=False,
  140. help='clean up the library by --buildlib')
  141. # add target option
  142. AddOption('--target',
  143. dest='target',
  144. type='string',
  145. help='set target project: mdk/iar/vs/ua')
  146. #{target_name:(CROSS_TOOL, PLATFORM)}
  147. tgt_dict = {'mdk':('keil', 'armcc'),
  148. 'mdk4':('keil', 'armcc'),
  149. 'iar':('iar', 'iar'),
  150. 'vs':('msvc', 'cl'),
  151. 'vs2012':('msvc', 'cl'),
  152. 'cb':('keil', 'armcc'),
  153. 'ua':('keil', 'armcc')}
  154. tgt_name = GetOption('target')
  155. if tgt_name:
  156. # --target will change the toolchain settings which clang-analyzer is
  157. # depend on
  158. if GetOption('clang-analyzer'):
  159. print '--clang-analyzer cannot be used with --target'
  160. sys.exit(1)
  161. SetOption('no_exec', 1)
  162. try:
  163. rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
  164. except KeyError:
  165. print 'Unknow target: %s. Avaible targets: %s' % \
  166. (tgt_name, ', '.join(tgt_dict.keys()))
  167. sys.exit(1)
  168. elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
  169. and rtconfig.PLATFORM == 'gcc':
  170. AddDepend('RT_USING_MINILIBC')
  171. # add comstr option
  172. AddOption('--verbose',
  173. dest='verbose',
  174. action='store_true',
  175. default=False,
  176. help='print verbose information during build')
  177. if not GetOption('verbose'):
  178. # override the default verbose command string
  179. env.Replace(
  180. ARCOMSTR = 'AR $TARGET',
  181. ASCOMSTR = 'AS $TARGET',
  182. ASPPCOMSTR = 'AS $TARGET',
  183. CCCOMSTR = 'CC $TARGET',
  184. CXXCOMSTR = 'CXX $TARGET',
  185. LINKCOMSTR = 'LINK $TARGET'
  186. )
  187. # we need to seperate the variant_dir for BSPs and the kernels. BSPs could
  188. # have their own components etc. If they point to the same folder, SCons
  189. # would find the wrong source code to compile.
  190. bsp_vdir = 'build/bsp'
  191. kernel_vdir = 'build/kernel'
  192. # board build script
  193. objs = SConscript('SConscript', variant_dir=bsp_vdir, duplicate=0)
  194. # include kernel
  195. objs.extend(SConscript(Rtt_Root + '/src/SConscript', variant_dir=kernel_vdir + '/src', duplicate=0))
  196. # include libcpu
  197. if not has_libcpu:
  198. objs.extend(SConscript(Rtt_Root + '/libcpu/SConscript',
  199. variant_dir=kernel_vdir + '/libcpu', duplicate=0))
  200. # include components
  201. objs.extend(SConscript(Rtt_Root + '/components/SConscript',
  202. variant_dir=kernel_vdir + '/components',
  203. duplicate=0,
  204. exports='remove_components'))
  205. return objs
  206. def PrepareModuleBuilding(env, root_directory):
  207. import rtconfig
  208. global Env
  209. global Rtt_Root
  210. Env = env
  211. Rtt_Root = root_directory
  212. # add build/clean library option for library checking
  213. AddOption('--buildlib',
  214. dest='buildlib',
  215. type='string',
  216. help='building library of a component')
  217. AddOption('--cleanlib',
  218. dest='cleanlib',
  219. action='store_true',
  220. default=False,
  221. help='clean up the library by --buildlib')
  222. # add program path
  223. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  224. def GetConfigValue(name):
  225. assert type(name) == str, 'GetConfigValue: only string parameter is valid'
  226. try:
  227. return BuildOptions[name]
  228. except:
  229. return ''
  230. def GetDepend(depend):
  231. building = True
  232. if type(depend) == type('str'):
  233. if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0:
  234. building = False
  235. elif BuildOptions[depend] != '':
  236. return BuildOptions[depend]
  237. return building
  238. # for list type depend
  239. for item in depend:
  240. if item != '':
  241. if not BuildOptions.has_key(item) or BuildOptions[item] == 0:
  242. building = False
  243. return building
  244. def AddDepend(option):
  245. BuildOptions[option] = 1
  246. def MergeGroup(src_group, group):
  247. src_group['src'] = src_group['src'] + group['src']
  248. if group.has_key('CCFLAGS'):
  249. if src_group.has_key('CCFLAGS'):
  250. src_group['CCFLAGS'] = src_group['CCFLAGS'] + group['CCFLAGS']
  251. else:
  252. src_group['CCFLAGS'] = group['CCFLAGS']
  253. if group.has_key('CPPPATH'):
  254. if src_group.has_key('CPPPATH'):
  255. src_group['CPPPATH'] = src_group['CPPPATH'] + group['CPPPATH']
  256. else:
  257. src_group['CPPPATH'] = group['CPPPATH']
  258. if group.has_key('CPPDEFINES'):
  259. if src_group.has_key('CPPDEFINES'):
  260. src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
  261. else:
  262. src_group['CPPDEFINES'] = group['CPPDEFINES']
  263. if group.has_key('LINKFLAGS'):
  264. if src_group.has_key('LINKFLAGS'):
  265. src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
  266. else:
  267. src_group['LINKFLAGS'] = group['LINKFLAGS']
  268. if group.has_key('LIBS'):
  269. if src_group.has_key('LIBS'):
  270. src_group['LIBS'] = src_group['LIBS'] + group['LIBS']
  271. else:
  272. src_group['LIBS'] = group['LIBS']
  273. if group.has_key('LIBPATH'):
  274. if src_group.has_key('LIBPATH'):
  275. src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
  276. else:
  277. src_group['LIBPATH'] = group['LIBPATH']
  278. def DefineGroup(name, src, depend, **parameters):
  279. global Env
  280. if not GetDepend(depend):
  281. return []
  282. # find exist group and get path of group
  283. group_path = ''
  284. for g in Projects:
  285. if g['name'] == name:
  286. group_path = g['path']
  287. if group_path == '':
  288. group_path = GetCurrentDir()
  289. group = parameters
  290. group['name'] = name
  291. group['path'] = group_path
  292. if type(src) == type(['src1']):
  293. group['src'] = File(src)
  294. else:
  295. group['src'] = src
  296. if group.has_key('CCFLAGS'):
  297. Env.Append(CCFLAGS = group['CCFLAGS'])
  298. if group.has_key('CPPPATH'):
  299. Env.Append(CPPPATH = group['CPPPATH'])
  300. if group.has_key('CPPDEFINES'):
  301. Env.Append(CPPDEFINES = group['CPPDEFINES'])
  302. if group.has_key('LINKFLAGS'):
  303. Env.Append(LINKFLAGS = group['LINKFLAGS'])
  304. # check whether to clean up library
  305. if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  306. if group['src'] != []:
  307. print 'Remove library:', GroupLibFullName(name, Env)
  308. do_rm_file(os.path.join(group['path'], GroupLibFullName(name, Env)))
  309. # check whether exist group library
  310. if not GetOption('buildlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  311. group['src'] = []
  312. if group.has_key('LIBS'): group['LIBS'] = group['LIBS'] + [GroupLibName(name, Env)]
  313. else : group['LIBS'] = [GroupLibName(name, Env)]
  314. if group.has_key('LIBPATH'): group['LIBPATH'] = group['LIBPATH'] + [GetCurrentDir()]
  315. else : group['LIBPATH'] = [GetCurrentDir()]
  316. if group.has_key('LIBS'):
  317. Env.Append(LIBS = group['LIBS'])
  318. if group.has_key('LIBPATH'):
  319. Env.Append(LIBPATH = group['LIBPATH'])
  320. objs = Env.Object(group['src'])
  321. if group.has_key('LIBRARY'):
  322. objs = Env.Library(name, objs)
  323. # merge group
  324. for g in Projects:
  325. if g['name'] == name:
  326. # merge to this group
  327. MergeGroup(g, group)
  328. return objs
  329. # add a new group
  330. Projects.append(group)
  331. return objs
  332. def GetCurrentDir():
  333. conscript = File('SConscript')
  334. fn = conscript.rfile()
  335. name = fn.name
  336. path = os.path.dirname(fn.abspath)
  337. return path
  338. PREBUILDING = []
  339. def RegisterPreBuildingAction(act):
  340. global PREBUILDING
  341. assert callable(act), 'Could only register callable objects. %s received' % repr(act)
  342. PREBUILDING.append(act)
  343. def PreBuilding():
  344. global PREBUILDING
  345. for a in PREBUILDING:
  346. a()
  347. def GroupLibName(name, env):
  348. import rtconfig
  349. if rtconfig.PLATFORM == 'armcc':
  350. return name + '_rvds'
  351. elif rtconfig.PLATFORM == 'gcc':
  352. return name + '_gcc'
  353. return name
  354. def GroupLibFullName(name, env):
  355. return env['LIBPREFIX'] + GroupLibName(name, env) + env['LIBSUFFIX']
  356. def BuildLibInstallAction(target, source, env):
  357. lib_name = GetOption('buildlib')
  358. for Group in Projects:
  359. if Group['name'] == lib_name:
  360. lib_name = GroupLibFullName(Group['name'], env)
  361. dst_name = os.path.join(Group['path'], lib_name)
  362. print 'Copy %s => %s' % (lib_name, dst_name)
  363. do_copy_file(lib_name, dst_name)
  364. break
  365. def DoBuilding(target, objects):
  366. program = None
  367. # check whether special buildlib option
  368. lib_name = GetOption('buildlib')
  369. if lib_name:
  370. # build library with special component
  371. for Group in Projects:
  372. if Group['name'] == lib_name:
  373. lib_name = GroupLibName(Group['name'], Env)
  374. objects = Env.Object(Group['src'])
  375. program = Env.Library(lib_name, objects)
  376. # add library copy action
  377. Env.BuildLib(lib_name, program)
  378. break
  379. else:
  380. # merge the repeated items in the Env
  381. if Env.has_key('CPPPATH') : Env['CPPPATH'] = list(set(Env['CPPPATH']))
  382. if Env.has_key('CPPDEFINES'): Env['CPPDEFINES'] = list(set(Env['CPPDEFINES']))
  383. if Env.has_key('LIBPATH') : Env['LIBPATH'] = list(set(Env['LIBPATH']))
  384. if Env.has_key('LIBS') : Env['LIBS'] = list(set(Env['LIBS']))
  385. program = Env.Program(target, objects)
  386. EndBuilding(target, program)
  387. def EndBuilding(target, program = None):
  388. import rtconfig
  389. Env.AddPostAction(target, rtconfig.POST_ACTION)
  390. if GetOption('target') == 'mdk':
  391. from keil import MDKProject
  392. from keil import MDK4Project
  393. template = os.path.isfile('template.Uv2')
  394. if template:
  395. MDKProject('project.Uv2', Projects)
  396. else:
  397. template = os.path.isfile('template.uvproj')
  398. if template:
  399. MDK4Project('project.uvproj', Projects)
  400. else:
  401. print 'No template project file found.'
  402. if GetOption('target') == 'mdk4':
  403. from keil import MDKProject
  404. from keil import MDK4Project
  405. MDK4Project('project.uvproj', Projects)
  406. if GetOption('target') == 'iar':
  407. from iar import IARProject
  408. IARProject('project.ewp', Projects)
  409. if GetOption('target') == 'vs':
  410. from vs import VSProject
  411. VSProject('project.vcproj', Projects, program)
  412. if GetOption('target') == 'vs2012':
  413. from vs2012 import VS2012Project
  414. VS2012Project('project.vcxproj', Projects, program)
  415. if GetOption('target') == 'cb':
  416. from codeblocks import CBProject
  417. CBProject('project.cbp', Projects, program)
  418. if GetOption('target') == 'ua':
  419. from ua import PrepareUA
  420. PrepareUA(Projects, Rtt_Root, str(Dir('#')))
  421. if GetOption('copy') and program != None:
  422. MakeCopy(program)
  423. if GetOption('copy-header') and program != None:
  424. MakeCopyHeader(program)
  425. if GetOption('cscope'):
  426. from cscope import CscopeDatabase
  427. CscopeDatabase(Projects)
  428. def SrcRemove(src, remove):
  429. if type(src[0]) == type('str'):
  430. for item in src:
  431. if os.path.basename(item) in remove:
  432. src.remove(item)
  433. return
  434. for item in src:
  435. if os.path.basename(item.rstr()) in remove:
  436. src.remove(item)
  437. def GetVersion():
  438. import SCons.cpp
  439. import string
  440. rtdef = os.path.join(Rtt_Root, 'include', 'rtdef.h')
  441. # parse rtdef.h to get RT-Thread version
  442. prepcessor = SCons.cpp.PreProcessor()
  443. f = file(rtdef, 'r')
  444. contents = f.read()
  445. f.close()
  446. prepcessor.process_contents(contents)
  447. def_ns = prepcessor.cpp_namespace
  448. version = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_VERSION']))
  449. subversion = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_SUBVERSION']))
  450. if def_ns.has_key('RT_REVISION'):
  451. revision = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_REVISION']))
  452. return '%d.%d.%d' % (version, subversion, revision)
  453. return '0.%d.%d' % (version, subversion)
  454. def GlobSubDir(sub_dir, ext_name):
  455. import os
  456. import glob
  457. def glob_source(sub_dir, ext_name):
  458. list = os.listdir(sub_dir)
  459. src = glob.glob(os.path.join(sub_dir, ext_name))
  460. for item in list:
  461. full_subdir = os.path.join(sub_dir, item)
  462. if os.path.isdir(full_subdir):
  463. src += glob_source(full_subdir, ext_name)
  464. return src
  465. dst = []
  466. src = glob_source(sub_dir, ext_name)
  467. for item in src:
  468. dst.append(os.path.relpath(item, sub_dir))
  469. return dst
  470. def file_path_exist(path, *args):
  471. return os.path.exists(os.path.join(path, *args))
  472. def do_rm_file(src):
  473. if os.path.exists(src):
  474. os.unlink(src)
  475. def do_copy_file(src, dst):
  476. import shutil
  477. # check source file
  478. if not os.path.exists(src):
  479. return
  480. path = os.path.dirname(dst)
  481. # mkdir if path not exist
  482. if not os.path.exists(path):
  483. os.makedirs(path)
  484. shutil.copy2(src, dst)
  485. def do_copy_folder(src_dir, dst_dir):
  486. import shutil
  487. # check source directory
  488. if not os.path.exists(src_dir):
  489. return
  490. if os.path.exists(dst_dir):
  491. shutil.rmtree(dst_dir)
  492. shutil.copytree(src_dir, dst_dir)
  493. source_ext = ["c", "h", "s", "S", "cpp", "xpm"]
  494. source_list = []
  495. def walk_children(child):
  496. global source_list
  497. global source_ext
  498. # print child
  499. full_path = child.rfile().abspath
  500. file_type = full_path.rsplit('.',1)[1]
  501. #print file_type
  502. if file_type in source_ext:
  503. if full_path not in source_list:
  504. source_list.append(full_path)
  505. children = child.all_children()
  506. if children != []:
  507. for item in children:
  508. walk_children(item)
  509. def MakeCopy(program):
  510. global source_list
  511. global Rtt_Root
  512. global Env
  513. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  514. if Env['PLATFORM'] == 'win32':
  515. RTT_ROOT = Rtt_Root.lower()
  516. else:
  517. RTT_ROOT = Rtt_Root
  518. if target_path.startswith(RTT_ROOT):
  519. return
  520. for item in program:
  521. walk_children(item)
  522. source_list.sort()
  523. # filte source file in RT-Thread
  524. target_list = []
  525. for src in source_list:
  526. if Env['PLATFORM'] == 'win32':
  527. src = src.lower()
  528. if src.startswith(RTT_ROOT):
  529. target_list.append(src)
  530. source_list = target_list
  531. # get source path
  532. src_dir = []
  533. for src in source_list:
  534. src = src.replace(RTT_ROOT, '')
  535. if src[0] == os.sep or src[0] == '/':
  536. src = src[1:]
  537. path = os.path.dirname(src)
  538. sub_path = path.split(os.sep)
  539. full_path = RTT_ROOT
  540. for item in sub_path:
  541. full_path = os.path.join(full_path, item)
  542. if full_path not in src_dir:
  543. src_dir.append(full_path)
  544. for item in src_dir:
  545. source_list.append(os.path.join(item, 'SConscript'))
  546. for src in source_list:
  547. dst = src.replace(RTT_ROOT, '')
  548. if dst[0] == os.sep or dst[0] == '/':
  549. dst = dst[1:]
  550. print '=> ', dst
  551. dst = os.path.join(target_path, dst)
  552. do_copy_file(src, dst)
  553. # copy tools directory
  554. print "=> tools"
  555. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  556. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  557. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
  558. def MakeCopyHeader(program):
  559. global source_ext
  560. source_ext = []
  561. source_ext = ["h", "xpm"]
  562. global source_list
  563. global Rtt_Root
  564. global Env
  565. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  566. if Env['PLATFORM'] == 'win32':
  567. RTT_ROOT = Rtt_Root.lower()
  568. else:
  569. RTT_ROOT = Rtt_Root
  570. if target_path.startswith(RTT_ROOT):
  571. return
  572. for item in program:
  573. walk_children(item)
  574. source_list.sort()
  575. # filte source file in RT-Thread
  576. target_list = []
  577. for src in source_list:
  578. if Env['PLATFORM'] == 'win32':
  579. src = src.lower()
  580. if src.startswith(RTT_ROOT):
  581. target_list.append(src)
  582. source_list = target_list
  583. for src in source_list:
  584. dst = src.replace(RTT_ROOT, '')
  585. if dst[0] == os.sep or dst[0] == '/':
  586. dst = dst[1:]
  587. print '=> ', dst
  588. dst = os.path.join(target_path, dst)
  589. do_copy_file(src, dst)
  590. # copy tools directory
  591. print "=> tools"
  592. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  593. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  594. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))