-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
141 lines (114 loc) · 2.85 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
133
134
135
136
137
138
139
140
141
#
# General
#
EXEC = demo
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra -Werror -fmax-errors=3 $(INCLUDES) $(LINKDIRS)
CC = $(CXX)
CFLAGS = $(CXXFLAGS)
INCLUDES = -Iinclude
LINKDIRS =
LDFLAGS =
LIBS =
LINKAGE = $(LIBS) $(LDFLAGS)
SRC_FILES = $(EXEC).cpp $(wildcard src/*.cpp)
OBJ = $(SRC_FILES:%.cpp=%.o)
DEP = $(OBJ:%.o=%.d)
#
# Debug build settings
#
DBGDIR = debug
DBGEXEC = $(DBGDIR)/$(EXEC)
DBGOBJ = $(addprefix $(DBGDIR)/, $(OBJ))
DBGDEP = $(addprefix $(DBGDIR)/, $(DEP))
DBGCFLAGS = -g -O0 -DDEBUG -DCANDLE_DEBUG
#
# Release build settings
#
RELDIR = release
RELEXEC = $(RELDIR)/$(EXEC)
RELOBJ = $(addprefix $(RELDIR)/, $(OBJ))
RELDEP = $(addprefix $(RELDIR)/, $(DEP))
RELCFLAGS = -O3 -DNDEBUG
#
# Libraries
#
# SFML
LIBS += -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-system
#
# Custom output functions
#
define print_info
@echo "\033[1;38;2;250;250;50m$(1)\033[0m"
endef
define print_success
@echo "\033[1;38;2;50;250;50m$(1)\033[0m"
endef
#
# Rules
#
.PHONY: all debug release remake clean clean-release clean-debug docs
# Default build
all: release
$(shell mkdir -p debug/src release/src )
# Include dependency rules
-include $(DBGDEP)
-include $(RELDEP)
#
# Debug rules
#
debug: $(DBGEXEC)
$(DBGEXEC): $(DBGOBJ)
$(call print_info,Building static library)
ar -rc $(DBGDIR)/libCandle-s-d.a $(DBGDIR)/src/*.o
ranlib $(DBGDIR)/libCandle-s-d.a
$(call print_success,$(DBGDIR)/libCandle-s.a built)
$(call print_info,Building $@)
@$(CXX) $(CXXFLAGS) $(DBGCFLAGS) $^ -o $(DBGEXEC) $(LINKAGE)
$(call print_success,$< ready)
$(DBGDIR)/%.d: %.cpp
$(call print_info,Checking debug dependencies for $<)
$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
@echo -e '\t$$(call print_info,Building $$@)' >> $@
@echo -e '\t$$(CXX) -c $$(CXXFLAGS) $$(DBGCFLAGS) -o $$@ $$<' >> $@
# $(DBGDIR)/%.o: %.cpp
# $(call print_info,Building $@)
# $(CXX) -c $(CXXFLAGS) $(DBGCFLAGS) -o $@ $<
#
# Release rules
#
release: $(RELEXEC)
$(RELEXEC): $(RELOBJ)
$(call print_info,Building static library)
ar -rc $(RELDIR)/libCandle-s.a $(RELDIR)/src/*.o
ranlib $(RELDIR)/libCandle-s.a
$(call print_success,$(RELDIR)/libCandle-s.a built)
$(call print_info,Building $@)
$(CXX) $(CXXFLAGS) $(RELCFLAGS) $^ -o $(RELEXEC) $(LINKAGE)
$(call print_success,$< ready)
$(RELDIR)/%.d: %.cpp
$(call print_info,Checking release dependencies for $<)
$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
@echo -e '\t$$(call print_info,Building $$@)' >> $@
@echo -e '\t$$(CXX) -c $$(CXXFLAGS) $$(RELCFLAGS) -o $$@ $$<' >> $@
lib: $(RELOBJ)
# $(RELDIR)/%.o: %.cpp
# $(call print_info,Building $@)
# $(CXX) -c $(CXXFLAGS) $(RELCFLAGS) -o $@ $<
#
# Other rules
#
remake: clean all
clean: clean-release clean-debug
clean-release:
@rm -f -r $(RELDIR)
@mkdir -p $(RELDIR)/src
clean-debug:
@rm -f -r $(DBGDIR)
@mkdir -p $(DBGDIR)/src
#
# Documentation rules
#
DOXYFILE = doc/Doxyfile
docs:
@doxygen $(DOXYFILE)