-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (118 loc) · 3.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
##############################################
# SRC #
##############################################
# All directories to build (inside src/)
DIR := tests
# Directories with src/ prefix
SRC_DIR := $(addprefix src/,$(DIR))
# All .cpp files
SRC := $(foreach d,$(SRC_DIR),$(wildcard $(d)/*.cpp))
##############################################
# MAIN #
##############################################
# Main directories
MAIN_DIR := src/
# Main file
# Pick one : main_ecs.cpp main_test.cpp
MAIN := main_ecs.cpp
# Main path
MAIN_PATH := $(MAIN_DIR)/$(MAIN)
# Main .o
MAIN_OBJ := $(patsubst %.cpp,build/main/%.o,$(MAIN))
##############################################
# BUILD/.o #
##############################################
# Name of the executable
DEST := build/main_app
# Arguments
ARGS :=
MORE_ARGS :=
# Build Directories
BUILD_DIR := build build/main build/src $(addprefix build/src/,$(SRC_DIR)) $(addprefix build/deps/,$(SRC_DIR))
# .o files
OBJ := $(patsubst %.cpp,build/src/%.o,$(SRC))
# Include folders
INCLUDE_FOLDER := include/
##############################################
# DEPS #
##############################################
# All .d files corresponding to each .cpp
DEPS := $(patsubst %.cpp,build/deps/%.d,$(SRC))
# Deps folder
DEPS_FOLDER := build/deps
# Flags
DEPS_FLAGS := -MMD -MP
##############################################
# FLAGS #
##############################################
# C++ optimsation level
OPTIM := -O2
# C++ flags
FLAGS := -std=c++1z -g3 -Wall -Wextra -Wno-pmf-conversions -fno-strict-aliasing
# C++ librairie
LIBS :=
# Header include folder
INCLUDE := -I ./include -I ./lib/meta-programming/include
# Makefile flags
MAKEFLAGS += --no-print-directory
all: $(DEST)
# Main build task
# Compile each file and link them
$(DEST): $(BUILD_DIR) $(OBJ) $(MAIN_OBJ)
@echo "\033[32m\033[1m:: Linking of all objects\033[0m"
@g++ $(INCLUDE) $(FLAGS) $(OBJ) $(MAIN_OBJ) -o $(DEST) $(LIBS)
@echo -n "\033[34m"
@echo "---------------"
@echo "Build finished!"
@echo "---------------"
@echo -n "\033[0m"
# Compile a file into a object
build/src/%.o: %.cpp
@echo "\033[1m:: Building" "$<" "\033[0m"
@g++ -c $(INCLUDE) $(OPTIM) $(FLAGS) $(DEPS_FLAGS) -o "$@" "$<"
# Compile a file into a object
$(MAIN_OBJ): $(MAIN_PATH)
@echo "\033[1m:: Building Main" "\033[0m"
@g++ -c $(INCLUDE) $(OPTIM) $(FLAGS) -o "$@" "$<"
# Make build folders
$(BUILD_DIR):
@mkdir -p $@
# Clean every build files by destroying the build/ folder.
clean:
@echo "Removing build folder..."
@rm -rf build
@echo -n "\033[34m"
@echo "----------------"
@echo "Project Cleaned"
@echo "----------------"
@echo -n "\033[0m"
# Run the program
run: $(DEST)
@echo -n "\033[34m"
@echo "----------------"
@echo " Run "
@echo "----------------"
@echo -n "\033[0m"
@$(DEST) $(ARGS) $(MORE_ARGS)
@echo -n "\033[34m"
@echo "----------------"
@echo " Stop "
@echo "----------------"
@echo -n "\033[0m"
# Equivalent of make clean and make run
again:
@make clean
@make run
valgrind: $(DEST)
@echo -n "\033[34m"
@echo "----------------"
@echo " Run Valgrind "
@echo "----------------"
@echo -n "\033[0m"
@valgrind --leak-check=full --show-leak-kinds=all $(DEST) $(ARGS) $(MORE_ARGS)
@echo -n "\033[34m"
@echo "----------------"
@echo " Stop "
@echo "----------------"
@echo -n "\033[0m"
-include $(DEPS)