building.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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):
  228. import rtconfig
  229. global Env
  230. global Rtt_Root
  231. Env = env
  232. Rtt_Root = root_directory
  233. # add build/clean library option for library checking
  234. AddOption('--buildlib',
  235. dest='buildlib',
  236. type='string',
  237. help='building library of a component')
  238. AddOption('--cleanlib',
  239. dest='cleanlib',
  240. action='store_true',
  241. default=False,
  242. help='clean up the library by --buildlib')
  243. # add program path
  244. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  245. def GetConfigValue(name):
  246. assert type(name) == str, 'GetConfigValue: only string parameter is valid'
  247. try:
  248. return BuildOptions[name]
  249. except:
  250. return ''
  251. def GetDepend(depend):
  252. building = True
  253. if type(depend) == type('str'):
  254. if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0:
  255. building = False
  256. elif BuildOptions[depend] != '':
  257. return BuildOptions[depend]
  258. return building
  259. # for list type depend
  260. for item in depend:
  261. if item != '':
  262. if not BuildOptions.has_key(item) or BuildOptions[item] == 0:
  263. building = False
  264. return building
  265. def AddDepend(option):
  266. BuildOptions[option] = 1
  267. def MergeGroup(src_group, group):
  268. src_group['src'] = src_group['src'] + group['src']
  269. if group.has_key('CCFLAGS'):
  270. if src_group.has_key('CCFLAGS'):
  271. src_group['CCFLAGS'] = src_group['CCFLAGS'] + group['CCFLAGS']
  272. else:
  273. src_group['CCFLAGS'] = group['CCFLAGS']
  274. if group.has_key('CPPPATH'):
  275. if src_group.has_key('CPPPATH'):
  276. src_group['CPPPATH'] = src_group['CPPPATH'] + group['CPPPATH']
  277. else:
  278. src_group['CPPPATH'] = group['CPPPATH']
  279. if group.has_key('CPPDEFINES'):
  280. if src_group.has_key('CPPDEFINES'):
  281. src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
  282. else:
  283. src_group['CPPDEFINES'] = group['CPPDEFINES']
  284. if group.has_key('LINKFLAGS'):
  285. if src_group.has_key('LINKFLAGS'):
  286. src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
  287. else:
  288. src_group['LINKFLAGS'] = group['LINKFLAGS']
  289. if group.has_key('LIBS'):
  290. if src_group.has_key('LIBS'):
  291. src_group['LIBS'] = src_group['LIBS'] + group['LIBS']
  292. else:
  293. src_group['LIBS'] = group['LIBS']
  294. if group.has_key('LIBPATH'):
  295. if src_group.has_key('LIBPATH'):
  296. src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
  297. else:
  298. src_group['LIBPATH'] = group['LIBPATH']
  299. def DefineGroup(name, src, depend, **parameters):
  300. global Env
  301. if not GetDepend(depend):
  302. return []
  303. # find exist group and get path of group
  304. group_path = ''
  305. for g in Projects:
  306. if g['name'] == name:
  307. group_path = g['path']
  308. if group_path == '':
  309. group_path = GetCurrentDir()
  310. group = parameters
  311. group['name'] = name
  312. group['path'] = group_path
  313. if type(src) == type(['src1']):
  314. group['src'] = File(src)
  315. else:
  316. group['src'] = src
  317. if group.has_key('CCFLAGS'):
  318. Env.Append(CCFLAGS = group['CCFLAGS'])
  319. if group.has_key('CPPPATH'):
  320. Env.Append(CPPPATH = group['CPPPATH'])
  321. if group.has_key('CPPDEFINES'):
  322. Env.Append(CPPDEFINES = group['CPPDEFINES'])
  323. if group.has_key('LINKFLAGS'):
  324. Env.Append(LINKFLAGS = group['LINKFLAGS'])
  325. # check whether to clean up library
  326. if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  327. if group['src'] != []:
  328. print 'Remove library:', GroupLibFullName(name, Env)
  329. do_rm_file(os.path.join(group['path'], GroupLibFullName(name, Env)))
  330. # check whether exist group library
  331. if not GetOption('buildlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  332. group['src'] = []
  333. if group.has_key('LIBS'): group['LIBS'] = group['LIBS'] + [GroupLibName(name, Env)]
  334. else : group['LIBS'] = [GroupLibName(name, Env)]
  335. if group.has_key('LIBPATH'): group['LIBPATH'] = group['LIBPATH'] + [GetCurrentDir()]
  336. else : group['LIBPATH'] = [GetCurrentDir()]
  337. if group.has_key('LIBS'):
  338. Env.Append(LIBS = group['LIBS'])
  339. if group.has_key('LIBPATH'):
  340. Env.Append(LIBPATH = group['LIBPATH'])
  341. if group.has_key('LIBRARY'):
  342. objs = Env.Library(name, group['src'])
  343. else:
  344. objs = group['src']
  345. # merge group
  346. for g in Projects:
  347. if g['name'] == name:
  348. # merge to this group
  349. MergeGroup(g, group)
  350. return objs
  351. # add a new group
  352. Projects.append(group)
  353. return objs
  354. def GetCurrentDir():
  355. conscript = File('SConscript')
  356. fn = conscript.rfile()
  357. name = fn.name
  358. path = os.path.dirname(fn.abspath)
  359. return path
  360. PREBUILDING = []
  361. def RegisterPreBuildingAction(act):
  362. global PREBUILDING
  363. assert callable(act), 'Could only register callable objects. %s received' % repr(act)
  364. PREBUILDING.append(act)
  365. def PreBuilding():
  366. global PREBUILDING
  367. for a in PREBUILDING:
  368. a()
  369. def GroupLibName(name, env):
  370. import rtconfig
  371. if rtconfig.PLATFORM == 'armcc':
  372. return name + '_rvds'
  373. elif rtconfig.PLATFORM == 'gcc':
  374. return name + '_gcc'
  375. return name
  376. def GroupLibFullName(name, env):
  377. return env['LIBPREFIX'] + GroupLibName(name, env) + env['LIBSUFFIX']
  378. def BuildLibInstallAction(target, source, env):
  379. lib_name = GetOption('buildlib')
  380. for Group in Projects:
  381. if Group['name'] == lib_name:
  382. lib_name = GroupLibFullName(Group['name'], env)
  383. dst_name = os.path.join(Group['path'], lib_name)
  384. print 'Copy %s => %s' % (lib_name, dst_name)
  385. do_copy_file(lib_name, dst_name)
  386. break
  387. def DoBuilding(target, objects):
  388. program = None
  389. # check whether special buildlib option
  390. lib_name = GetOption('buildlib')
  391. if lib_name:
  392. # build library with special component
  393. for Group in Projects:
  394. if Group['name'] == lib_name:
  395. lib_name = GroupLibName(Group['name'], Env)
  396. objects = Env.Object(Group['src'])
  397. program = Env.Library(lib_name, objects)
  398. # add library copy action
  399. Env.BuildLib(lib_name, program)
  400. break
  401. else:
  402. program = Env.Program(target, objects)
  403. EndBuilding(target, program)
  404. def EndBuilding(target, program = None):
  405. import rtconfig
  406. Env.AddPostAction(target, rtconfig.POST_ACTION)
  407. if GetOption('target') == 'mdk':
  408. from keil import MDKProject
  409. from keil import MDK4Project
  410. from keil import MDK5Project
  411. template = os.path.isfile('template.Uv2')
  412. if template:
  413. MDKProject('project.Uv2', Projects)
  414. else:
  415. template = os.path.isfile('template.uvproj')
  416. if template:
  417. MDK4Project('project.uvproj', Projects)
  418. else:
  419. template = os.path.isfile('template.uvprojx')
  420. if template:
  421. MDK5Project('project.uvprojx', Projects)
  422. else:
  423. print 'No template project file found.'
  424. if GetOption('target') == 'mdk4':
  425. from keil import MDK4Project
  426. MDK4Project('project.uvproj', Projects)
  427. if GetOption('target') == 'mdk5':
  428. from keil import MDK5Project
  429. MDK5Project('project.uvprojx', Projects)
  430. if GetOption('target') == 'iar':
  431. from iar import IARProject
  432. IARProject('project.ewp', Projects)
  433. if GetOption('target') == 'vs':
  434. from vs import VSProject
  435. VSProject('project.vcproj', Projects, program)
  436. if GetOption('target') == 'vs2012':
  437. from vs2012 import VS2012Project
  438. VS2012Project('project.vcxproj', Projects, program)
  439. if GetOption('target') == 'cb':
  440. from codeblocks import CBProject
  441. CBProject('project.cbp', Projects, program)
  442. if GetOption('target') == 'ua':
  443. from ua import PrepareUA
  444. PrepareUA(Projects, Rtt_Root, str(Dir('#')))
  445. if GetOption('copy') and program != None:
  446. MakeCopy(program)
  447. if GetOption('copy-header') and program != None:
  448. MakeCopyHeader(program)
  449. if GetOption('cscope'):
  450. from cscope import CscopeDatabase
  451. CscopeDatabase(Projects)
  452. def SrcRemove(src, remove):
  453. if not src:
  454. return
  455. if type(src[0]) == type('str'):
  456. for item in src:
  457. if os.path.basename(item) in remove:
  458. src.remove(item)
  459. return
  460. for item in src:
  461. if os.path.basename(item.rstr()) in remove:
  462. src.remove(item)
  463. def GetVersion():
  464. import SCons.cpp
  465. import string
  466. rtdef = os.path.join(Rtt_Root, 'include', 'rtdef.h')
  467. # parse rtdef.h to get RT-Thread version
  468. prepcessor = SCons.cpp.PreProcessor()
  469. f = file(rtdef, 'r')
  470. contents = f.read()
  471. f.close()
  472. prepcessor.process_contents(contents)
  473. def_ns = prepcessor.cpp_namespace
  474. version = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_VERSION']))
  475. subversion = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_SUBVERSION']))
  476. if def_ns.has_key('RT_REVISION'):
  477. revision = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_REVISION']))
  478. return '%d.%d.%d' % (version, subversion, revision)
  479. return '0.%d.%d' % (version, subversion)
  480. def GlobSubDir(sub_dir, ext_name):
  481. import os
  482. import glob
  483. def glob_source(sub_dir, ext_name):
  484. list = os.listdir(sub_dir)
  485. src = glob.glob(os.path.join(sub_dir, ext_name))
  486. for item in list:
  487. full_subdir = os.path.join(sub_dir, item)
  488. if os.path.isdir(full_subdir):
  489. src += glob_source(full_subdir, ext_name)
  490. return src
  491. dst = []
  492. src = glob_source(sub_dir, ext_name)
  493. for item in src:
  494. dst.append(os.path.relpath(item, sub_dir))
  495. return dst
  496. def file_path_exist(path, *args):
  497. return os.path.exists(os.path.join(path, *args))
  498. def do_rm_file(src):
  499. if os.path.exists(src):
  500. os.unlink(src)
  501. def do_copy_file(src, dst):
  502. import shutil
  503. # check source file
  504. if not os.path.exists(src):
  505. return
  506. path = os.path.dirname(dst)
  507. # mkdir if path not exist
  508. if not os.path.exists(path):
  509. os.makedirs(path)
  510. shutil.copy2(src, dst)
  511. def do_copy_folder(src_dir, dst_dir):
  512. import shutil
  513. # check source directory
  514. if not os.path.exists(src_dir):
  515. return
  516. if os.path.exists(dst_dir):
  517. shutil.rmtree(dst_dir)
  518. shutil.copytree(src_dir, dst_dir)
  519. source_ext = ["c", "h", "s", "S", "cpp", "xpm"]
  520. source_list = []
  521. def walk_children(child):
  522. global source_list
  523. global source_ext
  524. # print child
  525. full_path = child.rfile().abspath
  526. file_type = full_path.rsplit('.',1)[1]
  527. #print file_type
  528. if file_type in source_ext:
  529. if full_path not in source_list:
  530. source_list.append(full_path)
  531. children = child.all_children()
  532. if children != []:
  533. for item in children:
  534. walk_children(item)
  535. def MakeCopy(program):
  536. global source_list
  537. global Rtt_Root
  538. global Env
  539. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  540. if Env['PLATFORM'] == 'win32':
  541. RTT_ROOT = Rtt_Root.lower()
  542. else:
  543. RTT_ROOT = Rtt_Root
  544. if target_path.startswith(RTT_ROOT):
  545. return
  546. for item in program:
  547. walk_children(item)
  548. source_list.sort()
  549. # filte source file in RT-Thread
  550. target_list = []
  551. for src in source_list:
  552. if Env['PLATFORM'] == 'win32':
  553. src = src.lower()
  554. if src.startswith(RTT_ROOT):
  555. target_list.append(src)
  556. source_list = target_list
  557. # get source path
  558. src_dir = []
  559. for src in source_list:
  560. src = src.replace(RTT_ROOT, '')
  561. if src[0] == os.sep or src[0] == '/':
  562. src = src[1:]
  563. path = os.path.dirname(src)
  564. sub_path = path.split(os.sep)
  565. full_path = RTT_ROOT
  566. for item in sub_path:
  567. full_path = os.path.join(full_path, item)
  568. if full_path not in src_dir:
  569. src_dir.append(full_path)
  570. for item in src_dir:
  571. source_list.append(os.path.join(item, 'SConscript'))
  572. for src in source_list:
  573. dst = src.replace(RTT_ROOT, '')
  574. if dst[0] == os.sep or dst[0] == '/':
  575. dst = dst[1:]
  576. print '=> ', dst
  577. dst = os.path.join(target_path, dst)
  578. do_copy_file(src, dst)
  579. # copy tools directory
  580. print "=> tools"
  581. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  582. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  583. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
  584. def MakeCopyHeader(program):
  585. global source_ext
  586. source_ext = []
  587. source_ext = ["h", "xpm"]
  588. global source_list
  589. global Rtt_Root
  590. global Env
  591. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  592. if Env['PLATFORM'] == 'win32':
  593. RTT_ROOT = Rtt_Root.lower()
  594. else:
  595. RTT_ROOT = Rtt_Root
  596. if target_path.startswith(RTT_ROOT):
  597. return
  598. for item in program:
  599. walk_children(item)
  600. source_list.sort()
  601. # filte source file in RT-Thread
  602. target_list = []
  603. for src in source_list:
  604. if Env['PLATFORM'] == 'win32':
  605. src = src.lower()
  606. if src.startswith(RTT_ROOT):
  607. target_list.append(src)
  608. source_list = target_list
  609. for src in source_list:
  610. dst = src.replace(RTT_ROOT, '')
  611. if dst[0] == os.sep or dst[0] == '/':
  612. dst = dst[1:]
  613. print '=> ', dst
  614. dst = os.path.join(target_path, dst)
  615. do_copy_file(src, dst)
  616. # copy tools directory
  617. print "=> tools"
  618. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  619. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  620. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))