Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (103 loc) · 4.32 KB
/
Copy pathMakefile
File metadata and controls
132 lines (103 loc) · 4.32 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
CC := gcc
CXX := g++
PKG_LIBS := -lncursesw -lsqlite3
DB_LIBS := -lsqlite3
# Include search paths
INCLUDES := -I./src/include -I./include/
# Build modes
CFLAGS := -Wall -O2 -D_XOPEN_SOURCE=700 $(INCLUDES)
DEBUG_CFLAGS := -g -O0
RELEASE_CFLAGS := -O2
# Object dir
OBJDIR := obj
SRCDIR := src
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)
# Binary
BIN := leaderboard
# Database tool sources
DB_SRCDIR := src/backend
CREATE_SRC := $(DB_SRCDIR)/create.cpp
INSERT_SRC := $(DB_SRCDIR)/insertDelete.cpp
CREATE_BIN := $(DB_SRCDIR)/create
INSERT_BIN := $(DB_SRCDIR)/insertDelete
# ── Default: release build ─────────────────────────────────────────────
.PHONY: all
all: CFLAGS += $(RELEASE_CFLAGS)
all: $(BIN)
# ── Debug build ────────────────────────────────────────────────────────
.PHONY: debug
debug: CFLAGS += $(DEBUG_CFLAGS)
debug: clean $(BIN)
# ── Link ───────────────────────────────────────────────────────────────
$(BIN): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(PKG_LIBS)
# ── Compile .c -> .o and generate dependency .d ────────────────────────
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
# ── Ensure object dir exists ───────────────────────────────────────────
$(OBJDIR):
mkdir -p $(OBJDIR)
# ── Database tools ─────────────────────────────────────────────────────
$(CREATE_BIN): $(CREATE_SRC)
$(CXX) -O2 $< -o $@ $(DB_LIBS)
$(INSERT_BIN): $(INSERT_SRC)
$(CXX) -O2 $< -o $@ $(DB_LIBS)
# make db — create tables and insert all 20 products
.PHONY: db
db: $(CREATE_BIN)
$(CREATE_BIN)
@echo "Database ready."
# make resetdb — wipe and rebuild the database from scratch, also resets sync state
.PHONY: resetdb
resetdb:
@echo "Removing old database..."
rm -f $(DB_SRCDIR)/example.db
$(MAKE) db
@echo "Database reset"
rm -f sync_state.json
@echo "Sync reset"
# ── Run ────────────────────────────────────────────────────────────────
.PHONY: run
run: $(BIN)
./$(BIN)
# ── Install ────────────────────────────────────────────────────────────
PREFIX ?= /usr/local
.PHONY: install
install: $(BIN)
install -d $(DESTDIR)$(PREFIX)/bin
install -m 0755 $(BIN) $(DESTDIR)$(PREFIX)/bin/$(BIN)
# ── Strip binary for smaller release ───────────────────────────────────
.PHONY: strip
strip: $(BIN)
strip $(BIN)
# ── Clean ──────────────────────────────────────────────────────────────
.PHONY: clean
clean:
rm -rf $(OBJDIR) $(BIN)
# Clean including compiled db tools (but not the database itself)
.PHONY: cleanall
cleanall: clean
rm -f $(CREATE_BIN) $(INSERT_BIN)
# Note: only works with a synced db
.PHONY: test
test:
python3 test/test.py
.PHONY: sync
sync:
python3 src/scripts/sync.py
.PHONY: tidy
tidy:
find $(SRCDIR) -name '*.c' -print0 | xargs -0 clang-tidy -p .
.PHONY: tidy-fix
tidy-tix:
find $(SRCDIR) -name '*.c' -print0 | xargs -0 clang-tidy -p . -fix
.PHONY: format
format:
find $(SRCDIR) -name '*.c' -exec clang-format -i {} +
# ── Include auto-generated dependency files ────────────────────────────
-include $(DEPS)
# ── Phony convenience ──────────────────────────────────────────────────
.PHONY: rebuild
rebuild: clean all