diff --git a/build.lua b/build.lua index 2a091cc..397a71b 100644 --- a/build.lua +++ b/build.lua @@ -1,7 +1,7 @@ -- i love build scripts i love build scripts i love build scripts scripts build love i script build love me i love script build i script love build local isBlendi = os.getenv("USER") == "blendi" -local seperator = package.config:sub(1,1) +local separator = package.config:sub(1,1) local function filename(path) local s,e = 1, #path @@ -22,20 +22,18 @@ local function fixPath(path) local new = "" for i = 1,#path do local ch = path:sub(i,i) - if ch == '/' then new = new .. seperator + if ch == '/' then new = new .. separator else new = new .. ch end end return new end -if seperator == '\\' then - runCommand('rmdir /S /Q build') +if separator == '\\' then + runCommand('mkdir build 2>nul') else - runCommand('rm -rf build') + runCommand('mkdir -p build') end -runCommand('mkdir build') - local files = { 'src/helper.c', 'src/lexer.c', @@ -47,8 +45,25 @@ local files = { local objects = {} local coolArgs = {} + +local function getTime(path) + local handle = io.popen('stat -c %Y "' .. path .. '" 2>/dev/null') + local result = handle:read("*a") + handle:close() + return tonumber(result) or 0 +end + +local function needsRebuild(src, obj) + if separator == '\\' then return true end + local srcTime = getTime(src) + local objTime = getTime(obj) + return srcTime > objTime +end + if not isBlendi then table.insert(coolArgs, '-fsanitize=undefined,address') end +local needsLinking = false + for i = 1,#files do local fname = files[i] local out = "build/" .. filename(fname) .. '.o' @@ -56,11 +71,16 @@ for i = 1,#files do fname = fixPath(fname) out = fixPath(out) - runCommand('clang -c -o ' .. out .. ' ' .. fname .. ' ' .. table.concat(coolArgs, ' ')) + if needsRebuild(fname, out) then + needsLinking = true + runCommand('clang -c -o ' .. out .. ' ' .. fname .. ' ' .. table.concat(coolArgs, ' ')) + end objects[#objects+1] = out; end -local exe = seperator == '\\' and "noom.exe" or "noom" +local exe = separator == '\\' and "noom.exe" or "noom" -runCommand('clang -o ' .. exe .. ' ' .. table.concat(objects, ' ') .. ' ' .. table.concat(coolArgs, ' ')) +if needsLinking then + runCommand('clang -o ' .. exe .. ' ' .. table.concat(objects, ' ') .. ' ' .. table.concat(coolArgs, ' ')) +end diff --git a/src/helper.c b/src/helper.c index d6415a1..84f6c92 100644 --- a/src/helper.c +++ b/src/helper.c @@ -1,7 +1,7 @@ #include "helper.h" #include "types.h" -int noom_startswith(const char* str, char* compare) { +int noom_startswith(const char* str, const char* compare) { noom_uint_t i = 0; while (1) { if (compare[i] == '\0') return 1; // we did it diff --git a/src/helper.h b/src/helper.h index 9702158..b39b5ab 100644 --- a/src/helper.h +++ b/src/helper.h @@ -1,6 +1,6 @@ #include "types.h" -int noom_startswith(const char* str, char* compare); +int noom_startswith(const char* str, const char* compare); int noom_streql(const char* stra, noom_uint_t lena, const char* strb, noom_uint_t lenb); // rename to something better? void* noom_alloc(noom_uint_t size);