building.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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. 'mdk5':('keil', 'armcc'),
  147. 'iar':('iar', 'iar'),
  148. 'vs':('msvc', 'cl'),
  149. 'vs2012':('msvc', 'cl'),
  150. 'cb':('keil', 'armcc'),
  151. 'ua':('keil', 'armcc')}
  152. tgt_name = GetOption('target')
  153. if tgt_name:
  154. # --target will change the toolchain settings which clang-analyzer is
  155. # depend on
  156. if GetOption('clang-analyzer'):
  157. print '--clang-analyzer cannot be used with --target'
  158. sys.exit(1)
  159. SetOption('no_exec', 1)
  160. try:
  161. rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
  162. except KeyError:
  163. print 'Unknow target: %s. Avaible targets: %s' % \
  164. (tgt_name, ', '.join(tgt_dict.keys()))
  165. sys.exit(1)
  166. elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
  167. and rtconfig.PLATFORM == 'gcc':
  168. AddDepend('RT_USING_MINILIBC')
  169. # add comstr option
  170. AddOption('--verbose',
  171. dest='verbose',
  172. action='store_true',
  173. default=False,
  174. help='print verbose information during build')
  175. if not GetOption('verbose'):
  176. # override the default verbose command string
  177. env.Replace(
  178. ARCOMSTR = 'AR $TARGET',
  179. ASCOMSTR = 'AS $TARGET',
  180. ASPPCOMSTR = 'AS $TARGET',
  181. CCCOMSTR = 'CC $TARGET',
  182. CXXCOMSTR = 'CXX $TARGET',
  183. LINKCOMSTR = 'LINK $TARGET'
  184. )
  185. # we need to seperate the variant_dir for BSPs and the kernels. BSPs could
  186. # have their own components etc. If they point to the same folder, SCons
  187. # would find the wrong source code to compile.
  188. bsp_vdir = 'build/bsp'
  189. kernel_vdir = 'build/kernel'
  190. # board build script
  191. objs = SConscript('SConscript', variant_dir=bsp_vdir, duplicate=0)
  192. # include kernel
  193. objs.extend(SConscript(Rtt_Root + '/src/SConscript', variant_dir=kernel_vdir + '/src', duplicate=0))
  194. # include libcpu
  195. if not has_libcpu:
  196. objs.extend(SConscript(Rtt_Root + '/libcpu/SConscript',
  197. variant_dir=kernel_vdir + '/libcpu', duplicate=0))
  198. # include components
  199. objs.extend(SConscript(Rtt_Root + '/components/SConscript',
  200. variant_dir=kernel_vdir + '/components',
  201. duplicate=0,
  202. exports='remove_components'))
  203. return objs
  204. def PrepareModuleBuilding(env, root_directory):
  205. import rtconfig
  206. global Env
  207. global Rtt_Root
  208. Env = env
  209. Rtt_Root = root_directory
  210. # add build/clean library option for library checking
  211. AddOption('--buildlib',
  212. dest='buildlib',
  213. type='string',
  214. help='building library of a component')
  215. AddOption('--cleanlib',
  216. dest='cleanlib',
  217. action='store_true',
  218. default=False,
  219. help='clean up the library by --buildlib')
  220. # add program path
  221. env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
  222. def GetConfigValue(name):
  223. assert type(name) == str, 'GetConfigValue: only string parameter is valid'
  224. try:
  225. return BuildOptions[name]
  226. except:
  227. return ''
  228. def GetDepend(depend):
  229. building = True
  230. if type(depend) == type('str'):
  231. if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0:
  232. building = False
  233. elif BuildOptions[depend] != '':
  234. return BuildOptions[depend]
  235. return building
  236. # for list type depend
  237. for item in depend:
  238. if item != '':
  239. if not BuildOptions.has_key(item) or BuildOptions[item] == 0:
  240. building = False
  241. return building
  242. def AddDepend(option):
  243. BuildOptions[option] = 1
  244. def MergeGroup(src_group, group):
  245. src_group['src'] = src_group['src'] + group['src']
  246. if group.has_key('CCFLAGS'):
  247. if src_group.has_key('CCFLAGS'):
  248. src_group['CCFLAGS'] = src_group['CCFLAGS'] + group['CCFLAGS']
  249. else:
  250. src_group['CCFLAGS'] = group['CCFLAGS']
  251. if group.has_key('CPPPATH'):
  252. if src_group.has_key('CPPPATH'):
  253. src_group['CPPPATH'] = src_group['CPPPATH'] + group['CPPPATH']
  254. else:
  255. src_group['CPPPATH'] = group['CPPPATH']
  256. if group.has_key('CPPDEFINES'):
  257. if src_group.has_key('CPPDEFINES'):
  258. src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
  259. else:
  260. src_group['CPPDEFINES'] = group['CPPDEFINES']
  261. if group.has_key('LINKFLAGS'):
  262. if src_group.has_key('LINKFLAGS'):
  263. src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
  264. else:
  265. src_group['LINKFLAGS'] = group['LINKFLAGS']
  266. if group.has_key('LIBS'):
  267. if src_group.has_key('LIBS'):
  268. src_group['LIBS'] = src_group['LIBS'] + group['LIBS']
  269. else:
  270. src_group['LIBS'] = group['LIBS']
  271. if group.has_key('LIBPATH'):
  272. if src_group.has_key('LIBPATH'):
  273. src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
  274. else:
  275. src_group['LIBPATH'] = group['LIBPATH']
  276. def DefineGroup(name, src, depend, **parameters):
  277. global Env
  278. if not GetDepend(depend):
  279. return []
  280. # find exist group and get path of group
  281. group_path = ''
  282. for g in Projects:
  283. if g['name'] == name:
  284. group_path = g['path']
  285. if group_path == '':
  286. group_path = GetCurrentDir()
  287. group = parameters
  288. group['name'] = name
  289. group['path'] = group_path
  290. if type(src) == type(['src1']):
  291. group['src'] = File(src)
  292. else:
  293. group['src'] = src
  294. if group.has_key('CCFLAGS'):
  295. Env.Append(CCFLAGS = group['CCFLAGS'])
  296. if group.has_key('CPPPATH'):
  297. Env.Append(CPPPATH = group['CPPPATH'])
  298. if group.has_key('CPPDEFINES'):
  299. Env.Append(CPPDEFINES = group['CPPDEFINES'])
  300. if group.has_key('LINKFLAGS'):
  301. Env.Append(LINKFLAGS = group['LINKFLAGS'])
  302. # check whether to clean up library
  303. if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  304. if group['src'] != []:
  305. print 'Remove library:', GroupLibFullName(name, Env)
  306. do_rm_file(os.path.join(group['path'], GroupLibFullName(name, Env)))
  307. # check whether exist group library
  308. if not GetOption('buildlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
  309. group['src'] = []
  310. if group.has_key('LIBS'): group['LIBS'] = group['LIBS'] + [GroupLibName(name, Env)]
  311. else : group['LIBS'] = [GroupLibName(name, Env)]
  312. if group.has_key('LIBPATH'): group['LIBPATH'] = group['LIBPATH'] + [GetCurrentDir()]
  313. else : group['LIBPATH'] = [GetCurrentDir()]
  314. if group.has_key('LIBS'):
  315. Env.Append(LIBS = group['LIBS'])
  316. if group.has_key('LIBPATH'):
  317. Env.Append(LIBPATH = group['LIBPATH'])
  318. if group.has_key('LIBRARY'):
  319. objs = Env.Library(name, group['src'])
  320. else:
  321. objs = group['src']
  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. program = Env.Program(target, objects)
  380. EndBuilding(target, program)
  381. def EndBuilding(target, program = None):
  382. import rtconfig
  383. Env.AddPostAction(target, rtconfig.POST_ACTION)
  384. if GetOption('target') == 'mdk':
  385. from keil import MDKProject
  386. from keil import MDK4Project
  387. from keil import MDK5Project
  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. template = os.path.isfile('template.uvprojx')
  397. if template:
  398. MDK5Project('project.uvprojx', Projects)
  399. else:
  400. print 'No template project file found.'
  401. if GetOption('target') == 'mdk4':
  402. from keil import MDK4Project
  403. MDK4Project('project.uvproj', Projects)
  404. if GetOption('target') == 'mdk5':
  405. from keil import MDK5Project
  406. MDK5Project('project.uvprojx', Projects)
  407. if GetOption('target') == 'iar':
  408. from iar import IARProject
  409. IARProject('project.ewp', Projects)
  410. if GetOption('target') == 'vs':
  411. from vs import VSProject
  412. VSProject('project.vcproj', Projects, program)
  413. if GetOption('target') == 'vs2012':
  414. from vs2012 import VS2012Project
  415. VS2012Project('project.vcxproj', Projects, program)
  416. if GetOption('target') == 'cb':
  417. from codeblocks import CBProject
  418. CBProject('project.cbp', Projects, program)
  419. if GetOption('target') == 'ua':
  420. from ua import PrepareUA
  421. PrepareUA(Projects, Rtt_Root, str(Dir('#')))
  422. if GetOption('copy') and program != None:
  423. MakeCopy(program)
  424. if GetOption('copy-header') and program != None:
  425. MakeCopyHeader(program)
  426. if GetOption('cscope'):
  427. from cscope import CscopeDatabase
  428. CscopeDatabase(Projects)
  429. def SrcRemove(src, remove):
  430. if not src:
  431. return
  432. if type(src[0]) == type('str'):
  433. for item in src:
  434. if os.path.basename(item) in remove:
  435. src.remove(item)
  436. return
  437. for item in src:
  438. if os.path.basename(item.rstr()) in remove:
  439. src.remove(item)
  440. def GetVersion():
  441. import SCons.cpp
  442. import string
  443. rtdef = os.path.join(Rtt_Root, 'include', 'rtdef.h')
  444. # parse rtdef.h to get RT-Thread version
  445. prepcessor = SCons.cpp.PreProcessor()
  446. f = file(rtdef, 'r')
  447. contents = f.read()
  448. f.close()
  449. prepcessor.process_contents(contents)
  450. def_ns = prepcessor.cpp_namespace
  451. version = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_VERSION']))
  452. subversion = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_SUBVERSION']))
  453. if def_ns.has_key('RT_REVISION'):
  454. revision = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_REVISION']))
  455. return '%d.%d.%d' % (version, subversion, revision)
  456. return '0.%d.%d' % (version, subversion)
  457. def GlobSubDir(sub_dir, ext_name):
  458. import os
  459. import glob
  460. def glob_source(sub_dir, ext_name):
  461. list = os.listdir(sub_dir)
  462. src = glob.glob(os.path.join(sub_dir, ext_name))
  463. for item in list:
  464. full_subdir = os.path.join(sub_dir, item)
  465. if os.path.isdir(full_subdir):
  466. src += glob_source(full_subdir, ext_name)
  467. return src
  468. dst = []
  469. src = glob_source(sub_dir, ext_name)
  470. for item in src:
  471. dst.append(os.path.relpath(item, sub_dir))
  472. return dst
  473. def file_path_exist(path, *args):
  474. return os.path.exists(os.path.join(path, *args))
  475. def do_rm_file(src):
  476. if os.path.exists(src):
  477. os.unlink(src)
  478. def do_copy_file(src, dst):
  479. import shutil
  480. # check source file
  481. if not os.path.exists(src):
  482. return
  483. path = os.path.dirname(dst)
  484. # mkdir if path not exist
  485. if not os.path.exists(path):
  486. os.makedirs(path)
  487. shutil.copy2(src, dst)
  488. def do_copy_folder(src_dir, dst_dir):
  489. import shutil
  490. # check source directory
  491. if not os.path.exists(src_dir):
  492. return
  493. if os.path.exists(dst_dir):
  494. shutil.rmtree(dst_dir)
  495. shutil.copytree(src_dir, dst_dir)
  496. source_ext = ["c", "h", "s", "S", "cpp", "xpm"]
  497. source_list = []
  498. def walk_children(child):
  499. global source_list
  500. global source_ext
  501. # print child
  502. full_path = child.rfile().abspath
  503. file_type = full_path.rsplit('.',1)[1]
  504. #print file_type
  505. if file_type in source_ext:
  506. if full_path not in source_list:
  507. source_list.append(full_path)
  508. children = child.all_children()
  509. if children != []:
  510. for item in children:
  511. walk_children(item)
  512. def MakeCopy(program):
  513. global source_list
  514. global Rtt_Root
  515. global Env
  516. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  517. if Env['PLATFORM'] == 'win32':
  518. RTT_ROOT = Rtt_Root.lower()
  519. else:
  520. RTT_ROOT = Rtt_Root
  521. if target_path.startswith(RTT_ROOT):
  522. return
  523. for item in program:
  524. walk_children(item)
  525. source_list.sort()
  526. # filte source file in RT-Thread
  527. target_list = []
  528. for src in source_list:
  529. if Env['PLATFORM'] == 'win32':
  530. src = src.lower()
  531. if src.startswith(RTT_ROOT):
  532. target_list.append(src)
  533. source_list = target_list
  534. # get source path
  535. src_dir = []
  536. for src in source_list:
  537. src = src.replace(RTT_ROOT, '')
  538. if src[0] == os.sep or src[0] == '/':
  539. src = src[1:]
  540. path = os.path.dirname(src)
  541. sub_path = path.split(os.sep)
  542. full_path = RTT_ROOT
  543. for item in sub_path:
  544. full_path = os.path.join(full_path, item)
  545. if full_path not in src_dir:
  546. src_dir.append(full_path)
  547. for item in src_dir:
  548. source_list.append(os.path.join(item, 'SConscript'))
  549. for src in source_list:
  550. dst = src.replace(RTT_ROOT, '')
  551. if dst[0] == os.sep or dst[0] == '/':
  552. dst = dst[1:]
  553. print '=> ', dst
  554. dst = os.path.join(target_path, dst)
  555. do_copy_file(src, dst)
  556. # copy tools directory
  557. print "=> tools"
  558. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  559. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  560. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
  561. def MakeCopyHeader(program):
  562. global source_ext
  563. source_ext = []
  564. source_ext = ["h", "xpm"]
  565. global source_list
  566. global Rtt_Root
  567. global Env
  568. target_path = os.path.join(Dir('#').abspath, 'rt-thread')
  569. if Env['PLATFORM'] == 'win32':
  570. RTT_ROOT = Rtt_Root.lower()
  571. else:
  572. RTT_ROOT = Rtt_Root
  573. if target_path.startswith(RTT_ROOT):
  574. return
  575. for item in program:
  576. walk_children(item)
  577. source_list.sort()
  578. # filte source file in RT-Thread
  579. target_list = []
  580. for src in source_list:
  581. if Env['PLATFORM'] == 'win32':
  582. src = src.lower()
  583. if src.startswith(RTT_ROOT):
  584. target_list.append(src)
  585. source_list = target_list
  586. for src in source_list:
  587. dst = src.replace(RTT_ROOT, '')
  588. if dst[0] == os.sep or dst[0] == '/':
  589. dst = dst[1:]
  590. print '=> ', dst
  591. dst = os.path.join(target_path, dst)
  592. do_copy_file(src, dst)
  593. # copy tools directory
  594. print "=> tools"
  595. do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
  596. do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
  597. do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))