-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
93 lines (62 loc) · 2.11 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
C = cc
GP = gprof
C_GP_FLAGS = -pg
C_DEBUG_FLAGS = -Wall -Wextra -pedantic -ggdb -fPIC
C_COMPILE_FLAGS = -O2 -DNDEBUG -fno-stack-protector -z execstack -no-pie -fPIC
C_FLAGS = $(C_GP_FLAGS) $(C_DEBUG_FLAGS)
C_LIBS_FLAGS = -lexcept
C_FLAGS_WHOLE_ARCHIVE = -Wl,--whole-archive
C_FLAGS_NO_WHOLE_ARCHIVE = -Wl,--no-whole-archive
AR = ar rc
BUILD_DIR = build
OBJ_DIR = $(addprefix $(BUILD_DIR)/, obj)
LIB_DIR = $(addprefix $(BUILD_DIR)/, lib)
TEST_DIR = $(addprefix $(BUILD_DIR)/, test)
EXAMPLE_DIR = $(addprefix $(BUILD_DIR)/, example)
MAIN = $(addprefix $(BUILD_DIR)/, main.out)
OBJS = $(addprefix $(OBJ_DIR)/, heap.o chk.o page.o mem.o trie.o stack.o mem_dbg.o)
LIBS = $(addprefix $(LIB_DIR)/, libmem.a libmem.so)
TESTS = $(addprefix $(TEST_DIR)/, test.out)
EXAMPLES = $(addprefix $(EXAMPLE_DIR)/, example.out)
SRC_DIR = src
INCLUDE_DIR = include
.PHONY: all, run, clean, compile, test, profile, res
all: $(LIBS) $(MAIN) $(EXAMPLES) $(TESTS)
run: $(MAIN)
@echo "Running the DEMO of the project"
./$< > data.txt
res:
@echo "Printing the already calculated results"
python3 $(SRC_DIR)/script.py
$(MAIN): main.c $(LIBS) | $(BUILD_DIR)
$(C) $(C_GP_FLAGS) $(C_FLAGS) $^ -o $@ $(C_LIBS_FLAGS)
test: $(TESTS)
$(foreach test, $(TESTS), ./$(test))
profile: $(MAIN) | run
$(GP) $< gmon.out
rm gmon.out
$(TEST_DIR)/%.out: $(SRC_DIR)/%.c $(LIBS) | $(TEST_DIR)
$(C) $(C_FLAGS) $< -L./$(LIB_DIR) -lmem -Wl,-rpath,./build/lib -o $@ -lunittest
$(TEST_DIR): $(BUILD_DIR)
mkdir -p $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(C) $(C_FLAGS) -c $< -o $@ $(C_LIBS_FLAGS)
$(LIB_DIR)/%.a: $(OBJS) | $(LIB_DIR)
$(AR) $@ $^
ranlib $@
$(LIB_DIR)/%.so: $(OBJS) | $(LIB_DIR)
$(C) -shared -o $@ $(C_FLAGS_WHOLE_ARCHIVE) $^ $(C_LIBS_FLAGS) $(C_FLAGS_NO_WHOLE_ARCHIVE)
$(EXAMPLE_DIR)/%.out: $(SRC_DIR)/%.c $(LIBS) | $(EXAMPLE_DIR)
$(C) $(C_FLAGS) -o $@ $< -L./$(LIB_DIR) -lmem -Wl,-rpath,./build/lib
$(EXAMPLE_DIR): $(BUILD_DIR)
mkdir -p $@
$(LIB_DIR): $(BUILD_DIR)
mkdir -p $@
$(OBJ_DIR): $(BUILD_DIR)
mkdir -p $@
$(BUILD_DIR):
mkdir -p $@
compile: C_FLAGS = $(C_COMPILE_FLAGS)
compile: clean $(MAIN) $(TESTS)
clean:
rm -v -rf $(BUILD_DIR)