update build.lua and change char* to const char* #1

Merged
Blendi merged 1 commits from :main into main 2026-05-23 18:58:20 +02:00
3 changed files with 32 additions and 12 deletions

View File

@@ -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 -- 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 isBlendi = os.getenv("USER") == "blendi"
local seperator = package.config:sub(1,1) local separator = package.config:sub(1,1)
local function filename(path) local function filename(path)
local s,e = 1, #path local s,e = 1, #path
@@ -22,20 +22,18 @@ local function fixPath(path)
local new = "" local new = ""
for i = 1,#path do for i = 1,#path do
local ch = path:sub(i,i) local ch = path:sub(i,i)
if ch == '/' then new = new .. seperator if ch == '/' then new = new .. separator
else new = new .. ch end else new = new .. ch end
end end
return new return new
end end
if seperator == '\\' then if separator == '\\' then
runCommand('rmdir /S /Q build') runCommand('mkdir build 2>nul')
else else
runCommand('rm -rf build') runCommand('mkdir -p build')
end end
runCommand('mkdir build')
local files = { local files = {
'src/helper.c', 'src/helper.c',
'src/lexer.c', 'src/lexer.c',
@@ -47,8 +45,25 @@ local files = {
local objects = {} local objects = {}
local coolArgs = {} 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 if not isBlendi then table.insert(coolArgs, '-fsanitize=undefined,address') end
local needsLinking = false
for i = 1,#files do for i = 1,#files do
local fname = files[i] local fname = files[i]
local out = "build/" .. filename(fname) .. '.o' local out = "build/" .. filename(fname) .. '.o'
@@ -56,11 +71,16 @@ for i = 1,#files do
fname = fixPath(fname) fname = fixPath(fname)
out = fixPath(out) out = fixPath(out)
if needsRebuild(fname, out) then
needsLinking = true
runCommand('clang -c -o ' .. out .. ' ' .. fname .. ' ' .. table.concat(coolArgs, ' ')) runCommand('clang -c -o ' .. out .. ' ' .. fname .. ' ' .. table.concat(coolArgs, ' '))
end
objects[#objects+1] = out; objects[#objects+1] = out;
end 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

View File

@@ -1,7 +1,7 @@
#include "helper.h" #include "helper.h"
#include "types.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; noom_uint_t i = 0;
while (1) { while (1) {
if (compare[i] == '\0') return 1; // we did it if (compare[i] == '\0') return 1; // we did it

View File

@@ -1,6 +1,6 @@
#include "types.h" #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? 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); void* noom_alloc(noom_uint_t size);