Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 578 lines (517 sloc) 20.996 kb
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
1 local args = { ... }
2 local b = require "utils.build"
3 local mkfs = require "utils.mkfs"
4 builder = b.new_builder()
5 utils = b.utils
6 sf = string.format
7
8 -------------------------------------------------------------------------------
9 -- Build configuration 'shortcuts'
10
11 cdefs, cflags, includes, lflags, asflags, libs = {}, {}, {}, {}, {}, {}
12
13 -- "Normalize" a name to make it a suitable C macro name
14 function cnorm( name )
15 name = name:gsub( "[%-%s]*", '' )
16 return name:upper()
17 end
18
19 -- Add a macro defition
20 function addm( data )
21 table.insert( cdefs, data )
22 end
23
24 -- Add an include directory
25 function addi( data )
26 table.insert( includes, data )
27 end
28
29 -- Add a compiler flag
30 function addcf( data )
31 table.insert( cflags, data )
32 end
33
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
34 -- Delete a compiler flag
35 function delcf( data )
36 cflags = utils.linearize_array( cflags )
37 for _, v in pairs( data ) do
38 local i = utils.array_element_index( cflags, v )
39 if i then table.remove( cflags, i ) end
40 end
41 end
42
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
43 -- Add a linker flag
44 function addlf( data )
45 table.insert( lflags, data )
46 end
47
48 -- Add an assembler flag
49 function addaf( data )
50 table.insert( asflags, data )
51 end
52
53 -- Add a library
54 function addlib( data )
55 table.insert( libs, data )
56 end
57
58 -------------------------------------------------------------------------------
59 -- Build data
60
61 -- List of toolchains
62 local toolchain_list =
63 {
64 [ 'arm-gcc' ] = {
65 compile = 'arm-elf-gcc',
66 link = 'arm-elf-ld',
67 asm = 'arm-elf-as',
68 bin = 'arm-elf-objcopy',
69 size = 'arm-elf-size',
70 cross_cpumode = 'little',
71 cross_lua = 'float_arm 64',
72 cross_lualong = 'int 32',
73 version = '--version'
74 },
75 [ 'arm-eabi-gcc' ] = {
76 compile = 'arm-eabi-gcc',
77 link = 'arm-eabi-ld',
78 asm = 'arm-eabi-as',
79 bin = 'arm-eabi-objcopy',
80 size = 'arm-eabi-size',
81 cross_cpumode = 'little',
82 cross_lua = 'float 64',
83 cross_lualong = 'int 32',
84 version = '--version'
85 },
86 codesourcery = {
87 compile = 'arm-none-eabi-gcc',
88 link = 'arm-none-eabi-ld',
89 asm = 'arm-none-eabi-as',
90 bin = 'arm-none-eabi-objcopy',
91 size = 'arm-none-eabi-size',
92 cross_cpumode = 'little',
93 cross_lua = 'float 64',
94 cross_lualong = 'int 32',
95 version = '--version'
96 },
97 [ 'avr32-gcc' ] = {
98 compile = 'avr32-gcc',
99 link = 'avr32-ld',
100 asm = 'avr32-as',
101 bin = 'avr32-objcopy',
102 size = 'avr32-size',
103 cross_cpumode = 'big',
104 cross_lua = 'float 64',
105 cross_lualong = 'int 32',
106 version = '--version'
107 },
108 [ 'i686-gcc' ] = {
109 compile = 'i686-elf-gcc',
110 link = 'i686-elf-ld',
111 asm = 'nasm',
112 bin = 'i686-elf-objcopy',
113 size = 'i686-elf-size',
114 cross_cpumode = 'little',
115 cross_lua = 'float 64',
116 cross_lualong = 'int 32',
117 version = '--version'
118 }
119 }
120
121 -- Toolchain Aliases
122 toolchain_list[ 'devkitarm' ] = toolchain_list[ 'arm-eabi-gcc' ]
123
124 -- List of platform/CPU/toolchains combinations
125 -- The first toolchain in the toolchains list is the default one
126 -- (the one that will be used if none is specified)
127 local platform_list =
128 {
129 at91sam7x = { cpus = { 'AT91SAM7X256', 'AT91SAM7X512' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
130 lm3s = { cpus = { 'LM3S1968', 'LM3S8962', 'LM3S6965', 'LM3S6918', 'LM3S9B92' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
131 str9 = { cpus = { 'STR912FAW44' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
132 i386 = { cpus = { 'I386' }, toolchains = { 'i686-gcc' } },
133 sim = { cpus = { 'LINUX' }, toolchains = { 'i686-gcc' } },
134 lpc288x = { cpus = { 'LPC2888' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
135 str7 = { cpus = { 'STR711FR2' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
136 stm32 = { cpus = { 'STM32F103ZE', 'STM32F103RE' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
137 avr32 = { cpus = { 'AT32UC3A0512', 'AT32UC3A0128', 'AT32UC3B0256' }, toolchains = { 'avr32-gcc' } },
138 lpc24xx = { cpus = { 'LPC2468' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } },
139 lpc17xx = { cpus = { 'LPC1768' }, toolchains = { 'arm-gcc', 'codesourcery', 'devkitarm', 'arm-eabi-gcc' } }
140 }
141
142 -- List of board/CPU combinations
143 local board_list =
144 {
145 [ 'SAM7-EX256' ] = { 'AT91SAM7X256', 'AT91SAM7X512' },
146 [ 'EK-LM3S1968' ] = { 'LM3S1968' },
147 [ 'EK-LM3S8962' ] = { 'LM3S8962' },
148 [ 'EK-LM3S6965' ] = { 'LM3S6965' },
149 [ 'EK-LM3S9B92' ] = { 'LM3S9B92' },
150 [ 'STR9-COMSTICK' ] = { 'STR912FAW44' },
151 [ 'STR-E912' ] = { 'STR912FAW44' },
152 [ 'PC' ] = { 'I386' },
153 [ 'SIM' ] = { 'LINUX' },
154 [ 'LPC-H2888' ] = { 'LPC2888' },
155 [ 'MOD711' ] = { 'STR711FR2' },
156 [ 'STM3210E-EVAL' ] = { 'STM32F103ZE' },
157 [ 'ATEVK1100' ] = { 'AT32UC3A0512' },
158 [ 'ATEVK1101' ] = { 'AT32UC3B0256' },
159 [ 'ET-STM32' ] = { 'STM32F103RE' },
160 [ 'EAGLE-100' ] = { 'LM3S6918' },
161 [ 'ELUA-PUC' ] = { 'LPC2468' },
162 [ 'MBED' ] = { 'LPC1768' },
163 [ 'MIZAR32' ] = { 'AT32UC3A0128' },
164 [ 'NETDUINO' ] = { 'AT91SAM7X512' },
165 }
166
167 -- Build the CPU list starting from the above list
168 local cpu_list = {}
169 for k, v in pairs( board_list ) do
170 local clist = v
171 for i = 1, #clist do
172 if not utils.array_element_index( cpu_list, clist[ i ] ) then
173 table.insert( cpu_list, clist[ i ] )
174 end
175 end
176 end
177
178 -- ROMFS file list "groups"
179 -- To include a file in a ROMFS build, include it in a group here (or create one
180 -- if you need) and make sure the group is included on your platform's file_list
181 -- definition (right after this).
182
183 -- The following table will be left here just as an example
184 -- eLua examples were removed from the distro since v0.8
185 --[[
186 local romfs =
187 {
188 bisect = { 'bisect.lua' },
189 hangman = { 'hangman.lua' },
190 lhttpd = { 'index.pht', 'lhttpd.lua', 'test.lua' },
191 led = { 'led.lua' },
192 piano = { 'piano.lua' },
193 pwmled = { 'pwmled.lua' },
194 tvbgone = { 'tvbgone.lua', 'codes.bin' },
195 hello = { 'hello.lua' },
196 info = { 'info.lua' },
197 morse = { 'morse.lua' },
198 dualpwm = { 'dualpwm.lua' },
199 adcscope = { 'adcscope.lua' },
200 adcpoll = { 'adcpoll.lua' },
201 life = { 'life.lua' },
202 logo = {'logo.lua', 'logo.bin' },
203 pong = { 'pong.lua' },
204 spaceship = { 'spaceship.lua' },
205 tetrives = { 'tetrives.lua' },
206 snake = { 'snake.lua' },
207 dataflash = { 'dataflash.lua' },
208 pachube = { 'pachube_demo.lua' },
209 inttest = { 'inttest.lua' }
210 }
211 --]]
212
213 local romfs = {}
214
215 -- List of board/romfs data combinations
216 -- The following table will be left here just as an example
217 -- eLua examples were removed from the distro since v0.8
218 --[[
219 local file_list =
220 {
221 [ 'SAM7-EX256' ] = { 'bisect', 'hangman' , 'led', 'piano', 'hello', 'info', 'morse' },
222 [ 'EK-LM3S1968' ] = { 'bisect', 'hangman', 'pong', 'led', 'piano', 'pwmled', 'hello', 'info', 'morse', 'adcscope', 'adcpoll', 'logo', 'spaceship', 'tetrives', 'snake' },
223 [ 'EK-LM3S8962' ] = { 'lhttpd','bisect', 'led', 'pachube' },
224 [ 'EK-LM3S6965' ] = { 'bisect', 'hangman', 'pong', 'led', 'piano', 'pwmled', 'hello', 'info', 'morse', 'adcscope', 'adcpoll', 'logo', 'tetrives' },
225 [ 'EK-LM3S9B92' ] = { 'bisect', 'hangman', 'led', 'pwmled', 'hello', 'info', 'adcscope','adcpoll', 'life' },
226 [ 'STR9-COMSTICK' ] = { 'bisect', 'hangman', 'led', 'hello', 'info' },
227 [ 'STR-E912' ] = { 'bisect', 'hangman', 'led', 'hello', 'info', 'piano', 'adcscope' },
228 [ 'PC' ] = { 'bisect', 'hello', 'info', 'life', 'hangman' },
229 [ 'SIM' ] = { 'bisect', 'hello', 'info', 'life', 'hangman' },
230 [ 'LPC-H2888' ] = { 'bisect', 'hangman', 'led', 'hello', 'info' },
231 [ 'MOD711' ] = { 'bisect', 'hangman', 'led', 'hello', 'info', 'dualpwm' },
232 [ 'STM3210E-EVAL' ] = { 'bisect', 'hello', 'info' },
233 [ 'ATEVK1100' ] = { 'bisect', 'hangman', 'led', 'hello', 'info', 'dataflash' },
234 [ 'ATEVK1101' ] = { 'bisect', 'led', 'hello', 'info', 'dataflash' },
235 [ 'ET-STM32' ] = { 't' },
236 [ 'EAGLE-100' ] = { 'bisect', 'hangman', 'lhttpd', 'led', 'hello', 'info' },
237 [ 'ELUA-PUC' ] = { 'bisect', 'hangman', 'led', 'hello', 'info', 'pwmled', 'adcscope', 'adcpoll', 'inttest' },
238 [ 'MBED' ] = { 'bisect', 'hangman', 'hello', 'info', 'led', 'pwmled', 'dualpwm', 'life', 'adcscope', 'adcpoll' },
239 [ 'MIZAR32' ] = { },
240 [ 'NETDUINO' ] = { },
241 }
242 --]]
243
244 local file_list =
245 {
246 [ 'SAM7-EX256' ] = {},
247 [ 'EK-LM3S1968' ] = {},
248 [ 'EK-LM3S8962' ] = {},
249 [ 'EK-LM3S6965' ] = {},
250 [ 'EK-LM3S9B92' ] = {},
251 [ 'STR9-COMSTICK' ] = {},
252 [ 'STR-E912' ] = {},
253 [ 'PC' ] = {},
254 [ 'SIM' ] = {},
255 [ 'LPC-H2888' ] = {},
256 [ 'MOD711' ] = {},
257 [ 'STM3210E-EVAL' ] = {},
258 [ 'ATEVK1100' ] = {},
259 [ 'ATEVK1101' ] = {},
260 [ 'ET-STM32' ] = {},
261 [ 'EAGLE-100' ] = {},
262 [ 'ELUA-PUC' ] = {},
263 [ 'MBED' ] = {},
264 [ 'MIZAR32' ] = {},
265 [ 'NETDUINO'] = {},
266 }
267
268 builder:add_option( 'target', 'build "regular" float lua or integer-only "lualong"', 'lua', { 'lua', 'lualong' } )
269 builder:add_option( 'cpu', 'build for the specified CPU (board will be inferred, if possible)', 'auto', { cpu_list, 'auto' } )
270 builder:add_option( 'allocator', 'select memory allocator', 'auto', { 'newlib', 'multiple', 'simple', 'auto' } )
271 builder:add_option( 'board', 'selects board for target (cpu will be inferred)', 'auto', { utils.table_keys( board_list ), 'auto' } )
272 builder:add_option( 'toolchain', 'specifies toolchain to use (auto=search for usable toolchain)', 'auto', { utils.table_keys( toolchain_list ), 'auto' } )
273 builder:add_option( 'optram', 'enables Lua Tiny RAM enhancements', true )
274 builder:add_option( 'boot', 'boot mode, standard will boot to shell, luarpc boots to an rpc server', 'standard', { 'standard' , 'luarpc' } )
275 builder:add_option( 'romfs', 'ROMFS compilation mode', 'verbatim', { 'verbatim' , 'compress', 'compile' } )
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
276 builder:add_option( 'cpumode', 'ARM CPU compilation mode (only affects certain ARM targets)', nil, { 'arm', 'thumb' } )
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
277 builder:init( args )
278 builder:set_build_mode( builder.BUILD_DIR_LINEARIZED )
279
280 -- Build the 'comp' target which will 'redirect' all the requests
281 -- for its fields to builder:get_option
282 comp = {}
283 setmetatable( comp, { __index = function( t, key ) return builder:get_option( key ) end } )
284
285 -- Variants: board = <board>
286 -- cpu = <cpuname>
287 -- board = <board> cpu=<cpuname>
288 if comp.board == 'auto' and comp.cpu == 'auto' then
289 print "Must specifiy board, cpu, or both"
290 os.exit( -1 )
291 elseif comp.board ~= 'auto' and comp.cpu ~= 'auto' then
292 -- Check if the board, cpu pair is correct
293 if utils.array_element_index( board_list[ comp.board:upper() ], comp.cpu:upper() ) == nil then
294 print( sf( "Invalid CPU '%s' for board '%s'" , comp.cpu, comp.board ) )
295 os.exit( -1 )
296 end
297 elseif comp.board ~= 'auto' then
298 -- Find CPU
299 comp.cpu = board_list[ comp.board:upper() ][ 1 ]
300 else
301 -- cpu = <cputype>
302 -- Find board name
303 for b, v in pairs( board_list ) do
304 if utils.array_element_index( v, comp.cpu:upper() ) then
305 comp.board = b
306 break
307 end
308 end
309 if comp.board == 'auto' then
310 print( sf( "CPU '%s' not found", comp.cpu ) )
311 os.exit( -1 )
312 end
313 end
314
315 -- Look for the given CPU in the list of platforms
316 for p, v in pairs( platform_list ) do
317 if utils.array_element_index( v.cpus, comp.cpu:upper() ) then
318 platform = p
319 break
320 end
321 end
322 if not platform then
323 print( "Unable to find platform (this shouldn't happen, check the build script for errors)" )
324 os.exit( -1 )
325 end
326
327 -- Check the toolchain
328 if comp.toolchain ~= 'auto' then
329 if utils.array_element_index( platform_list[ platform ].toolchains, comp.toolchain ) == nil then
330 print( sf( "Invalid toolchain '%s' for CPU '%s'", comp.toolchain, comp.cpu ) )
331 os.exit( -1 )
332 end
333 toolset = toolchain_list[ comp.toolchain ]
334 comp.CC = toolset.compile
335 comp.AS = toolset.compile
336 else
337 -- If 'auto' try to match a working toolchain with target
338 local usable_chains = platform_list[ platform ].toolchains
339 -- Try to execute all compilers, exit when one found
340 local chain
341 for i = 1, #usable_chains do
342 local c = usable_chains[ i ]
343 local t = toolchain_list[ c ]
b95dd84 Bogdan Marinescu - avr32 platform now uses the Lua build system (lua build_elua.lua board...
bogdanm authored
344 local res = utils.check_command( t.compile .. " " .. t.version )
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
345 if res == 0 then chain = c break end
346 end
347 if chain then
348 comp.toolchain = chain
349 comp.CC = toolchain_list[ chain ].compile
350 comp.AS = comp.CC
351 toolset = toolchain_list[ chain ]
352 else
353 print "Unable to find an usable toolchain in your path."
354 print( sf( "List of accepted toolchains (for %s): %s", comp.cpu, table.concat( usable_chains ) ) )
355 os.exit( -1 )
356 end
357 end
358
359 -- CPU/allocator mapping (if allocator not specified)
360 if comp.allocator == 'auto' then
1822ee1 Bogdan Marinescu Now all eLua platforms compile using build_elua.lua; output compared wit...
bogdanm authored
361 if utils.array_element_index( { 'LPC-H2888', 'ATEVK1100', 'MBED' }, comp.board:upper() ) then
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
362 comp.allocator = 'multiple'
363 else
364 comp.allocator = 'newlib'
365 end
366 end
367
368 -- Build the compilation command now
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
369 local fscompcmd = ''
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
370 if comp.romfs == 'compile' then
371 local suffix = ''
372 if utils.is_windows() then
373 suffix = '.exe'
374 end
375 -- First check for luac.cross in the current directory
376 if not utils.is_file( "luac.cross" .. suffix ) then
377 print "The eLua cross compiler was not found."
378 print "Build it by running 'lua cross-lua.lua'"
379 os.exit( -1 )
380 end
381 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() ) }
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
382 fscompcmd = table.concat( cmdpath, utils.dir_sep )
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
383 elseif comp.romfs == 'compress' then
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
384 fscompcmd = 'lua luasrcdiet.lua --quiet --maximum --opt-comments --opt-whitespace --opt-emptylines --opt-eols --opt-strings --opt-numbers --opt-locals -o %s %s'
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
385 end
386
387 -- Output file
388 output = 'elua_' .. comp.target .. '_' .. comp.cpu:lower()
389 builder:set_output_dir( ".build" .. utils.dir_sep .. comp.board:lower() )
390
391 -- User report
392 print ""
393 print "*********************************"
394 print "Compiling eLua ..."
395 print( "CPU: ", comp.cpu )
396 print( "Board: ", comp.board )
397 print( "Platform: ", platform )
398 print( "Allocator: ", comp.allocator )
399 print( "Boot Mode: ", comp.boot )
400 print( "Target: ", comp.target )
401 print( "Toolchain: ", comp.toolchain )
402 print( "ROMFS mode: ", comp.romfs )
403 print "*********************************"
404 print ""
405
406 -- Build list of source files, include directories, macro definitions
407 addm( "ELUA_CPU=" .. comp.cpu:upper() )
408 addm( "ELUA_BOARD=" .. comp.board:upper() )
409 addm( "ELUA_PLATFORM=" .. platform:upper() )
410 addm( "__BUFSIZ__=128" )
411
412 -- Also make the above into direct defines (to use in conditional C code)
413 addm( "ELUA_CPU_" .. cnorm( comp.cpu ) )
414 addm( "ELUA_BOARD_" .. cnorm( comp.board ) )
415 addm( "ELUA_PLATFORM_" .. cnorm( platform ) )
416
417 if comp.allocator == 'multiple' then
418 addm( "USE_MULTIPLE_ALLOCATOR" )
419 elseif comp.allocator == 'simple' then
420 addm( "USE_SIMPLE_ALLOCATOR" )
421 end
422
423 if comp.boot == 'luarpc' then
424 addm( "ELUA_BOOT_RPC" )
425 end
426
427 -- Special macro definitions for the SYM target
428 if platform == 'sim' then
429 addm( { "ELUA_SIMULATOR", "ELUA_SIM_" .. cnorm( comp.cpu ) } )
430 end
431
432 -- Lua source files and include path
433 local lua_files = ([[lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
434 lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c
435 ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c lua.c lrotable.c legc.c]]):gsub( "\n", "" )
436 local lua_full_files = utils.prepend_path( lua_files, "src/lua" )
437
438 addi( { 'inc', 'inc/newlib', 'inc/remotefs', 'src/platform', 'src/lua' } )
439
440 if comp.target == 'lualong' then
441 addm( "LUA_NUMBER_INTEGRAL" )
442 end
443
444 addi( { 'src/modules', 'src/platform/' .. platform } )
445 addm( "LUA_OPTIMIZE_MEMORY=" .. ( comp.optram and "2" or "0" ) )
446
447 -- Application files
448 local app_files = ([[ src/main.c src/romfs.c src/semifs.c src/xmodem.c src/shell.c src/term.c src/common.c src/common_tmr.c src/buf.c src/elua_adc.c src/dlmalloc.c
449 src/salloc.c src/luarpc_elua_uart.c src/elua_int.c src/linenoise.c src/common_uart.c src/eluarpc.c ]]):gsub( "\n", "" )
450
451 -- Newlib related files
452 local newlib_files = " src/newlib/devman.c src/newlib/stubs.c src/newlib/genstd.c src/newlib/stdtcp.c"
453
454 -- UIP files
455 local uip_files = "uip_arp.c uip.c uiplib.c dhcpc.c psock.c resolv.c"
456 uip_files = " src/elua_uip.c " .. utils.prepend_path( uip_files, "src/uip" )
457 addi( "src/uip" )
458
459 -- FatFs files
460 app_files = app_files .. "src/elua_mmc.c src/mmcfs.c src/fatfs/ff.c src/fatfs/ccsbcs.c "
461 addi( "src/fatfs" )
462
463 -- Lua module files
464 local 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 i2c.c"
465 local module_files = " " .. utils.prepend_path( module_names, 'src/modules' )
466
467 -- Remote file system files
468 local rfs_names = "remotefs.c client.c elua_os_io.c elua_rfs.c"
469 local rfs_files = " " .. utils.prepend_path( rfs_names, "src/remotefs" )
470
471 -- Optimizer flags (speed or size)
472 addcf( { '-Os','-fomit-frame-pointer' } )
473
474 -- Toolset data (filled by each platform in part)
475 tools = {}
476 specific_files = ''
477
478 -- We get platform-specific data by executing the platform script
479 dofile( sf( "src/platform/%s/conf.lua", platform ) )
480
481 -- Complete file list
482 local source_files = app_files .. specific_files .. newlib_files .. uip_files .. lua_full_files .. module_files .. rfs_files
483
484 -------------------------------------------------------------------------------
485 -- Create compiler/linker/assembler command lines and build
486
487 -- ROM file system builder
488 local function make_romfs()
489 print "Building ROM file system ..."
490 local romdir = "romfs"
491 local flist = {}
492 for _, sample in pairs( file_list[ comp.board:upper() ] ) do
493 table.insert( flist, romfs[ sample ] )
494 end
495 flist = utils.linearize_array( flist )
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
496 if not mkfs.mkfs( romdir, "romfiles", flist, comp.romfs, fscompcmd ) then return -1 end
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
497 if utils.is_file( "inc/romfiles.h" ) then
498 -- Read both the old and the new file
499 local oldfile = io.open( "inc/romfiles.h", "rb" )
500 assert( oldfile )
501 local newfile = io.open( "romfiles.h", "rb" )
502 assert( newfile )
503 local olddata, newdata = oldfile:read( "*a" ), newfile:read( "*a" )
504 oldfile:close()
505 newfile:close()
506 -- If content is similar return '1' to builder to indicate that the target didn't really
507 -- produce a change even though it ran
508 if olddata == newdata then
509 os.remove( "romfiles.h" )
510 return 1
511 end
512 os.remove( "inc/romfiles.h" )
513 end
514 os.rename( "romfiles.h", "inc/romfiles.h" )
515 return 0
516 end
517
1638700 Bogdan Marinescu Yeah, you guessed it: even more improvements to the build system :)
bogdanm authored
518 -- Generic 'prog' action function
519 local function genprog( target, deps )
520 local outname = deps[ 1 ]:target_name()
521 local outtype = target:find( "%.hex$" ) and "ihex" or "binary"
522 print( sf( "Generating binary image %s...", target ) )
523 os.execute( sf( "%s %s", toolset.size, outname ) )
524 os.execute( sf( "%s -O %s %s %s", toolset.bin, outtype, outname, target ) )
525 return 0
526 end
527
528 -- Generic 'size' action function
529 local function sizefunc( target, deps )
530 local outname = deps[ 1 ]:target_name()
531 os.execute( sf( "%s %s", toolset.size, outname ) )
532 return 0
533 end
534
b95dd84 Bogdan Marinescu - avr32 platform now uses the Lua build system (lua build_elua.lua board...
bogdanm authored
535 -- Command lines for the tools (compiler, linker, assembler)
cd3d721 Bogdan Marinescu added more platforms to the new build script; fixed issue that prevented...
bogdanm authored
536 compcmd = compcmd or builder:compile_cmd{ flags = cflags, defines = cdefs, includes = includes, compiler = toolset.compile }
537 linkcmd = linkcmd or builder:link_cmd{ flags = lflags, libraries = libs, linker = toolset.compile }
538 ascmd = ascmd or builder:asm_cmd{ flags = asflags, defines = cdefs, includes = includes, assembler = toolset.asm }
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
539 builder:set_compile_cmd( compcmd )
540 builder:set_link_cmd( linkcmd )
541 builder:set_asm_cmd( ascmd )
542 builder:set_exe_extension( ".elf" )
543
1638700 Bogdan Marinescu Yeah, you guessed it: even more improvements to the build system :)
bogdanm authored
544 -- Create the ROM file system
545 make_romfs()
546 -- Creaate executable targets
547 builder:make_depends( source_files )
b95dd84 Bogdan Marinescu - avr32 platform now uses the Lua build system (lua build_elua.lua board...
bogdanm authored
548 odeps = builder:create_compile_targets( source_files )
549 exetarget = builder:link_target( output, odeps )
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
550 -- This is also the default target
b95dd84 Bogdan Marinescu - avr32 platform now uses the Lua build system (lua build_elua.lua board...
bogdanm authored
551 builder:default( builder:add_target( exetarget, 'build eLua executable' ) )
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
552
1638700 Bogdan Marinescu Yeah, you guessed it: even more improvements to the build system :)
bogdanm authored
553 -- Create 'prog' target(s)
554 local ptargets = {}
555 local progfunc = tools[ platform ].progfunc or genprog
556 utils.foreach( tools[ platform ].prog_flist, function( _, t )
557 local target = builder:target( t, { exetarget }, progfunc )
558 table.insert( ptargets, target )
559 end )
560 if #ptargets > 0 then
561 progtarget = builder:target( "#phony:prog", ptargets )
562 builder:add_target( progtarget, "build eLua firmware image", { "prog" } )
563 end
564
565 -- Create generic 'size' target
566 local size_target = builder:target( "#phony:size", { exetarget }, sizefunc )
567 size_target:force_rebuild( true )
568 builder:add_target( size_target, "shows the size of the eLua firmware", { "size" } )
b95dd84 Bogdan Marinescu - avr32 platform now uses the Lua build system (lua build_elua.lua board...
bogdanm authored
569
570 -- If the backend needs to do more processing before the build starts, do it now
571 if tools[ platform ].pre_build then
572 tools[ platform ].pre_build()
573 end
e3d6ee2 Bogdan Marinescu Continuing work on the build system, try 'lua build_elua.lua board=et-st...
bogdanm authored
574
575 -- Finally build everything
576 builder:build()
577
Something went wrong with that request. Please try again.