-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (65 loc) · 2.43 KB
/
Copy pathMakefile
File metadata and controls
79 lines (65 loc) · 2.43 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
# Makefile — X-Optimizer (C11)
# Targets: all, debug, test, clean, install, install-updater, valgrind
CC := gcc
CFLAGS := -std=c11 -Wall -Wextra -Wpedantic -Wshadow \
-Wformat=2 -Wundef -fstack-protector-strong \
-D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE
LDFLAGS :=
TARGET := xoptimizer
PREFIX := /usr/local
SRC_DIR := src
INC_DIR := include
BLD_DIR := build
SRCS := $(SRC_DIR)/log.c \
$(SRC_DIR)/arena.c \
$(SRC_DIR)/string_utils.c \
$(SRC_DIR)/trie.c \
$(SRC_DIR)/cidr.c \
$(SRC_DIR)/rules.c \
$(SRC_DIR)/resolver.c \
$(SRC_DIR)/ipc_server.c \
$(SRC_DIR)/optimizer_core.c \
$(SRC_DIR)/main.c
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BLD_DIR)/%.o,$(SRCS))
# ── Targets ─────────────────────────────────────────────────────────────
.PHONY: all debug test clean install install-updater valgrind
all: CFLAGS += -O2 -DNDEBUG
all: $(BLD_DIR)/$(TARGET)
debug: CFLAGS += -g3 -O0 -fsanitize=address,undefined
debug: LDFLAGS += -fsanitize=address,undefined
debug: $(BLD_DIR)/$(TARGET)
$(BLD_DIR)/$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
@echo "Built: $@"
$(BLD_DIR)/%.o: $(SRC_DIR)/%.c | $(BLD_DIR)
$(CC) $(CFLAGS) -I$(INC_DIR) -c -o $@ $<
$(BLD_DIR):
mkdir -p $(BLD_DIR)
clean:
rm -rf $(BLD_DIR)
install: all
install -Dm755 $(BLD_DIR)/$(TARGET) $(PREFIX)/bin/$(TARGET)
install -Dm644 xoptimizer.service \
/etc/systemd/system/xoptimizer.service
systemctl daemon-reload
install-updater:
install -Dm755 tools/update_rules.sh \
$(PREFIX)/libexec/xoptimizer/update_rules.sh
install -Dm644 xoptimizer-rules-update.service \
/etc/systemd/system/xoptimizer-rules-update.service
install -Dm644 xoptimizer-rules-update.timer \
/etc/systemd/system/xoptimizer-rules-update.timer
systemctl daemon-reload
valgrind: debug
valgrind --leak-check=full --track-origins=yes \
--error-exitcode=1 \
$(BLD_DIR)/$(TARGET) -s /tmp/xopt-valgrind.sock &
sleep 1
echo '{"type":"ping"}' | socat - UNIX-CONNECT:/tmp/xopt-valgrind.sock
echo '{"type":"lookup","domain":"yandex.ru"}' | \
socat - UNIX-CONNECT:/tmp/xopt-valgrind.sock
echo '{"type":"lookup","domain":"google.com"}' | \
socat - UNIX-CONNECT:/tmp/xopt-valgrind.sock
echo '{"type":"stats"}' | socat - UNIX-CONNECT:/tmp/xopt-valgrind.sock
kill %1
@echo "Valgrind run complete"