| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- # File : ua.py
- # Tool Script for building User Applications
- # This file is part of RT-Thread RTOS
- # COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License along
- # with this program; if not, write to the Free Software Foundation, Inc.,
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- #
- # Change Logs:
- # Date Author Notes
- # 2015-02-07 Bernard The firstly version
- #
- import os
- import sys
- from SCons.Script import *
- Rtt_Root = ''
- BSP_Root = ''
- Env = None
- def BuildEnv(BSP_ROOT, RTT_ROOT):
- if BSP_ROOT == None:
- if os.getenv('BSP_ROOT'):
- BSP_ROOT = os.getenv('BSP_ROOT')
- else:
- print 'Please set BSP(board support package) directory!'
- exit(-1)
- if not os.path.exists(BSP_ROOT):
- print 'No BSP(board support package) directory found!'
- exit(-1)
- if RTT_ROOT == None:
- # get RTT_ROOT from BSP_ROOT
- sys.path = sys.path + [BSP_ROOT]
- try:
- import rtconfig
- RTT_ROOT = rtconfig.RTT_ROOT
- except Exception as e:
- print 'Import rtconfig.py in BSP(board support package) failed.'
- print e
- exit(-1)
- global Rtt_Root
- global BSP_Root
- Rtt_Root = RTT_ROOT
- BSP_Root = BSP_ROOT
- def BuildHostApplication(TARGET, SConscriptFile):
- import platform
- platform_type = platform.system()
- if platform_type == 'Windows' or platform_type.find('MINGW') != -1:
- TARGET = TARGET.replace('.mo', '.exe')
- sys.path = sys.path + [os.path.join(os.getcwd(), 'tools', 'host')]
- from building import PrepareHostModuleBuilding
- HostRtt = os.path.join(os.getcwd(), 'tools', 'host', 'rtthread')
- Env = Environment()
- if not GetOption('verbose'):
- # override the default verbose command string
- Env.Replace(
- ARCOMSTR = 'AR $TARGET',
- ASCOMSTR = 'AS $TARGET',
- ASPPCOMSTR = 'AS $TARGET',
- CCCOMSTR = 'CC $TARGET',
- CXXCOMSTR = 'CXX $TARGET',
- LINKCOMSTR = 'LINK $TARGET'
- )
- PrepareHostModuleBuilding(Env)
- objs = SConscript(SConscriptFile)
- objs += SConscript(HostRtt + '/SConscript')
- target = Env.Program(TARGET, objs)
- return
- def BuildHostLibrary(TARGET, SConscriptFile):
- import platform
- platform_type = platform.system()
- if platform_type == 'Windows' or platform_type.find('MINGW') != -1:
- TARGET = TARGET.replace('.mo', '.exe')
- sys.path = sys.path + [os.path.join(os.getcwd(), 'tools', 'host')]
- from building import PrepareHostModuleBuilding
- HostRtt = os.path.join(os.getcwd(), 'tools', 'host', 'rtthread')
- Env = Environment()
- if not GetOption('verbose'):
- # override the default verbose command string
- Env.Replace(
- ARCOMSTR = 'AR $TARGET',
- ASCOMSTR = 'AS $TARGET',
- ASPPCOMSTR = 'AS $TARGET',
- CCCOMSTR = 'CC $TARGET',
- CXXCOMSTR = 'CXX $TARGET',
- LINKCOMSTR = 'LINK $TARGET'
- )
- PrepareHostModuleBuilding(Env)
- objs = SConscript(SConscriptFile)
- objs += SConscript(HostRtt + '/SConscript')
- target = Env.Program(TARGET, objs)
- return
- def BuildApplication(TARGET, SConscriptFile, BSP_ROOT = None, RTT_ROOT = None):
- global Env
- global Rtt_Root
- global BSP_Root
- # add comstr option
- AddOption('--verbose',
- dest='verbose',
- action='store_true',
- default=False,
- help='print verbose information during build')
- # build application in host
- if BSP_ROOT == None and RTT_ROOT == None and not os.getenv('BSP_ROOT'):
- BuildHostApplication(TARGET, SConscriptFile)
- return
- if RTT_ROOT == None and os.getenv('RTT_ROOT'):
- RTT_ROOT = os.getenv('RTT_ROOT')
- # handle BSP_ROOT and RTT_ROOT
- BuildEnv(BSP_ROOT, RTT_ROOT)
- sys.path = sys.path + [os.path.join(Rtt_Root, 'tools'), BSP_Root]
- # get configuration from BSP
- import rtconfig
- from rtua import GetCPPPATH
- from rtua import GetCPPDEFINES
- from building import PrepareModuleBuilding
- from eclipse import TargetEclipse
- CPPPATH = GetCPPPATH(BSP_Root, Rtt_Root)
- cflags = rtconfig.CFLAGS + ' -mlong-calls -fPIC '
- Env = Environment(tools = ['mingw'],
- AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
- CC = rtconfig.CC, CCFLAGS = cflags,
- CPPDEFINES = GetCPPDEFINES(),
- CXX = rtconfig.CXX, AR = rtconfig.AR, ARFLAGS = '-rc',
- LINK = rtconfig.LINK, LINKFLAGS = cflags + '-Wl,-z,max-page-size=0x4 -nostartfiles -nostdlib -static-libgcc -shared -e main',
- CPPPATH = CPPPATH)
- if not GetOption('verbose'):
- # override the default verbose command string
- Env.Replace(
- ARCOMSTR = 'AR $TARGET',
- ASCOMSTR = 'AS $TARGET',
- ASPPCOMSTR = 'AS $TARGET',
- CCCOMSTR = 'CC $TARGET',
- CXXCOMSTR = 'CXX $TARGET',
- LINKCOMSTR = 'LINK $TARGET'
- )
- PrepareModuleBuilding(Env, Rtt_Root, BSP_Root)
- objs = SConscript(SConscriptFile)
- need_exit = False
- # build program
- target = Env.Program(TARGET, objs)
- Env['target'] = target
- basename = os.path.basename(TARGET)
- if GetOption('target') == 'eclipse':
- from eclipse import TargetEclipse
- TargetEclipse(Env, GetOption('reset-project-config'), basename.split(".")[0])
- need_exit = True
-
- if hasattr(rtconfig, 'M_POST_ACTION'):
- Env.AddPostAction(target, rtconfig.M_POST_ACTION)
- if hasattr(rtconfig, 'M_BIN_PATH'):
- Env.AddPostAction(target, [Copy(rtconfig.M_BIN_PATH, TARGET)])
- if need_exit:
- exit(0)
- def BuildLibrary(TARGET, SConscriptFile, BSP_ROOT = None, RTT_ROOT = None):
- global Env
- global Rtt_Root
- global BSP_Root
- # add comstr option
- AddOption('--verbose',
- dest='verbose',
- action='store_true',
- default=False,
- help='print verbose information during build')
- # build application in host
- if BSP_ROOT == None and RTT_ROOT == None and not os.getenv('BSP_ROOT'):
- BuildHostLibrary(TARGET, SConscriptFile)
- return
- if RTT_ROOT == None and os.getenv('RTT_ROOT'):
- RTT_ROOT = os.getenv('RTT_ROOT')
- # handle BSP_ROOT and RTT_ROOT
- BuildEnv(BSP_ROOT, RTT_ROOT)
- sys.path = sys.path + [os.path.join(Rtt_Root, 'tools'), BSP_Root]
- # get configuration from BSP
- import rtconfig
- from rtua import GetCPPPATH
- from rtua import GetCPPDEFINES
- from building import PrepareModuleBuilding
- linkflags = rtconfig.M_LFLAGS + ' -e 0'
- CPPPATH = GetCPPPATH(BSP_Root, Rtt_Root)
- Env = Environment(tools = ['mingw'],
- AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
- CC = rtconfig.CC, CCFLAGS = rtconfig.M_CFLAGS,
- CPPDEFINES = GetCPPDEFINES(),
- CXX = rtconfig.CXX, AR = rtconfig.AR, ARFLAGS = '-rc',
- LINK = rtconfig.LINK, LINKFLAGS = linkflags,
- CPPPATH = CPPPATH)
- if not GetOption('verbose'):
- # override the default verbose command string
- Env.Replace(
- ARCOMSTR = 'AR $TARGET',
- ASCOMSTR = 'AS $TARGET',
- ASPPCOMSTR = 'AS $TARGET',
- CCCOMSTR = 'CC $TARGET',
- CXXCOMSTR = 'CXX $TARGET',
- LINKCOMSTR = 'LINK $TARGET'
- )
- PrepareModuleBuilding(Env, Rtt_Root, BSP_Root)
- objs = SConscript(SConscriptFile)
- # build program
- target = Env.Program(TARGET, objs)
- if hasattr(rtconfig, 'M_POST_ACTION'):
- Env.AddPostAction(target, rtconfig.M_POST_ACTION)
|