about summary refs log tree commit diff
path: root/Makefile
blob: ad57dfce020bf8839f0f34585f9179e6ed6d4294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)