building.py 22 KB

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