1#! /usr/bin/env python 2#coding=utf-8 3 4# 5# File : wizard.py 6# This file is part of RT-Thread RTOS 7# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team 8# 9# This program is free software; you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation; either version 2 of the License, or 12# (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License along 20# with this program; if not, write to the Free Software Foundation, Inc., 21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22# 23# Change Logs: 24# Date Author Notes 25# 2015-01-20 Bernard Add copyright information 26# 27 28""" 29wizard.py - a script to generate SConscript in RT-Thread RTOS. 30 31`wizard --component name' to generate SConscript for name component. 32`wizard --bridge' to generate SConscript as a bridge to connect each 33SConscript script file of sub-directory. 34""" 35 36import sys 37 38SConscript_com = '''# RT-Thread building script for component 39 40from building import * 41 42cwd = GetCurrentDir() 43src = Glob('*.c') + Glob('*.cpp') 44CPPPATH = [cwd] 45 46group = DefineGroup('COMPONENT_NAME', src, depend = [''], CPPPATH = CPPPATH) 47 48Return('group') 49''' 50 51SConscript_bridge = '''# RT-Thread building script for bridge 52 53import os 54from building import * 55 56cwd = GetCurrentDir() 57objs = [] 58list = os.listdir(cwd) 59 60for d in list: 61 path = os.path.join(cwd, d) 62 if os.path.isfile(os.path.join(path, 'SConscript')): 63 objs = objs + SConscript(os.path.join(d, 'SConscript')) 64 65Return('objs') 66''' 67 68def usage(): 69 print('wizard --component name') 70 print('wizard --bridge') 71 72def gen_component(name): 73 print('generate SConscript for ' + name) 74 text = SConscript_com.replace('COMPONENT_NAME', name) 75 f = open('SConscript', 'w') 76 f.write(text) 77 f.close() 78 79def gen_bridge(): 80 print('generate SConscript for bridge') 81 f = open('SConscript', 'w') 82 f.write(SConscript_bridge) 83 f.close() 84 85if __name__ == '__main__': 86 if len(sys.argv) == 1: 87 usage() 88 sys.exit(2) 89 90 if sys.argv[1] == '--component': 91 gen_component(sys.argv[2]) 92 elif sys.argv[1] == '--bridge': 93 gen_bridge() 94 else: 95 usage() 96