-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (44 loc) · 1.47 KB
/
Makefile
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
LDFLAGS :=
TARGET_EXEC := bin
BUILD_DIR := ./build
SRC_DIR := ./src
CC := gcc
CPPFLAGS := -MMD -MP
CFLAGS_RELEASE := -O3 -flto=auto -DNDEBUG
CFLAGS_PROFILE := -O3 -flto=auto -g
CFLAGS_DEBUG := -O0 -ggdb3
CFLAGS_DEV := -O0 -g3 -fsanitize=address,undefined -Werror -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wlogical-op -Wswitch-default -Wswitch-enum -Wconversion -Winline -Wdouble-promotion -pedantic-errors -std=c17
ifeq ($(MAKECMDGOALS),release)
CFLAGS := $(CFLAGS_RELEASE)
else ifeq ($(MAKECMDGOALS),profile)
CFLAGS := $(CFLAGS_PROFILE)
else ifeq ($(MAKECMDGOALS),debug)
CFLAGS := $(CFLAGS_DEBUG)
else
CFLAGS := $(CFLAGS_DEV)
endif
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
.PHONY: all release profile debug run clean clang
all: $(BUILD_DIR)/$(TARGET_EXEC)
$(BUILD_DIR):
@mkdir -p $@
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
@$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
release: clean all
profile: clean all
@perf record -g --freq=max -o $(BUILD_DIR)/perf.data $(BUILD_DIR)/$(TARGET_EXEC) $(ARGS)
@perf script -i $(BUILD_DIR)/perf.data | stackcollapse-perf.pl | flamegraph.pl > $(BUILD_DIR)/flamegraph.svg
@chromium $(BUILD_DIR)/flamegraph.svg
debug: clean all
@gdbgui '$(BUILD_DIR)/$(TARGET_EXEC) $(ARGS)'
run:
@$(BUILD_DIR)/$(TARGET_EXEC) $(ARGS)
clean:
@rm -rf $(BUILD_DIR)
clang: clean
@bear -- make
-include $(DEPS)