From 9074c4c6f270f554db7ad7d5afbf44f7db66a475 Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Thu, 17 May 2018 00:59:24 +0300 Subject: [PATCH 1/2] Multiple fixes - Use the proper suffix in Windows for cross-compilation - Add a boolean attribute type - Increased number of virtual UARTs - Updated README.asciidoc with more information on how to cross-compile in Windows --- README.asciidoc | 12 ++++++++++++ config/attributes.lua | 14 ++++++++++++++ config/constants.lua | 2 +- cross-lua.lua | 3 ++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index bb42b6da..c467514e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -11,6 +11,18 @@ page]. If you've just downloaded *eLua* and are looking to get started check out link:http://www.eluaproject.net/en_using.html[using eLua]. +Windows Cross Compiling Update +---------------- + +To cross compile scripts on Windows (cross-lua), you'll need to install a few packages: + +* A GCC compiler. link:http://tdm-gcc.tdragon.net/index.php[TDM-GCC] was tested, + but other GCC for Windows distributions should work. +* Python 2.7 (from link:http://www.python.org[python.org] or other distributions). +* link:https://github.com/rjpcomputing/luaforwindows/releases/[Lua for Windows]. + +Run lua cross-lua.lua and then you're ready to cross compile Lua scripts! + General Features ---------------- diff --git a/config/attributes.lua b/config/attributes.lua index 2c980a2c..c2cc739d 100644 --- a/config/attributes.lua +++ b/config/attributes.lua @@ -96,6 +96,14 @@ local function _validate_ip( adesc, aname, aval, elname, sectname ) return aval end +-- Validator for a boolean value +local function _validate_bool( adesc, aname, aval, elname, sectname ) + if type( aval ) ~= "boolean" then + return false, sf( "attribute '%s' of element '%s' in section '%s' must be a boolean", aname, elname, sectname) + end + return aval and 1 or 0 +end + -- Builds a validator with the given array element checker local function build_validator( realvname ) return function( adesc, aname, aval, elname, sectname ) @@ -124,6 +132,7 @@ local validate_choice = build_validator( _validate_choice ) local validate_log2 = build_validator( _validate_log2 ) local validate_string = build_validator( _validate_string ) local validate_ip = build_validator( _validate_ip ) +local validate_bool = build_validator( _validate_bool ) -- Composite validator: run each validator in turn local function composite_validator( adesc, aname, aval, elname, sectname ) @@ -219,3 +228,8 @@ function nostr( attr ) return attr end +-- Returns a new boolean attr (can be either true or false) +function bool_attr( macro, default ) + return { macro = macro, validator = validate_bool, default = default } +end + diff --git a/config/constants.lua b/config/constants.lua index 21d8f5a5..a147aa92 100644 --- a/config/constants.lua +++ b/config/constants.lua @@ -18,7 +18,7 @@ uart_flow = uart_values = {} -- Add a sufficient number of virtual and real UARTs -for i = 0, 127 do +for i = 0, 255 do uart_values[ sf( 'vuart%d', i ) ] = sf( '( SERMUX_SERVICE_ID_FIRST + %d )', i ) uart_values[ tostring( i ) ] = i end diff --git a/cross-lua.lua b/cross-lua.lua index 5e92f997..5d377c98 100644 --- a/cross-lua.lua +++ b/cross-lua.lua @@ -6,7 +6,8 @@ local sf = string.format builder:init( args ) builder:set_build_mode( builder.BUILD_DIR_LINEARIZED ) -local output = 'luac.cross' +local suffix = utils.is_windows() and '.exe' or '' +local output = 'luac.cross' .. suffix local cdefs = '-DLUA_CROSS_COMPILER' -- Lua source files and include path From a1e677012309281582b08d57fde99db58f09e83f Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Sat, 19 May 2018 00:54:56 +0300 Subject: [PATCH 2/2] Always create build directory for cross compiler --- cross-lua.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cross-lua.lua b/cross-lua.lua index 5d377c98..ba22a0ee 100644 --- a/cross-lua.lua +++ b/cross-lua.lua @@ -22,6 +22,13 @@ local local_include = "-Isrc/lua -Iinc/desktop -Iinc" builder:set_compile_cmd( sf( "gcc -O2 %s -Wall %s -c $(FIRST) -o $(TARGET)", local_include, cdefs ) ) builder:set_link_cmd( "gcc -o $(TARGET) $(DEPENDS) -lm" ) +if not utils.is_dir( ".build" ) then + if not utils.full_mkdir( ".build" ) then + print( "[builder] Unable to create directory .build" ) + os.exit( 1 ) + end +end + -- Build everything builder:make_exe_target( output, lua_full_files ) builder:build()