-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (45 loc) · 1.46 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
# Folders
SRC_DIR = src
TEST_DIR := tests
OBJ_DIR := build
# Compiler
CCC = g++
# Compiling flags
CCFLAGS += -Wno-deprecated-declarations -Wall -Wextra -pedantic -Weffc++ -Wold-style-cast -Woverloaded-virtual -fmax-errors=3 -g
CCFLAGS += -std=c++17 -MMD -Icommon
# Linking flags
#LDFLAGS += -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
# File which contains the main function
MAINFILE := main.cpp
# Name of output
OUTNAME := main.out
MAINOBJ := main.o
SOURCE := $(shell find $(SRC_DIR) -name '*.cpp' ! -name $(MAINFILE))
OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SOURCE))
ALL_OBJS := $(OBJS) $(TEST_OBJS) $(OBJ_DIR)/$(MAINOBJ)
DEPS := $(patsubst %.o, %.d, $(ALL_OBJS))
# Main objetice - created with 'make' or 'make main'.
main: base $(OBJ_DIR)/$(MAINOBJ)
@ echo Linking main file
@ $(CCC) $(CCFLAGS) -o $(OUTNAME) $(OBJS) $(OBJ_DIR)/$(MAINOBJ) $(LDFLAGS)
@ echo ""
# Compile everything except mainfile
base: $(OBJ_DIR) $(OBJS) Makefile
# Main program objects
$(OBJS) $(OBJ_DIR)/$(MAINOBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@ echo Compiling $<
@ $(CCC) $(CCFLAGS) -c $< -o $@
$(OBJ_DIR):
@ mkdir -p $(OBJ_DIR)
# Run output file (and compile it if needed)
run: main
@ ./$(OUTNAME)
run-leaktest: main
@ valgrind --leak-check=full ./$(OUTNAME)
# 'make clean' removes object files and memory dumps.
clean:
@ \rm -rf $(OBJ_DIR) *.gch core
# 'make zap' also removes the executable and backup files.
zap: clean
@ \rm -rf $(OUTNAME) test *~
-include $(DEPS)