1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00

added more platforms to the new build script; fixed issue that prevented compilation under Windows

This commit is contained in:
Bogdan Marinescu 2011-02-21 23:29:54 +00:00
parent 36d160876d
commit cd3d721519
7 changed files with 273 additions and 16 deletions

View File

@ -31,6 +31,15 @@ function addcf( data )
table.insert( cflags, data )
end
-- Delete a compiler flag
function delcf( data )
cflags = utils.linearize_array( cflags )
for _, v in pairs( data ) do
local i = utils.array_element_index( cflags, v )
if i then table.remove( cflags, i ) end
end
end
-- Add a linker flag
function addlf( data )
table.insert( lflags, data )
@ -264,6 +273,7 @@ builder:add_option( 'toolchain', 'specifies toolchain to use (auto=search for us
builder:add_option( 'optram', 'enables Lua Tiny RAM enhancements', true )
builder:add_option( 'boot', 'boot mode, standard will boot to shell, luarpc boots to an rpc server', 'standard', { 'standard' , 'luarpc' } )
builder:add_option( 'romfs', 'ROMFS compilation mode', 'verbatim', { 'verbatim' , 'compress', 'compile' } )
builder:add_option( 'cpumode', 'ARM CPU compilation mode (only affects certain ARM targets)', nil, { 'arm', 'thumb' } )
builder:init( args )
builder:set_build_mode( builder.BUILD_DIR_LINEARIZED )
@ -356,7 +366,7 @@ if comp.allocator == 'auto' then
end
-- Build the compilation command now
local compcmd = ''
local fscompcmd = ''
if comp.romfs == 'compile' then
local suffix = ''
if utils.is_windows() then
@ -369,10 +379,9 @@ if comp.romfs == 'compile' then
os.exit( -1 )
end
local cmdpath = { lfs.currentdir(), sf( 'luac.cross%s -ccn %s -cce %s -o %%s -s %%s', suffix, toolset[ "cross_" .. comp.target:lower() ], toolset.cross_cpumode:lower() ) }
compcmd = table.concat( cmdpath, utils.dir_sep )
print( compcmd )
fscompcmd = table.concat( cmdpath, utils.dir_sep )
elseif comp.romfs == 'compress' then
compcmd = 'lua luasrcdiet.lua --quiet --maximum --opt-comments --opt-whitespace --opt-emptylines --opt-eols --opt-strings --opt-numbers --opt-locals -o %s %s'
fscompcmd = 'lua luasrcdiet.lua --quiet --maximum --opt-comments --opt-whitespace --opt-emptylines --opt-eols --opt-strings --opt-numbers --opt-locals -o %s %s'
end
-- Output file
@ -484,7 +493,7 @@ local function make_romfs()
table.insert( flist, romfs[ sample ] )
end
flist = utils.linearize_array( flist )
if not mkfs.mkfs( romdir, "romfiles", flist, comp.romfs, compcmd ) then return -1 end
if not mkfs.mkfs( romdir, "romfiles", flist, comp.romfs, fscompcmd ) then return -1 end
if utils.is_file( "inc/romfiles.h" ) then
-- Read both the old and the new file
local oldfile = io.open( "inc/romfiles.h", "rb" )
@ -507,9 +516,9 @@ local function make_romfs()
end
-- Command lines for the tools (compiler, linker, assembler)
compcmd = builder:compile_cmd{ flags = cflags, defines = cdefs, includes = includes, compiler = toolset.compile }
linkcmd = builder:link_cmd{ flags = lflags, libraries = libs, linker = toolset.compile }
ascmd = builder:asm_cmd{ flags = asflags, defines = cdefs, includes = includes, assembler = toolset.asm }
compcmd = compcmd or builder:compile_cmd{ flags = cflags, defines = cdefs, includes = includes, compiler = toolset.compile }
linkcmd = linkcmd or builder:link_cmd{ flags = lflags, libraries = libs, linker = toolset.compile }
ascmd = ascmd or builder:asm_cmd{ flags = asflags, defines = cdefs, includes = includes, assembler = toolset.asm }
builder:set_compile_cmd( compcmd )
builder:set_link_cmd( linkcmd )
builder:set_asm_cmd( ascmd )

View File

@ -0,0 +1,60 @@
-- Configuration file for the AT91SAM7X(256/512) backend
local cpumode = ( builder:get_option( 'cpumode' ) or 'thumb' ):lower()
specific_files = "board_cstartup.s board_lowlevel.c board_memories.c usart.c pmc.c pio.c platform.c tc.c pwmc.c aic.c platform_int.c"
local ldscript
if comp.cpu:upper() == 'AT91SAM7X256' then
ldscript = "flash256.lds"
addm( 'at91sam7x256' )
elseif comp.cpu:upper() == 'AT91SAM7X512' then
ldscript = "flash512.lds"
addm( 'at91sam7x512' )
else
print( sf( "Invalid AT91SAM7X CPU %s", comp.cpu ) )
os.exit( -1 )
end
addm( { 'NOASSERT','NOTRACE' } )
-- Prepend with path
specific_files = utils.prepend_path( specific_files, sf( "src/platform/%s", platform ) )
specific_files = specific_files .. " src/platform/arm_utils.s src/platform/arm_cortex_interrupts.c"
ldscript = sf( "src/platform/%s/%s", platform, ldscript )
addcf( { '-ffunction-sections', '-fdata-sections', '-fno-strict-aliasing', '-Wall' } )
addlf( { '-nostartfiles', '-nostdlib', '-T', ldscript, '-Wl,--gc-sections', '-Wl,--allow-multiple-definition' } )
addaf( { '-x', 'assembler-with-cpp', '-Wall' } )
addlib( { 'c','gcc','m' } )
local target_flags = '-mcpu=arm7tdmi'
if cpumode == 'thumb' then
target_flags = target_flags .. ' -mthumb'
addm( 'CPUMODE_THUMB' )
else
addm( 'CPUMODE_ARM' )
end
-- Configure general flags for target
addcf( target_flags )
addlf( { target_flags, '-Wl,-e,entry' } )
addaf( { target_flags, '-D__ASSEMBLY__' } )
-- Toolset data
tools.at91sam7x = {}
-- Programming function for AT91SAM7X
tools.at91sam7x.progfunc = function( target, deps )
local outname = deps[ 1 ]:target_name()
os.execute( sf( "%s %s", toolset.size, outname ) )
print "Generating binary image..."
os.execute( sf( "%s -O binary %s %s.bin", toolset.bin, outname, output ) )
return 0
end
-- Array of file names that will be checked against the 'prog' target; their absence will force a rebuild
tools.at91sam7x.prog_flist = { output .. ".bin" }
-- We use 'gcc' as the assembler
toolset.asm = toolset.compile

View File

@ -0,0 +1,36 @@
-- Configuration file for the i386 backend
specific_files = "boot.s common.c descriptor_tables.c gdt.s interrupt.s isr.c kb.c monitor.c timer.c platform.c"
local ldscript = "i386.ld"
-- Prepend with path
specific_files = utils.prepend_path( specific_files, sf( "src/platform/%s", platform ) )
ldscript = sf( "src/platform/%s/%s", platform, ldscript )
-- Standard GCC Flags
addcf{ '-ffunction-sections', '-fdata-sections', '-fno-strict-aliasing', '-Wall' }
addlf{ '-nostartfiles', '-nostdlib', '-T', ldscript, '-Wl,--gc-sections', '-Wl,--allow-multiple-definition' }
addlib{ 'c','gcc','m' }
local target_flags = { '-march=i386','-mfpmath=387', '-m32' }
addcf{ target_flags, '-fno-builtin', '-fno-stack-protector' }
addlf{ target_flags, '-Wl,-e,start' }
addaf{ '-felf' }
-- Need to force the assembler command as we're using nasm
ascmd = "nasm -felf -o $(TARGET) $(FIRST)"
-- Also tell the builder that we don't need dependency checks for assembler files
builder:set_asm_dep_cmd( false )
-- Toolset data
tools.i386 = {}
-- Programming function for i386 (not needed, empty function)
tools.i386.progfunc = function( target, deps )
local outname = deps[ 1 ]:target_name()
os.execute( sf( "%s %s", toolset.size, outname ) )
print "Visit http://www.eluaproject.net for instructions on how to use your eLua ELF file"
return 0
end

View File

@ -0,0 +1,56 @@
-- Configuration file for the LM3S microcontroller
specific_files = "startup_gcc.c platform.c uart.c sysctl.c gpio.c ssi.c timer.c pwm.c ethernet.c systick.c flash.c interrupt.c cpu.c adc.c can.c platform_int.c"
local board = comp.board:upper()
if board == 'EK-LM3S1968' or board == 'EK-LM3S6965' or board == 'EK-LM3S8962' then
specific_files = specific_files .. " rit128x96x4.c disp.c"
addm 'ENABLE_DISP'
end
-- The default for the Eagle 100 board is to start the image at 0x2000,
-- so that the built in Ethernet boot loader can be used to upload it
if board == 'EAGLE-100' then
addlf '-Wl,-Ttext,0x2000'
end
local ldscript = board == 'EK-LM3S9B92' and "lm3s-9b92.ld" or "lm3s.ld"
-- Prepend with path
specific_files = utils.prepend_path( specific_files, sf( "src/platform/%s", platform) )
specific_files = specific_files .. " src/platform/cortex_utils.s src/platform/arm_cortex_interrupts.c"
ldscript = sf( "src/platform/%s/%s", platform, ldscript )
addm{ "FOR" .. comp.cpu:upper(), 'gcc', 'CORTEX_M3' }
-- Standard GCC flags
addcf{ '-ffunction-sections', '-fdata-sections', '-fno-strict-aliasing', '-Wall' }
addlf{ '-nostartfiles', '-nostdlib', '-T', ldscript, '-Wl,--gc-sections', '-Wl,--allow-multiple-definition' }
addaf{ '-x', 'assembler-with-cpp', '-Wall' }
addlib{ 'c','gcc','m' }
local target_flags = {'-mcpu=cortex-m3','-mthumb' }
-- Configure general flags for target
addcf{ target_flags, '-mlittle-endian' }
addlf{ target_flags, '-Wl,-e,ResetISR', '-Wl,-static' }
addaf( target_flags )
-- Toolset data
tools.lm3s = {}
-- Programming function
tools.lm3s.progfunc = function( target, deps )
local outname = deps[ 1 ]:target_name()
os.execute( sf( "%s %s", toolset.size, outname ) )
print "Generating binary image..."
os.execute( sf( "%s -O binary %s %s.bin", toolset.bin, outname, output ) )
return 0
end
-- Array of file names that will be checked against the 'prog' target; their absence will force a rebuild
tools.lm3s.prog_flist = { output .. ".bin" }
-- We use 'gcc' as the assembler
toolset.asm = toolset.compile

View File

@ -0,0 +1,47 @@
-- Configuration file for the LPC17xx backend
addi( sf( 'src/platform/%s/drivers/inc', platform ) )
local fwlib_files = utils.get_files( sf( "src/platform/%s/drivers/src", platform ), ".*%.c$" )
specific_files = "startup_LPC17xx.c system_LPC17xx.c core_cm3.c platform.c mbed_pio.c"
local ldscript = "LPC17xx.ld"
-- Prepend with path
specific_files = fwlib_files .. " " .. utils.prepend_path( specific_files, sf( "src/platform/%s", platform ) )
specific_files = specific_files .. " src/platform/cortex_utils.s src/platform/arm_cortex_interrupts.c"
ldscript = sf( "src/platform/%s/%s", platform, ldscript )
addm{ "FOR" .. comp.cpu:upper(), 'gcc', 'CORTEX_M3' }
-- Standard GCC flags
addcf{ '-ffunction-sections', '-fdata-sections', '-fno-strict-aliasing', '-Wall' }
addlf{ '-nostartfiles', '-nostdlib', '-T', ldscript, '-Wl,--gc-sections', '-Wl,--allow-multiple-definition' }
addaf{ '-x', 'assembler-with-cpp', '-Wall' }
addlib{ 'c','gcc','m' }
local target_flags = { '-mcpu=cortex-m3','-mthumb' }
-- Configure general flags for target
addcf{ target_flags, '-mlittle-endian' }
addlf{ target_flags, '-Wl,-e,Reset_Handler', '-Wl,-static' }
addaf{ target_flags }
-- Toolset data
tools.lpc17xx = {}
-- Programming function
tools.lpc17xx.progfunc = function( target, deps )
local outname = deps[ 1 ]:target_name()
os.execute( sf( "%s %s", toolset.size, outname ) )
print "Generating binary image..."
os.execute( sf( "%s -O binary %s %s.bin", toolset.bin, outname, output ) )
return 0
end
-- Array of file names that will be checked against the 'prog' target; their absence will force a rebuild
tools.lpc17xx.prog_flist = { output .. ".bin" }
-- We use 'gcc' as the assembler
toolset.asm = toolset.compile

38
src/platform/sim/conf.lua Normal file
View File

@ -0,0 +1,38 @@
-- Configuration file for the linux (sim) backend
specific_files = sf( "boot.s utils.s hostif_%s.c platform.c host.c", comp.cpu:lower() )
local ldscript = "i386.ld"
-- Override default optimize settings
delcf{ "-Os", "-fomit-frame-pointer" }
addcf{ "-O0", "-g" }
-- Prepend with path
specific_files = utils.prepend_path( specific_files, sf( "src/platform/%s", platform ) )
local ldscript = sf( "src/platform/%s/%s", platform, ldscript )
-- Standard GCC flags
addcf{ '-ffunction-sections', '-fdata-sections', '-fno-strict-aliasing', '-Wall' }
addlf{ '-nostartfiles', '-nostdlib', '-T', ldscript, '-Wl,--gc-sections', '-Wl,--allow-multiple-definition' }
addlib{ 'c','gcc','m' }
local target_flags = { '-march=i386','-mfpmath=387','-m32' }
addcf{ target_flags, '-fno-builtin', '-fno-stack-protector' }
addlf{ target_flags, '-Wl,-e,start', '-Wl,-static' }
addaf{ '-felf' }
-- Need to force the assembler command as we're using nasm
ascmd = "nasm -felf -o $(TARGET) $(FIRST)"
-- Also tell the builder that we don't need dependency checks for assembler files
builder:set_asm_dep_cmd( false )
-- Toolset data
tools.sim = {}
-- Programming function for i386 (not needed, empty function)
tools.sim.progfunc = function( target, deps )
print "Run the simulator (./run_elua_sim.sh) and enjoy :) Linux only."
return 0
end

View File

@ -36,8 +36,7 @@ end
-- 'Liniarize' a file name by replacing its path separators indicators with '_'
local function linearize_fname( s )
local fmt = "%" .. dir_sep
return ( s:gsub( fmt, "__" ) )
return ( s:gsub( "[\\/]", "__" ) )
end
-- Helper: transform a table into a string if needed
@ -517,7 +516,7 @@ builder._show_help = function( self )
if values then
print( sf( " Possible values: %s", values ) )
end
print( sf( " Default value: %s", default ) )
print( sf( " Default value: %s", default or "none (changes at runtime)" ) )
end
end
@ -574,6 +573,12 @@ builder.get_target_args = function( self )
return self.targetargs
end
-- Set a specific dependency generation command for the assembler
-- Pass 'false' to skip dependency generation for assembler files
builder.set_asm_dep_cmd = function( self, asm_dep_cmd )
self.asm_dep_cmd = asm_dep_cmd
end
---------------------------------------
-- Command line builders
@ -701,9 +706,14 @@ builder.make_depends = function( self, ftable, deptargets )
deptargets = deptargets or {}
for i = 1, #ftable do
local isasm = ftable[ i ]:find( "%.c$" ) == nil
local cmd = isasm and self.asm_cmd or self.comp_cmd
local target = self:dep_target( ftable[ i ], initdep[ ftable[ i ] ], cmd:gsub( "-c ", "-E -MM " ) )
table.insert( deptargets, target )
-- Skip assembler targets if 'asm_dep_cmd' is set to 'false'
if not isasm or self.asm_dep_cmd ~= false then
local cmd = isasm and self.asm_cmd or self.comp_cmd
local depcmd = cmd:gsub( "-c ", "-E -MM " )
if isasm and self.asm_dep_cmd then depcmd = self.asm_dep_cmd end
local target = self:dep_target( ftable[ i ], initdep[ ftable[ i ] ], depcmd )
table.insert( deptargets, target )
end
end
local t = self:target( "#phony:deps", deptargets )
t:build()
@ -728,10 +738,11 @@ builder.create_compile_targets = function( self, ftable, res )
-- Build dependencies for all targets
for i = 1, #ftable do
local target
local deps = self.dtable and self.dtable[ ftable[ i ] ]
if ftable[ i ]:find( "%.c$" ) then
target = self:c_target( self:obj_name( ftable[ i ] ), self.dtable and self.dtable[ ftable[ i ] ] )
target = self:c_target( self:obj_name( ftable[ i ] ), deps )
else
target = self:asm_target( self:obj_name( ftable[ i ] ), self.dtable and self.dtable[ ftable[ i ] ] )
target = self:asm_target( self:obj_name( ftable[ i ] ), deps )
end
table.insert( res, target )
end