-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (50 loc) · 1.66 KB
/
Makefile
File metadata and controls
67 lines (50 loc) · 1.66 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# --- Variables ---
BIN_DIR ?= $(realpath .)/bin
OUTPUT_NAME ?= main
CC := $(realpath ./cosmocc/bin/cosmocc)
ZIPCOPY := $(realpath ./cosmocc/bin/zipcopy)
LUA_VERSION := 5.4.8
LUA_DIR := lib/lua-$(LUA_VERSION)
LUA_SRC_DIR := $(LUA_DIR)/src
TARGET := $(BIN_DIR)/main
# Flags
LUA_INC := -I$(LUA_SRC_DIR)
CFLAGS := $(LUA_INC)
LDFLAGS :=
# Source files (main.c and all Lua source files except lua.c and luac.c which are for the stand-alone interpreters)
MAIN_OBJ := main.o
LUA_SRCS := $(wildcard $(LUA_SRC_DIR)/*.c)
# Exclude lua.c and luac.c from compilation for the library
LUA_LIB_SRCS := $(filter-out $(LUA_SRC_DIR)/lua.c $(LUA_SRC_DIR)/luac.c, $(LUA_SRCS))
LUA_OBJS := $(patsubst $(LUA_SRC_DIR)/%.c, $(LUA_SRC_DIR)/%.o, $(LUA_LIB_SRCS))
# --- Phony Targets ---
.PHONY: all append-zip build clean clean-link-target rebuild
# --- all Target ---
all: clean-link-target $(TARGET) append-zip
# --- append-zip Target ---
append-zip:
ifdef ZIP_EXTRAS_DIR
(cd $(ZIP_EXTRAS_DIR) && zip -r $(BIN_DIR)/embed.zip . > /dev/null)
$(ZIPCOPY) $(BIN_DIR)/embed.zip $(BIN_DIR)/$(OUTPUT_NAME)
endif
# --- Link Rules ---
$(TARGET): $(MAIN_OBJ) $(LUA_OBJS)
@echo "Linking..."
mkdir -p $(BIN_DIR)
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$(OUTPUT_NAME) $(MAIN_OBJ) $(LUA_OBJS)
# --- Compilation Rules ---
$(MAIN_OBJ): main.c
@echo "Compiling $<"
$(CC) $(CFLAGS) -c $<
$(LUA_SRC_DIR)/%.o: $(LUA_SRC_DIR)/%.c
@echo "Compiling $<"
(cd $(LUA_SRC_DIR) && $(CC) -c $(notdir $<))
# --- Utility Targets ---
clean-link-target:
rm -rf $(BIN_DIR)
clean:
rm -rf $(BIN_DIR)
rm -f $(MAIN_OBJ)
rm -f $(LUA_SRC_DIR)/*.o
rm -rf $(LUA_SRC_DIR)/../.aarch64
rebuild: clean all