Skip to content

Commit

Permalink
Now updates selectively based off of if an exe or dll was changed or …
Browse files Browse the repository at this point in the history
…the source was updated, compiles whatever it needs, and links it all together
  • Loading branch information
tilkinsc committed Jan 2, 2018
1 parent a35a395 commit c9d4d92
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 29 deletions.
88 changes: 60 additions & 28 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@ require("build_func")
require("build_setup")


local targ_compile_units = {
"console.c", "consolew.c", "darr.c";
"additions.c";
}

local targ_dir = (gcc.debug and "DEBUG" or "RELEASE")

local targ_exe = {enc_exe("lua"), enc_exe("luaw")}
local targ_dll = {enc_dll("luaadd")}
local targ_units1 = {"console.c", "consolew.c", "darr.c"}
local targ_units2 = {"additions.c"}

local targ_compile_units1 = check_cache(targ_units1, "src/", "obj/", "o")
local targ_compile_units2 = check_cache(targ_units2, "src/", "obj/", "o")
local targ_end = check_cache({"libluaadd.dll.a"}, "obj/", "obj/", "a")

local exe_test =
check_bin_cache(targ_exe, "src/", install_path .. "\\", targ_units1)
or check_bin_cache(targ_exe, "src/", install_path .. "\\", targ_units2)
or check_bin_cache(targ_dll, "src/", install_path .. "\\", targ_units1)
or check_bin_cache(targ_dll, "src/", install_path .. "\\", targ_units2)



local std_libs = enc_dll(" -llua53") .. choose_opt("", " -lm -ldl", " -lm -ldl")
Expand All @@ -36,8 +50,9 @@ local targ_luaw_exe_o = {"consolew.o", "darr.o"}
local targ_lua_exe_libs = std_libs .. " -lluaadd.dll"



-- compile string
local compile_str = gcc_c(
local compile_str1 = gcc_c(
gcc.g,
gcc.O,
gcc.warnings,
Expand All @@ -46,9 +61,19 @@ local compile_str = gcc_c(
gcc.ccextras,
gcc.include_dir,
gcc.library_dir,
targ_compile_units)


targ_compile_units1)

local compile_str2 = gcc_c(
gcc.g,
gcc.O,
gcc.warnings,
gcc.extra_warnings,
gcc.defines,
gcc.ccextras,
gcc.include_dir,
gcc.library_dir,
targ_compile_units2)

-- generate dll/so string
local linker_str_dll1 = choose_gcc_dll()(
targ_luaadd_dll_a,
Expand Down Expand Up @@ -94,29 +119,36 @@ local linker_str_exe2 = gcc_l(
targ_lua_exe_libs)


-- compile
compiler_exec((gcc.debug and "DEBUG" or "RELEASE"), compile_str)

-- cleanup
obj_transfer()

-- link dll
linker_exec(enc_dll("libluaadd") .. ".a" .. enc_dll(" luaadd"), linker_str_dll1)

-- cleanup
obj_transfer()

-- link exe
linker_exec("lua", linker_str_exe1)
linker_exec("luaw", linker_str_exe2)
-- compile
if(#targ_compile_units1 > 0 or exe_test or force)then
compiler_exec(targ_dir, compile_str1)
obj_transfer()
end
if(#targ_compile_units2 > 0 or exe_test or force)then
compiler_exec(targ_dir, compile_str2)
obj_transfer()
end


-- strip redundancy
if(not gcc.debug)then
strip_targ(enc_exe("lua"))
strip_targ(enc_exe("luaw"))
if(#targ_compile_units1 + #targ_compile_units2 > 0 or exe_test or force)then
-- link dll
linker_exec(enc_dll("libluaadd") .. ".a" .. enc_dll(" luaadd"), linker_str_dll1)
obj_transfer()

-- link exe
linker_exec("lua", linker_str_exe1)
linker_exec("luaw", linker_str_exe2)

-- strip redundancy
if(not gcc.debug)then
strip_targ(enc_exe("lua"))
strip_targ(enc_exe("luaw"))
end

-- setup
migrate_binaries(install_path, {enc_exe("lua"), enc_exe("luaw"), enc_dll("luaadd")})
end
print("Done. Up to date.")

-- setup
migrate_binaries(install_path, {enc_exe("lua"), enc_exe("luaw"), enc_dll("luaadd")})

29 changes: 28 additions & 1 deletion build_func.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ gcc_so = function(lib_name, g, O, warnings, extrawarn, defines, extra, includesd
end


check_cache = function(target, pref1, pref2, endtype)
local invalid_cache = {}
for i, v in next, target do
local cu = io.mtime(pref1 .. v)
local obj = io.mtime(pref2 .. v:sub(0,-1 - #endtype) .. endtype)
if(cu ~= nil)then
if(obj == nil or cu > obj)then
table.insert(invalid_cache, v)
end
end
end
return invalid_cache
end

check_bin_cache = function(binaries, pref1, pref2, target)
for i, v in next, target do
for l, g in next, binaries do
local obj = io.mtime(pref1 .. v)
local bin = io.mtime(pref2 .. g)
if(bin == nil or obj > bin)then
return true
end
end
end
return false
end


compiler_exec = function(target, str)
print(">>> Compiling for `" .. target .. "`")
Expand All @@ -112,7 +139,7 @@ end

strip_targ = function(target)
print(">>> Stripping `" .. target .. "`")
os.execute("strip " .. enc_exe)
os.execute("strip " .. enc_exe(target))
end

migrate_binaries = function(install_path, binaries)
Expand Down

0 comments on commit c9d4d92

Please sign in to comment.