1# 2# File : ua.py 3# This file is part of RT-Thread RTOS 4# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License along 17# with this program; if not, write to the Free Software Foundation, Inc., 18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20# Change Logs: 21# Date Author Notes 22# 2015-01-20 Bernard Add copyright information 23# 24 25import os 26import sys 27from utils import _make_path_relative 28 29def PrefixPath(prefix, path): 30 path = os.path.abspath(path) 31 prefix = os.path.abspath(prefix) 32 33 if sys.platform == 'win32': 34 prefix = prefix.lower() 35 path = path.lower() 36 37 if path.startswith(prefix): 38 return True 39 40 return False 41 42def PrepareUA(project, RTT_ROOT, BSP_ROOT): 43 with open('rtua.py', 'w') as ua: 44 # ua.write('import os\n') 45 # ua.write('import sys\n') 46 ua.write('\n') 47 48 print RTT_ROOT 49 50 CPPPATH = [] 51 CPPDEFINES = [] 52 53 for group in project: 54 # get each include path 55 if 'CPPPATH' in group and group['CPPPATH']: 56 CPPPATH += group['CPPPATH'] 57 58 # get each group's definitions 59 if 'CPPDEFINES' in group and group['CPPDEFINES']: 60 CPPDEFINES += group['CPPDEFINES'] 61 62 if len(CPPPATH): 63 # use absolute path 64 for i in range(len(CPPPATH)): 65 CPPPATH[i] = os.path.abspath(CPPPATH[i]) 66 67 # remove repeat path 68 paths = [i for i in set(CPPPATH)] 69 CPPPATH = [] 70 for path in paths: 71 if PrefixPath(RTT_ROOT, path): 72 CPPPATH += ['RTT_ROOT + "/%s",' % _make_path_relative(RTT_ROOT, path).replace('\\', '/')] 73 74 elif PrefixPath(BSP_ROOT, path): 75 CPPPATH += ['BSP_ROOT + "/%s",' % _make_path_relative(BSP_ROOT, path).replace('\\', '/')] 76 else: 77 CPPPATH += ['"%s",' % path.replace('\\', '/')] 78 79 CPPPATH.sort() 80 ua.write('def GetCPPPATH(BSP_ROOT, RTT_ROOT):\n') 81 ua.write('\tCPPPATH=[\n') 82 for path in CPPPATH: 83 ua.write('\t\t%s\n' % path) 84 ua.write('\t]\n\n') 85 ua.write('\treturn CPPPATH\n\n') 86 else: 87 ua.write('def GetCPPPATH(BSP_ROOT, RTT_ROOT):\n') 88 ua.write('\tCPPPATH=[]\n\n') 89 ua.write('\treturn CPPPATH\n\n') 90 91 if len(CPPDEFINES): 92 CPPDEFINES = [i for i in set(CPPDEFINES)] 93 94 ua.write('def GetCPPDEFINES():\n') 95 ua.write('\tCPPDEFINES=%s\n' % str(CPPDEFINES)) 96 ua.write('\treturn CPPDEFINES\n\n') 97 98 else: 99 ua.write('def GetCPPDEFINES():\n') 100 ua.write('\tCPPDEFINES=""\n\n') 101 ua.write('\treturn CPPDEFINES\n\n') 102