1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Use more of SCons handling for adding preprocessor defines & validation.

This commit is contained in:
James Snyder 2010-05-10 23:05:55 +00:00
parent a8bacf78ce
commit ea64e2b7d3
2 changed files with 126 additions and 117 deletions

View File

@ -1,6 +1,5 @@
import os, sys, shutil, string import os, sys, shutil, string
# Helper: "normalize" a name to make it a suitable C macro name # Helper: "normalize" a name to make it a suitable C macro name
def cnorm( name ): def cnorm( name ):
name = name.replace( '-', '' ) name = name.replace( '-', '' )
@ -147,7 +146,57 @@ file_list = { 'SAM7-EX256' : [ 'bisect', 'hangman' , 'led', 'piano', 'hello', 'i
'MBED' : [ 'bisect', 'hangman', 'hello', 'info', 'led', 'pwmled', 'dualpwm', 'life' ], 'MBED' : [ 'bisect', 'hangman', 'hello', 'info', 'led', 'pwmled', 'dualpwm', 'life' ],
} }
comp = Environment( OBJSUFFIX = ".o", PROGSUFFIX = ".elf", ENV = os.environ ) # define terminal colors
colors = {}
colors['cyan'] = '\033[96m'
colors['purple'] = '\033[95m'
colors['blue'] = '\033[94m'
colors['green'] = '\033[92m'
colors['yellow'] = '\033[93m'
colors['red'] = '\033[91m'
colors['end'] = '\033[0m'
#If the output is not a terminal, remove the colors
if not sys.stdout.isatty():
for key, value in colors.iteritems():
colors[key] = ''
compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % \
(colors['blue'], colors['purple'], colors['yellow'], colors['end'])
compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % \
(colors['blue'], colors['purple'], colors['yellow'], colors['end'])
link_program_message = '%sLinking Image %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
link_library_message = '%sLinking Static Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
ranlib_library_message = '%sRanlib Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
link_shared_library_message = '%sLinking Shared Library %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
java_library_message = '%sCreating Java Archive %s==> %s$TARGET%s' % \
(colors['red'], colors['purple'], colors['yellow'], colors['end'])
comp = Environment( OBJSUFFIX = ".o",
PROGSUFFIX = ".elf",
ENV = os.environ,
CPPDEFINES = {},
CXXCOMSTR = compile_source_message,
CCCOMSTR = compile_source_message,
SHCCCOMSTR = compile_shared_source_message,
SHCXXCOMSTR = compile_shared_source_message,
ARCOMSTR = link_library_message,
RANLIBCOMSTR = ranlib_library_message,
SHLINKCOMSTR = link_shared_library_message,
LINKCOMSTR = link_program_message,
JARCOMSTR = java_library_message,
JAVACCOMSTR = compile_source_message )
# Replacement for standard EnumVariable functionality to derive case from original list # Replacement for standard EnumVariable functionality to derive case from original list
class InsensitiveString(object): class InsensitiveString(object):
@ -176,59 +225,42 @@ def MatchEnumVariable(key, help, default, allowed_values, map={}):
# Add Configurable Variables # Add Configurable Variables
vars = Variables('build-setup.conf') vars = Variables('build-setup.conf')
vars.Add(MatchEnumVariable('target', vars.AddVariables(MatchEnumVariable('target',
'build "regular" float lua or integer-only "lualong"', 'build "regular" float lua or integer-only "lualong"',
'lua', 'lua',
allowed_values = ['lua','lualong'])) allowed_values = [ 'lua', 'lualong' ] ),
MatchEnumVariable('cpu',
vars.Add(MatchEnumVariable('cpu',
'build for the specified CPU (board will be inferred, if possible)', 'build for the specified CPU (board will be inferred, if possible)',
'auto', 'auto',
allowed_values = cpu_list + ['auto'])) allowed_values = cpu_list + [ 'auto' ] ),
MatchEnumVariable('allocator',
vars.Add(MatchEnumVariable('allocator',
'select memory allocator', 'select memory allocator',
'auto', 'auto',
allowed_values=['newlib','multiple','simple','auto'])) allowed_values=[ 'newlib', 'multiple', 'simple', 'auto' ] ),
MatchEnumVariable('board',
vars.Add(MatchEnumVariable('board',
'selects board for target (cpu will be inferred)', 'selects board for target (cpu will be inferred)',
'auto', 'auto',
allowed_values=board_list.keys() + ['auto'])) allowed_values=board_list.keys() + [ 'auto' ] ),
MatchEnumVariable('toolchain',
vars.Add(MatchEnumVariable('toolchain', 'specifies toolchain to use (auto=search for usable toolchain)',
'specifies toolchain to use (if unset, will scan for working, compatible toolchain',
'auto', 'auto',
allowed_values=toolchain_list.keys() + ['auto'])) allowed_values=toolchain_list.keys() + [ 'auto' ] ),
BoolVariable( 'optram',
vars.Add(BoolVariable('optram',
'enables Lua Tiny RAM enhancements', 'enables Lua Tiny RAM enhancements',
True)) True ),
MatchEnumVariable('boot',
vars.Add(MatchEnumVariable('boot',
'boot mode, standard will boot to shell, luarpc boots to an rpc server', 'boot mode, standard will boot to shell, luarpc boots to an rpc server',
'standard', 'standard',
allowed_values=['standard','luarpc'])) allowed_values=[ 'standard' , 'luarpc' ] ),
MatchEnumVariable('romfs',
vars.Add(MatchEnumVariable('romfs',
'ROMFS compilation mode', 'ROMFS compilation mode',
'verbatim', 'verbatim',
allowed_values=[ 'verbatim' , 'compress', 'compiled' ] ) ) allowed_values=[ 'verbatim' , 'compress', 'compiled' ] ) )
vars.Update(comp) vars.Update(comp)
Help(vars.GenerateHelpText(comp))
vars.Save('build-setup.conf', comp) vars.Save('build-setup.conf', comp)
# target = ARGUMENTS.get( 'target', 'lua' ).lower()
# cputype = ARGUMENTS.get( 'cpu', '' ).upper()
# allocator = ARGUMENTS.get( 'allocator', '' ).lower()
# board = ARGUMENTS.get( 'board' , '').upper()
# toolchain = ARGUMENTS.get( 'toolchain', '')
# optram = int( ARGUMENTS.get( 'optram', '1' ) )
# boot = ARGUMENTS.get( 'boot', '').lower()
# romfsmode = ARGUMENTS.get( 'romfs', 'verbatim' ).lower()
if not GetOption( 'help' ): if not GetOption( 'help' ):
conf = Configure(comp) conf = Configure(comp)
@ -240,20 +272,12 @@ if not GetOption( 'help' ):
print "Must specifiy board, cpu, or both" print "Must specifiy board, cpu, or both"
Exit( -1 ) Exit( -1 )
elif comp['board'] != 'auto' and comp['cpu'] != 'auto': elif comp['board'] != 'auto' and comp['cpu'] != 'auto':
# board = <board> cpu=<cpuname>
# Check if the board, cpu pair is correct # Check if the board, cpu pair is correct
if not board_list.has_key( comp['board'] ):
print "Unknown board", comp['board']
Exit( -1 )
if not comp['cpu'] in board_list[ comp['board'] ]: if not comp['cpu'] in board_list[ comp['board'] ]:
print "Invalid CPU %s for board %s" % ( comp['cpu'], comp['board'] ) print "Invalid CPU %s for board %s" % ( comp['cpu'], comp['board'] )
Exit( -1 ) Exit( -1 )
elif comp['board'] != 'auto': elif comp['board'] != 'auto':
# board = <board>
# Find CPU # Find CPU
if not board_list.has_key( comp['board'] ):
print "Unknown board", comp['board']
Exit( -1 )
comp['cpu'] = board_list[ comp['board'] ][ 0 ] comp['cpu'] = board_list[ comp['board'] ][ 0 ]
else: else:
# cpu = <cputype> # cpu = <cputype>
@ -280,7 +304,7 @@ if not GetOption( 'help' ):
for cpu in v[ 'cpus' ]: for cpu in v[ 'cpus' ]:
print cpu, print cpu,
print print
sys.exit( -1 ) Exit( -1 )
# Check the toolchain # Check the toolchain
if comp['toolchain'] != 'auto': if comp['toolchain'] != 'auto':
@ -289,40 +313,25 @@ if not GetOption( 'help' ):
Exit( -1 ) Exit( -1 )
toolset = toolchain_list[ comp['toolchain'] ] toolset = toolchain_list[ comp['toolchain'] ]
else: else:
for toolchain in platform_list[ platform ]['toolchains']: # if 'auto' try to match a working toolchain with target
comp['CC'] = toolchain_list[ toolchain ][ 'compile' ] usable_chains = [toolchain_list[ toolchain ][ 'compile' ] for toolchain in platform_list[ platform ]['toolchains']]
if conf.CheckCC(): comp['CC'] = comp.Detect( usable_chains )
comp['toolchain'] = toolchain if comp['CC']:
comp['AS'] = toolchain_list[ toolchain ][ 'asm' ]
comp['toolchain'] = platform_list[ platform ]['toolchains'][usable_chains.index(comp['CC'])]
toolset = toolchain_list[ comp['toolchain'] ] toolset = toolchain_list[ comp['toolchain'] ]
break else:
print "Unable to find usable toolchain in your path."
if comp['toolchain'] == 'auto': print "List of accepted toolchains (for %s):" % ( comp['cpu'] )
print "No available, compatible toolchain found" print ', '.join(usable_chains)
Exit( -1 ) Exit( -1 )
# CPU/allocator mapping (if allocator not specified) # CPU/allocator mapping (if allocator not specified)
if comp['allocator'] == 'auto': if comp['allocator'] == 'auto':
if comp['board'] in ['LPC-H2888', 'ATEVK1100', 'MBED']: if comp['board'] in ['LPC-H2888', 'ATEVK1100', 'MBED']:
comp['allocator'] = 'multiple' comp['allocator'] = 'multiple'
else: else:
comp['allocator'] = 'newlib' comp['allocator'] = 'newlib'
elif comp['allocator'] not in [ 'newlib', 'multiple', 'simple' ]:
print "Unknown allocator", comp['allocator']
print "Allocator can be either 'newlib', 'multiple' or 'simple'"
Exit( -1 )
# Check boot mode selection
## if comp['boot'] not in ['standard', 'luarpc']:
## print "Unknown boot mode: ", comp['boot']
## print "Boot mode can be either 'standard' or 'luarpc'"
## Exit( -1 );
# Check romfs mode
if comp['romfs'] not in ['verbatim', 'compile', 'compress']:
print "Unknown romfs mode: ", comp['romfs']
print "romfs mode can be either 'verbatim', 'compile' or 'compress'"
Exit( -1 )
# Build the compilation command now # Build the compilation command now
compcmd = '' compcmd = ''
@ -353,36 +362,36 @@ if not GetOption( 'help' ):
print print
output = 'elua_' + comp['target'] + '_' + comp['cpu'].lower() output = 'elua_' + comp['target'] + '_' + comp['cpu'].lower()
cdefs = '-DELUA_CPU=%s -DELUA_BOARD=%s -DELUA_PLATFORM=%s -D__BUFSIZ__=128' % ( comp['cpu'], comp['board'], platform.upper() )
comp.Append(CPPDEFINES = {'__BUFSIZ__' : 128})
# Also make the above into direct defines (to use in conditional C code) # Also make the above into direct defines (to use in conditional C code)
cdefs = cdefs + " -DELUA_CPU_%s -DELUA_BOARD_%s -DELUA_PLATFORM_%s" % ( cnorm( comp['cpu'] ), cnorm( comp['board'] ), cnorm( platform ) ) comp.Append(CPPDEFINES = ["ELUA_CPU_" + cnorm( comp['cpu'] ), "ELUA_BOARD_" + cnorm( comp['board'] ), "ELUA_PLATFORM_" + cnorm( platform )])
if comp['allocator'] == 'multiple': if comp['allocator'] == 'multiple':
cdefs = cdefs + " -DUSE_MULTIPLE_ALLOCATOR" comp.Append(CPPDEFINES = ['USE_MULTIPLE_ALLOCATOR'])
elif comp['allocator'] == 'simple': elif comp['allocator'] == 'simple':
cdefs = cdefs + " -DUSE_SIMPLE_ALLOCATOR" comp.Append(CPPDEFINES = ['USE_SIMPLE_ALLOCATOR'])
if comp['boot'] == 'luarpc': if comp['boot'] == 'luarpc':
cdefs += " -DELUA_BOOT_RPC" comp.Append(CPPDEFINES = ['ELUA_BOOT_RPC'])
# Special macro definitions for the SYM target # Special macro definitions for the SYM target
if platform == 'sim': if platform == 'sim':
cdefs = cdefs + " -DELUA_SIMULATOR -DELUA_SIM_%s" % comp['cpu'] comp.Append(CPPDEFINES = ['ELUA_SIMULATOR',"ELUA_SIM_" + cnorm( comp['cpu'] ) ] )
# Lua source files and include path # Lua source files and include path
lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c
ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c lua.c lrotable.c legc.c""" ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c lua.c lrotable.c legc.c"""
if comp['target'] == 'lualong' or comp['target'] == 'lua':
lua_full_files = " " + " ".join( [ "src/lua/%s" % name for name in lua_files.split() ] )
local_include = ['inc', 'inc/newlib', 'inc/remotefs', 'src/lua']
if comp['target'] == 'lualong':
cdefs = cdefs + ' -DLUA_NUMBER_INTEGRAL'
else:
print "Invalid target", comp['target']
Exit( 1 )
local_include += ['src/modules', 'src/platform/%s' % platform] lua_full_files = " " + " ".join( [ "src/lua/%s" % name for name in lua_files.split() ] )
cdefs = cdefs + " -DLUA_OPTIMIZE_MEMORY=%d" % ( comp['optram'] != 0 and 2 or 0 )
comp.Append(CPPPATH = ['inc', 'inc/newlib', 'inc/remotefs', 'src/lua'])
if comp['target'] == 'lualong':
comp.Append(CPPDEFINES = ['LUA_NUMBER_INTEGRAL'])
comp.Append(CPPPATH = ['src/modules', 'src/platform/%s' % platform])
comp.Append(CPPDEFINES = {"LUA_OPTIMIZE_MEMORY" : ( comp['optram'] != 0 and 2 or 0 ) } )
# Additional libraries # Additional libraries
local_libs = '' local_libs = ''
@ -396,11 +405,11 @@ if not GetOption( 'help' ):
# UIP files # UIP files
uip_files = "uip_arp.c uip.c uiplib.c dhcpc.c psock.c resolv.c" uip_files = "uip_arp.c uip.c uiplib.c dhcpc.c psock.c resolv.c"
uip_files = " src/elua_uip.c " + " ".join( [ "src/uip/%s" % name for name in uip_files.split() ] ) uip_files = " src/elua_uip.c " + " ".join( [ "src/uip/%s" % name for name in uip_files.split() ] )
local_include += ['src/uip'] comp.Append(CPPPATH = ['src/uip'])
# FatFs files # FatFs files
app_files = app_files + "src/elua_mmc.c src/mmcfs.c src/fatfs/ff.c src/fatfs/ccsbcs.c " app_files = app_files + "src/elua_mmc.c src/mmcfs.c src/fatfs/ff.c src/fatfs/ccsbcs.c "
local_include += ['src/fatfs'] comp.Append(CPPPATH = ['src/fatfs'])
# Lua module files # Lua module files
module_names = "pio.c spi.c tmr.c pd.c uart.c term.c pwm.c lpack.c bit.c net.c cpu.c adc.c can.c luarpc.c bitarray.c elua.c" module_names = "pio.c spi.c tmr.c pd.c uart.c term.c pwm.c lpack.c bit.c net.c cpu.c adc.c can.c luarpc.c bitarray.c elua.c"
@ -411,8 +420,7 @@ if not GetOption( 'help' ):
rfs_files = " " + " ".join( [ "src/remotefs/%s" % name for name in rfs_names.split() ] ) rfs_files = " " + " ".join( [ "src/remotefs/%s" % name for name in rfs_names.split() ] )
# Optimizer flags (speed or size) # Optimizer flags (speed or size)
#opt = "-O3" comp.Append(CCFLAGS = ['-Os','-fomit-frame-pointer'])
opt = "-Os -fomit-frame-pointer"
#opt += " -ffreestanding" #opt += " -ffreestanding"
#opt += " -fconserve-stack" # conserve stack at potential speed cost, >=GCC4.4 #opt += " -fconserve-stack" # conserve stack at potential speed cost, >=GCC4.4
@ -423,13 +431,7 @@ if not GetOption( 'help' ):
execfile( "src/platform/%s/conf.py" % platform ) execfile( "src/platform/%s/conf.py" % platform )
# Complete file list # Complete file list
source_files = app_files + specific_files + newlib_files + uip_files + lua_full_files + module_files + rfs_files source_files = Split( app_files + specific_files + newlib_files + uip_files + lua_full_files + module_files + rfs_files )
# Env for building the program
comp['CCCOM'] = tools[ platform ][ 'cccom' ]
comp['ASCOM'] = tools[ platform ][ 'ascom' ]
comp['LINKCOM'] = tools[ platform ][ 'linkcom' ]
comp['CPPPATH'] = local_include
comp = conf.Finish() comp = conf.Finish()
@ -458,9 +460,11 @@ if not GetOption( 'help' ):
# comp.TargetSignatures( 'content' ) # comp.TargetSignatures( 'content' )
# comp.SourceSignatures( 'MD5' ) # comp.SourceSignatures( 'MD5' )
comp[ 'INCPREFIX' ] = "-I" comp[ 'INCPREFIX' ] = "-I"
Default( comp.Program( target = output, source = Split( source_files ) ) ) Default( comp.Program( target = output, source = source_files ) )
Decider( 'MD5-timestamp' ) Decider( 'MD5-timestamp' )
# Programming target # Programming target
prog = Environment( BUILDERS = { 'program' : Builder( action = Action ( tools[ platform ][ 'progfunc' ] ) ) }, ENV = os.environ ) prog = Environment( BUILDERS = { 'program' : Builder( action = Action ( tools[ platform ][ 'progfunc' ] ) ) }, ENV = os.environ )
prog.program( "prog", output + ".elf" ) prog.program( "prog", output + ".elf" )
Help(vars.GenerateHelpText(comp))

