-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (135 loc) · 4.83 KB
/
Makefile
File metadata and controls
164 lines (135 loc) · 4.83 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# CupidChat build system
# Targets: cupid-chatd (server binary)
# cupid-chat (client TUI binary)
# test-* (unit-test binaries)
# all / clean / check
#
# Requires: gcc (C11), ncurses-dev, libreadline (optional)
# TLS: pass TLS=1 to enable OpenSSL (skeleton is wired in already)
#
CC := gcc
STD := -std=c11
WARN := -Wall -Wextra -Wpedantic -Wno-unused-parameter -Werror
SAN := -fsanitize=address,undefined -fno-omit-frame-pointer
OPT := -O2 -g $(SAN)
DEFS := -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CFLAGS := $(STD) $(WARN) $(OPT) $(DEFS) -Iinclude -MMD -MP
# Keep 'all' as the default goal even though generated-file rules appear
# before it in this file.
.DEFAULT_GOAL := all
# Optional TLS (OpenSSL)
ifeq ($(TLS),1)
CFLAGS += -DCUPID_TLS
LDTLS := -lssl -lcrypto
else
LDTLS :=
endif
# Directories
BUILDDIR := build
SRVDIR := src/server
CLIDIR := src/client
SHDIR := src/shared
TESTDIR := tests
$(shell mkdir -p $(BUILDDIR)/server/core \
$(BUILDDIR)/server/util \
$(BUILDDIR)/server/db \
$(BUILDDIR)/server \
$(BUILDDIR)/client/net \
$(BUILDDIR)/client/state \
$(BUILDDIR)/client/ui \
$(BUILDDIR)/shared/proto \
$(BUILDDIR)/shared/net \
$(BUILDDIR)/tests/proto \
$(BUILDDIR)/tests/server)
# Embedded sound data — generated from sounds/*.wav at build time
SOUNDS_GEN_C := src/client/sounds_data.c
SOUNDS_GEN_H := include/client/sounds_data.h
# N.B. "You've Got Mail.wav" is omitted — make cannot handle apostrophes in
# prerequisite names. Modify gen_sounds.py or touch any listed WAV to force
# regeneration if that file changes.
SOUNDS_WAVS := sounds/Welcome.wav sounds/Goodbye.wav \
sounds/IM.wav sounds/BuddyIn.wav sounds/BuddyOut.wav
$(SOUNDS_GEN_C) $(SOUNDS_GEN_H): $(SOUNDS_WAVS) scripts/gen_sounds.py
@echo " GEN sounds_data"
@python3 scripts/gen_sounds.py sounds $(SOUNDS_GEN_C) $(SOUNDS_GEN_H)
# Shared sources
SHARED_SRC := \
$(SHDIR)/proto/frame.c \
$(SHDIR)/proto/tlv.c \
$(SHDIR)/net/transport_posix.c
ifeq ($(TLS),1)
SHARED_SRC += $(SHDIR)/net/transport_tls.c
else
SHARED_SRC += $(SHDIR)/net/transport_tls_stub.c
endif
SHARED_OBJ := $(patsubst src/%.c, $(BUILDDIR)/%.o, $(SHARED_SRC))
# Server sources
SERVER_SRC := \
$(SRVDIR)/main.c \
$(SRVDIR)/core/loop.c \
$(SRVDIR)/core/conn.c \
$(SRVDIR)/core/dispatch.c \
$(SRVDIR)/core/room.c \
$(SRVDIR)/core/state.c \
$(SRVDIR)/core/keepalive.c \
$(SRVDIR)/core/rate_limit.c \
$(SRVDIR)/core/backpressure.c \
$(SRVDIR)/util/log.c \
$(SRVDIR)/util/config.c \
$(SRVDIR)/db/db.c
SERVER_OBJ := $(patsubst src/%.c, $(BUILDDIR)/%.o, $(SERVER_SRC))
SERVER_BIN := cupid-chatd
# Client sources
CLIENT_SRC := \
$(CLIDIR)/main.c \
$(CLIDIR)/net/client_conn.c \
$(CLIDIR)/state/model.c \
$(CLIDIR)/state/history.c \
$(CLIDIR)/ui/layout.c \
$(CLIDIR)/ui/input.c \
$(CLIDIR)/ui/render.c \
$(CLIDIR)/sound.c \
$(SOUNDS_GEN_C)
CLIENT_OBJ := $(patsubst src/%.c, $(BUILDDIR)/%.o, $(CLIENT_SRC))
# Ensure the generated header exists before any client source is compiled.
# The .d files track it for rebuilds; this covers the initial build.
$(CLIENT_OBJ): | $(SOUNDS_GEN_H)
CLIENT_BIN := cupid-chat
# Test sources
TEST_BINS := \
$(BUILDDIR)/tests/proto/test_frame \
$(BUILDDIR)/tests/proto/test_tlv \
$(BUILDDIR)/tests/server/test_rate_limit
# Default target
.PHONY: all clean check install
all: $(SERVER_BIN) $(CLIENT_BIN)
# Link binaries
$(SERVER_BIN): $(SERVER_OBJ) $(SHARED_OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(LDTLS) -lsqlite3 -lcrypt
$(CLIENT_BIN): $(CLIENT_OBJ) $(SHARED_OBJ)
$(CC) $(CFLAGS) $^ -o $@ -lncurses $(LDTLS)
# Compile rule
$(BUILDDIR)/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@
# Tests
$(BUILDDIR)/tests/proto/test_frame: $(TESTDIR)/proto/test_frame.c $(SHARED_OBJ)
$(CC) $(CFLAGS) $^ -o $@
$(BUILDDIR)/tests/proto/test_tlv: $(TESTDIR)/proto/test_tlv.c $(SHARED_OBJ)
$(CC) $(CFLAGS) $^ -o $@
$(BUILDDIR)/tests/server/test_rate_limit: \
$(TESTDIR)/server/test_rate_limit.c \
$(BUILDDIR)/server/core/rate_limit.o \
$(SHARED_OBJ)
$(CC) $(CFLAGS) $^ -o $@
check: $(TEST_BINS)
@echo "=== Running unit tests ==="
@for t in $(TEST_BINS); do echo "--- $$t ---"; $$t; done
@echo "=== All tests done ==="
clean:
rm -rf $(BUILDDIR) $(SERVER_BIN) $(CLIENT_BIN) \
$(SOUNDS_GEN_C) $(SOUNDS_GEN_H)
# Auto-generated header dependencies
-include $(shell find $(BUILDDIR) -name '*.d' 2>/dev/null)
install: all
install -Dm755 $(SERVER_BIN) /usr/local/bin/$(SERVER_BIN)
install -Dm755 $(CLIENT_BIN) /usr/local/bin/$(CLIENT_BIN)