-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (77 loc) · 2.13 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
#Compiler and basic compilation flags (like warnings)
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17
#Folder where binary file will reside.
#Leave blank for current (root) folder
BIN_DIR = bin
_BIN = fractal.out
#Folder where source files reside. Must exist.
#Leave blank for current (root) folder
SRC_DIR =
_SRC = main.cc Bitmap.cc Mandelbrot.cc Zoom.cc FractalCreator.cc
#Folder where object files will reside.
#Will be created if it doesn't exist.
#Leave blank for current (root) folder
OBJ_DIR = obj
#Folder where include files reside. Must preprend every folder with -I.
INCLUDES = -Iinclude -I. -I${SRC_DIR}
#Shared libraries to be included in compilation, must preprend with -l.
LIBS =
#Folder where to find shared libraries, must prepend with -L.
LDFLAGS =
#Debugging option. Leave 1 to create debugging symbols.
#Leave as 0 to compile with optimization. Defaults to 0.
DEBUG ?= 0
##########################################
# DEFAULT VARIABLES: most of the time
# you won't need to modify them.
##########################################
ifneq (${BIN_DIR},)
BIN = $(patsubst %, $(BIN_DIR)/%, $(_BIN))
else
BIN = ${_BIN}
BIN_DIR = .
endif
ifneq (${SRC_DIR},)
SRC = $(patsubst %, $(SRC_DIR)/%, $(_SRC))
else
SRC = ${_SRC}
SRC_DIR = .
endif
_OBJ = $(_SRC:.cc=.o)
ifneq (${OBJ_DIR},)
OBJ = $(patsubst %, $(OBJ_DIR)/%, $(_OBJ))
else
OBJ = ${_OBJ}
OBJ_DIR = .
endif
DEPFILE = .deps
ifeq ($(DEBUG),1)
CXXFLAGS += -g
else
CXXFLAGS += -O2
endif
##########################################
# RULES SECTION
#########################################
#Default rule: compiles the binary file
$(BIN): $(OBJ_DIR) $(BIN_DIR) $(OBJ)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
#Constructs object files automatically
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCLUDES)
#Executes binary file with no arguments
run: $(BIN)
$(BIN)
$(OBJ_DIR):
-mkdir -p $(OBJ_DIR)
$(BIN_DIR):
-mkdir -p $(BIN_DIR)
.PHONY: clean depend
clean:
-rm -rf $(OBJ) *~ $(BIN)
#puts dependency rules in external file
depend: $(SRC)
touch $(DEPFILE)
makedepend -p obj/ -Y -f $(DEPFILE) -- $(INCLUDES) -- $(SRC) > /dev/null 2> /dev/null
sinclude $(DEPFILE)