building.py 22 KB

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