-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
executable file
·87 lines (61 loc) · 1.75 KB
/
makefile
File metadata and controls
executable file
·87 lines (61 loc) · 1.75 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
NAME := Hanoi_Tower
SRC_DIR := src
LIB_DIR := lib
INC_DIR := ./include/
BUILD_DIR := build
BIN_DIR := bin
TESTS_DIR := ./tests
TESTS_INC_DIR := $(TESTS_DIR)/include/
DATA_DIR := data
DIRS += $(BUILD_DIR) $(BIN_DIR)
dbg ?= 0
asan ?= 0
num_disks ?= 3
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(SRC:src/%.c=build/%.o)
TEST_SRC := $(wildcard $(TESTS_DIR)/*.c)
INCS := $(wildcard $(INC_DIR)/*.h)
CC := gcc
CFLAGS := -Wall -Wextra -pedantic -std=gnu17 -D _GNU_SOURCE -D __STDC_WANT_LIB_EXT1__ -fPIC
LDFLAGS := -lm
TARGET := $(BIN_DIR)/$(NAME)
TEST_TARGET := $(BIN_DIR)/$(NAME)_test
ifeq ($(asan), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libsan -g
endif
ifeq ($(dbg), 1)
CFLAGS += -g -O0
else
CFLAGS += -O3
endif
$(OBJS): $(BUILD_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -I$(INC_DIR) -c $< -o $@ $(LDFLAGS)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(TEST_TARGET): $(OBJS)
$(CC) $(CFLAGS) -I$(TESTS_INC_DIR) -I$(INC_DIR) $(filter-out build/main.o, $(OBJS)) $(TEST_SRC) -o $@ -lcunit $(LDFLAGS)
all : build $(TARGET)
MAKE_DIRS :
@mkdir -p $(DIRS)
build : MAKE_DIRS $(OBJS)
check : all
valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes $(TARGET)
cache : all
valgrind --cachegrind-out-file=$(DATA_DIR)/cachegrind.out --tool=cachegrind $(TARGET)
cg_annotate $(DATA_DIR)/cachegrind.out > $(DATA_DIR)/cachegrind.annotate
test : build $(TEST_TARGET)
$(TEST_TARGET)
setup:
@sudo apt install -y valgrind
@sudo apt install -y lcunit1 libcunit1-dev libcuint1-doc
@sudo apt install -y clang
@sudo apt install -y bear
run : all
$(TARGET) $(num_disks)
debug: all
gdb $(TARGET)
clean :
$(RM) $(OBJS)
$(RM) $(BIN_DIR)/*
$(RM) $(DATA_DIR)/cachegrind*
.PHONY: all clean run check test setup