View File

@ -3,7 +3,8 @@ import fnmatch
import glob import glob
import os import os
local_include += ['src/platform/%s/drivers/inc' % platform]
comp.Append(CPPPATH = ['src/platform/%s/drivers/inc' % platform])
fwlib_files = " ".join(glob.glob("src/platform/%s/drivers/src/*.c" % platform)) fwlib_files = " ".join(glob.glob("src/platform/%s/drivers/src/*.c" % platform))
@ -20,13 +21,17 @@ else:
specific_files = fwlib_files + " " + " ".join( [ "src/platform/%s/%s" % ( platform, f ) for f in specific_files.split() ] ) specific_files = fwlib_files + " " + " ".join( [ "src/platform/%s/%s" % ( platform, f ) for f in specific_files.split() ] )
ldscript = "src/platform/%s/%s" % ( platform, ldscript ) ldscript = "src/platform/%s/%s" % ( platform, ldscript )
cdefs = cdefs + " -DFOR" + comp[ 'cpu' ] + " -Dgcc" comp.Append(CPPDEFINES = ["FOR" + comp[ 'cpu' ],'gcc'])
# Configure General Flags for Target
comp.Prepend(CCFLAGS = ['-mcpu=cortex-m3','-mthumb','-mlittle-endian','-ffunction-sections','-fdata-sections','-fno-strict-aliasing'])
comp.Prepend(LINKFLAGS = ['-mcpu=cortex-m3','-mthumb','-Wl,-T','-Xlinker',ldscript,'-u', '_start','-Wl,-e,Reset_Handler','-Wl,-static','-Wl,--gc-sections','-nostartfiles','-nostdlib','-Wl,--allow-multiple-definition'])
comp.Prepend(ASFLAGS = ['-x assembler-with-cpp','-mcpu=cortex-m3','-mthumb','-Wall'])
comp.Append(LIBS = ['c','gcc','m'])
# Toolset data # Toolset data
tools[ 'lpc17xx' ] = {} tools[ 'lpc17xx' ] = {}
tools[ 'lpc17xx' ][ 'cccom' ] = "%s -mcpu=cortex-m3 -mthumb -mlittle-endian %s $_CPPINCFLAGS -ffunction-sections -fdata-sections -fno-strict-aliasing %s -Wall -c $SOURCE -o $TARGET" % ( toolset[ 'compile' ], opt, cdefs )
tools[ 'lpc17xx' ][ 'linkcom' ] = "%s -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker %s -u _start -Wl,-e,Reset_Handler -Wl,-static -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--allow-multiple-definition -o $TARGET $SOURCES -lc -lgcc -lm %s" % ( toolset[ 'compile' ], ldscript, local_libs )
tools[ 'lpc17xx' ][ 'ascom' ] = "%s -x assembler-with-cpp $_CPPINCFLAGS -mcpu=cortex-m3 -mthumb %s -Wall -c $SOURCE -o $TARGET" % ( toolset[ 'compile' ], cdefs )
# Programming function for LPC17xx # Programming function for LPC17xx
def progfunc_lpc17xx( target, source, env ): def progfunc_lpc17xx( target, source, env ):