building.py 24 KB

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