building.py 22 KB

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