building.py 23 KB

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