CC := clang LUAC := luac CFLAGS := -Wall -Wextra -O2 -std=c11 -MMD -MP CPPFLAGS := -I/opt/homebrew/include LDFLAGS := -L/opt/homebrew/lib LDLIBS := /opt/homebrew/lib/liblua.a -lncurses -lm TARGET := lume SRC := main.c lua_bytecode.c OBJ := $(SRC:.c=.o) DEP := $(OBJ:.o=.d) .PHONY: all clean run all: $(TARGET) lua_bytecode.c: main.lua @echo "Compiling Lua to bytecode..." $(LUAC) -o main.luac main.lua @echo "Generating C array..." #@echo 'const char lua_bytecode[] = {' > lua_bytecode.c #@od -An -tx1 -v main.luac | sed 's/ *\([0-9a-f][0-9a-f]\)/0x\1,/g' | sed 's/,$$//' >> lua_bytecode.c @xxd -i main.luac > lua_bytecode.c #@echo '};' >> lua_bytecode.c #@echo 'const unsigned int lua_bytecode_len = sizeof(lua_bytecode);' >> lua_bytecode.c @rm -f main.luac $(TARGET): $(OBJ) $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -include $(DEP) clean: rm -f $(OBJ) $(TARGET) $(DEP) lua_bytecode.c main.luac run: $(TARGET) ./$(TARGET)