Merge pull request 'update build.lua and change char* to const char*' (#1) from tema5002/noom:main into main

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
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
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

View File

@@ -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

View File

@@ -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);