-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
53 lines (38 loc) · 866 Bytes
/
Makefile
File metadata and controls
53 lines (38 loc) · 866 Bytes
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
CC=gcc
CF=-Iinclude
LDF=-lm -lpthread
MAKEFLAGS+=-j
BIN_DIR=bin
OBJ_DIR=obj
SRC_DIR=src
TARGET=$(BIN_DIR)/Redis
C_FILES=$(wildcard $(SRC_DIR)/*.c)
OBJECT_FILES:=$(subst .c,.o, ${C_FILES})
OBJECT_FILES:=$(subst $(SRC_DIR),$(OBJ_DIR), $(OBJECT_FILES))
mode?=debug
ifeq ($(mode), debug)
CF+=-g3 -fsanitize=address,undefined -Wall -Wno-unused-value -Wno-unused-variable
else ifeq ($(mode), release)
# `-flto` is a real magic ^_^
CF+=-Ofast -s -flto
else
$?=1
endif
all: print-mode $(OBJ_DIR) $(BIN_DIR) $(TARGET)
print-mode:
@echo "[!] Build mode: $(mode)"
gdb_debug: $(TARGET)
gdb $<
clean:
@rm -f bin/* obj/*
$(OBJ_DIR):
mkdir $@
$(BIN_DIR):
mkdir $@
obj/%.o: src/%.c
@echo "[*] Compiling $<"
@$(CC) -c $(CF) -o $@ $<
$(TARGET): $(OBJECT_FILES)
@echo "[*] Linking all together"
@$(CC) -o $@ $^ $(CF) $(LDF)
.PHONY: all clean run gdb_debug