From 66f8c102a5101cd1d213ff574ad0ea1778ac5864 Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Tue, 5 Jun 2018 19:17:58 +0300 Subject: [PATCH] New cross-compiler mode: "compile_raw" The new mode compiles the Lua files to .lc (bytecode) files for later use. This should be replaced later with a proper script dedicated to cross-compiling Lua sources. --- utils/mkfs.lua | 76 ++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/utils/mkfs.lua b/utils/mkfs.lua index c1b22fcf..fa18245a 100644 --- a/utils/mkfs.lua +++ b/utils/mkfs.lua @@ -38,6 +38,7 @@ end -- mode - preprocess the file system: -- "verbatim" - copy the files directly to the FS as they are -- "compile" - precompile all files to Lua bytecode and then copy them +-- "compile_raw" - precompile all files to Lua bytecode for direct loading, IE, leave as individual *.lc scripts -- "compress" - keep the source code, but compress it with LuaSrcDiet -- compcmd - the command to use for compiling if "mode" is "compile" -- Returns true for OK, false for error @@ -50,15 +51,19 @@ function mkfs( dirname, outname, flist, mode, compcmd ) return false end + print( sf( "Generating file %s/%s", dirname, outfname ) ) + _crtline = ' ' _numdata = 0 _bytecnt = 0 - -- Generate headers - outfile:write( "// Generated by mkfs.lua\n// DO NOT MODIFY\n\n" ) - outfile:write( sf( "#ifndef __%s_H__\n#define __%s_H__\n\n", outname:upper(), outname:upper() ) ) + if mode ~= "compile_raw" then + -- Generate headers + outfile:write( "// Generated by mkfs.lua\n// DO NOT MODIFY\n\n" ) + outfile:write( sf( "#ifndef __%s_H__\n#define __%s_H__\n\n", outname:upper(), outname:upper() ) ) - outfile:write( sf( "const unsigned char %s_fs[] = \n{\n", outname:lower() ) ) + outfile:write( sf( "const unsigned char %s_fs[] = \n{\n", outname:lower() ) ) + end -- Process all files for _, fname in pairs( flist ) do @@ -81,7 +86,7 @@ function mkfs( dirname, outname, flist, mode, compcmd ) end -- Do we need to process the file? local fextpart, fnamepart = '' - if mode == "compile" or mode == "compress" then + if mode == "compile" or mode == "compile_raw" or mode == "compress" then fnamepart, fextpart = utils.split_ext( realname ) local newext = mode == "compress" and ".lua.tmp" or ".lc" if fextpart == ".lua" then @@ -91,6 +96,7 @@ function mkfs( dirname, outname, flist, mode, compcmd ) else print( sf( "Cross compiling %s to %s ...", realname, newname ) ) end + print( "Cross compile command:" .. sf( compcmd, newname, realname ) ) if os.execute( sf( compcmd, newname, realname ) ) ~= 0 then print "Cross-compilation error, aborting" outfile:close() @@ -105,7 +111,7 @@ function mkfs( dirname, outname, flist, mode, compcmd ) print( sf( "Unable to read %s", newname ) ) return false end - if mode == "compile" then + if mode == "compile" or mode == "compile_raw" then fnamepart, fextpart = utils.split_ext( fname ) fname = fnamepart .. ".lc" end @@ -113,40 +119,44 @@ function mkfs( dirname, outname, flist, mode, compcmd ) end local filedata = crtfile:read( '*a' ) crtfile:close() - if fextpart == ".lua" and mode ~= "verbatim" then + if fextpart == ".lua" and mode ~= "verbatim" and mode ~= "compile_raw" then os.remove( newname ) end - -- Write name, size, id, numpars - _fcnt = 0 - for i = 1, #fname do - _add_data( fname:byte( i ), outfile ) + if mode ~= "compile_raw" then + -- Write name, size, id, numpars + _fcnt = 0 + for i = 1, #fname do + _add_data( fname:byte( i ), outfile ) + end + _add_data( 0, outfile ) -- ASCIIZ + local plen = string.pack( "