lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Why exactly are you merging together the headers as well? That is for "ease of use" (which is questionable), not for speed, right?

For just getting the compiler optimizations, simply concatenating the .c's together would be enough? Roberto mentioned to have a Makefile target for this in upcoming versions, that would indeed be fine.


dcharno kirjoitti 15.2.2009 kello 19:49:

I was reading the following page related to the SQLite project:
and found this:
"In addition to making SQLite easier to incorporate into other projects, the amalgamation also makes it run faster. Many compilers are able to do additional optimizations on code when it is contained with in a single translation unit such as it is in the amalgamation. We have measured performance improvements of between 5 and 10% when we use the amalgamation to compile SQLite rather than individual source files."

This is an old thread, but ...

After using SQLite in a number of projects I really came to appreciate the convenience of the amalgamation approach. etc/all.c helps quite a bit, but it is nice dealing with fewer files.

The attached script makes amalgamated C and header files based upon all.c. To use them in a project, just build in am-lua.c and include am-lua.h. Maybe someone else finds it useful

-- Copy inputs to output, inlining any Lua #include once

local PREFIX = "am-"
local SRC_PATH = "../src/"

function CreateAmalgamation(ofilename, files)

 local out = assert(, "w"))
 local headers = { ["lua.c"]=true }

 function CopyWithInline(filename)
 if headers[filename] == nil then
   headers[filename] = true

   local inp = assert( .. filename, "r"))
     for l in inp:lines() do
       local inc = l:match('#include "([^"]+)"')
       if inc and (inc ~= "luaconf.h") then
         out:write(l .. "\n")

 for _, file in ipairs(files) do


CreateAmalgamation(PREFIX.."lua.c", {"../etc/all.c"})
CreateAmalgamation(PREFIX.."lua.h", { "lua.h", "lauxlib.h", "lualib.h"})