-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
207 lines (163 loc) · 7.88 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright (c) 2015, Tamas Csala
BINARY = a.out
SRC_DIR = src
OBJ_DIR = .obj
PRECOMPILED_HEADER_SRC = $(SRC_DIR)/cpp/engine/oglwrap_all.h
TP_DIR = $(SRC_DIR)/thirdparty
FREETYPE_GL_DIR = $(TP_DIR)/freetype-gl
FREETYPE_GL_INCL = $(FREETYPE_GL_DIR)
FREETYPE_GL_LIB = $(FREETYPE_GL_DIR)
FREETYPE_GL_ARCHIVE = $(FREETYPE_GL_DIR)/libfreetype-gl.a
GLFW_DIR = $(TP_DIR)/glfw
GLFW_INCL = $(GLFW_DIR)/include
GLFW_LIB = $(GLFW_DIR)/src
GLFW_ARCHIVE = $(GLFW_LIB)/libglfw3.a
GLM_DIR = $(TP_DIR)/glm
GLM_INCL = $(GLM_DIR)
OGLWRAP_DIR = $(TP_DIR)/oglwrap
OGLWRAP_INCL = $(OGLWRAP_DIR)
OGLWRAP_LIB = $(OGLWRAP_DIR)/oglwrap
OGLWRAP_ARCHIVE = $(OGLWRAP_LIB)/liboglwrap.a
OGLWRAP_ARCHIVE_SRC = $(OGLWRAP_LIB)/oglwrap.cc
GLEW_DIR = $(TP_DIR)/glew
GLEW_INCL = $(GLEW_DIR)
GLEW_LIB = $(GLEW_DIR)/GL
GLEW_ARCHIVE = $(GLEW_LIB)/libglew.a
GLEW_ARCHIVE_SRC = $(GLEW_LIB)/glew.c
GLEW_DEPS = $(shell find $(GLEW_INCL) -type f -name *.h -or -name *.c)
TP_CXXFLAGS = -isystem $(FREETYPE_GL_INCL) -isystem $(GLFW_INCL) \
-isystem $(GLM_INCL) -I $(OGLWRAP_INCL) -isystem $(GLEW_INCL)
TP_LDFLAGS = -L$(FREETYPE_GL_LIB) -lfreetype-gl -L$(GLFW_LIB) -lglfw3 \
-L$(GLEW_LIB) -lglew -lGL -L$(OGLWRAP_LIB) -loglwrap
DEPENDENCIES_DIR = .deps
MAGICKPP_FOUND = $(DEPENDENCIES_DIR)/magickpp.found
FREETYPE2_FOUND = $(DEPENDENCIES_DIR)/freetype2.found
THIRD_PARTY_LIBS_FOUND = $(MAGICKPP_FOUND) $(FREETYPE2_FOUND)
PKG_CONFIG_LIB_NAMES = Magick++ freetype2
PKG_CONFIG_CXXFLAGS_ := $(shell pkg-config --cflags $(PKG_CONFIG_LIB_NAMES))
PKG_CONFIG_CXXFLAGS := $(filter-out -fopenmp,$(PKG_CONFIG_CXXFLAGS_))
PKG_CONFIG_LDFLAGS := $(shell pkg-config --libs $(PKG_CONFIG_LIB_NAMES))
CPP_FILES := $(shell find -L $(SRC_DIR)/cpp -name '*.cc')
OBJECTS := $(subst $(SRC_DIR),$(OBJ_DIR),$(CPP_FILES:.cc=.o))
DEPS := $(OBJECTS:.o=.d)
#CC = clang
#CXX = clang++
CXX_PRECOMPILED_HEADER_EXTENSION = pch
PRECOMPILED_HEADER = $(PRECOMPILED_HEADER_SRC).$(CXX_PRECOMPILED_HEADER_EXTENSION)
PRECOMPILED_HEADER_DEP = $(subst $(SRC_DIR),$(OBJ_DIR),$(PRECOMPILED_HEADER).d)
BASE_CXXFLAGS = -std=c++11 -Wall $(TP_CXXFLAGS) $(PKG_CONFIG_CXXFLAGS)
ifeq ($(MAKECMDGOALS),release)
CXXFLAGS = -O3 -DOGLWRAP_DEBUG=0 $(BASE_CXXFLAGS)
else
CXXFLAGS = -g $(BASE_CXXFLAGS)
endif
CXXFLAG_PRECOMPILED_HEADER = -include $(PRECOMPILED_HEADER_SRC)
GLFW_X11_LDFALGS = -lXxf86vm -lX11 -lXrandr -lXi -lXcursor -lXinerama -lpthread
BASE_LDFLAGS = -lm $(TP_LDFLAGS) $(PKG_CONFIG_LDFLAGS) $(GLFW_X11_LDFALGS)
ifeq ($(MAKECMDGOALS),release)
LDFLAGS = $(BASE_LDFLAGS)
else
LDFLAGS = -rdynamic $(BASE_LDFLAGS)
endif
# Terminal font colors
NORMAL = \e[0m
GREEN = \e[32m
RED = \e[91m
BOLD = \e[1m
YELLOW = \e[93m
CYAN = \e[96m
# The nocolor target is for sublime-text termial, that doesn't support font colors.
ifeq ($(MAKECMDGOALS),nocolor)
printf = /bin/echo "$(1)$(subst $(OBJ_DIR)/,,$(2))"
else
printf = /bin/echo -e "$(1)$(3)$(subst $(OBJ_DIR)/,,$(2))$(NORMAL)"
endif
.PHONY: all debug release nocolor clean clean_deps update
all: $(BINARY)
debug: $(BINARY)
nocolor: $(BINARY)
release: $(BINARY)
clean:
@rm -f $(BINARY) -rf $(OBJ_DIR) -f $(PRECOMPILED_HEADER)
clean_deps:
@find $(OBJ_DIR) -name '*.d*' | xargs rm -f
update:
@git pull && git submodule update
ifneq ($(MAKECMDGOALS),clean) # don't create .d files just to remove them...
ifneq ($(MAKECMDGOALS),clean_deps)
ifneq ($(MAKECMDGOALS),update)
$(shell mkdir -p $(OBJ_DIR)) # make OBJ_DIR for a helper file
$(shell mkdir -p $(DEPENDENCIES_DIR)) # make the dir for third party libs
$(shell echo 0 > $(OBJ_DIR)/objs_current) # reset the built object counter
$(shell touch scripts/progress_counter.make) # force the helper makefile to always run
$(shell $(MAKE) -f scripts/progress_counter.make all) # count the number of objects to be built
$(shell rm -rf $(OBJ_DIR)/deps) # remove the dir used to sign the first .d file
$(shell rm -rf .lockdir) # reset the lock for scripts/get_build_progress.sh
# include the dependency files
-include $(DEPS)
-include $(PRECOMPILED_HEADER_DEP)
endif
endif
endif
# The dependency list files
%.d:
@ # print some text for the user if its the first .d file
@ if mkdir $(OBJ_DIR)/deps 2> /dev/null; then $(call printf,[ 0%] ,Scanning dependencies,$(YELLOW)); fi;
@ # if the file doesn't exist, create its directory,
@ # else create a .d2 file to sign, that we have just created it (see %.o)
@ if [ ! -f $@ ]; then mkdir -p $(dir $@); touch $(@:.d=.d2); fi;
@ # create the dependency list using clang -MM
@ $(CXX) $(CXXFLAGS) -M $(subst $(OBJ_DIR),$(SRC_DIR),$(@:.d=.cc)) -MT $(@:.d=.o) -MF $@
@ # Manually insert the precompiled header as a dependency
@ sed -i 's,.o: ,.o: $(PRECOMPILED_HEADER) \\\n ,' $@
# We need a dep list for the precompiled header too
$(PRECOMPILED_HEADER_DEP):
@ if mkdir $(OBJ_DIR)/deps 2> /dev/null; then $(call printf,[ 0%] ,Scanning dependencies,$(YELLOW)); fi;
@ if [ ! -f $@ ]; then mkdir -p $(dir $@); touch $(@:.d=.d2); fi;
@ $(CXX) $(CXXFLAGS) -x c++-header -M $(subst $(OBJ_DIR),$(SRC_DIR),$(@:.$(CXX_PRECOMPILED_HEADER_EXTENSION).d=)) -MT $(subst $(OBJ_DIR),$(SRC_DIR),$(@:.d=)) -MF $@
%.o:
@ $(call printf,$(shell scripts/get_build_progress.sh) ,Building object $@,$(GREEN))
@ # One of the depencies changed, which probably introduced new dependencies,
@ # that we don't depend on now. So if a new header is included from a header,
@ # normally we wouldn't track that header's changes, and the make would claim
@ # that everything is up to date, even if the newly included header changed.
@ # So we have to recalculate the dependencies for this cc file at next
@ # compilation. The easiest to solve this is to remove the outdated .d file.
@ # Alternatively we could rebuild the .d right now. I choose the second option
@ # as it makes the makefile's output nicer (will only print Checking Dependecies
@ # at the first compilation).
@ #
@ # But note, that we shouldn't create the .d file if we have just built them
@ # for the includes (the .d2 signs this)
@ if [ -f $(@:.o=.d2) ]; then rm $(@:.o=.d2); else $(CXX) $(CXXFLAGS) -MM $(subst $(OBJ_DIR),$(SRC_DIR),$(@:.o=.cc)) -MT $@ -MF $(@:.o=.d); sed -i 's,.o: ,.o: $(PRECOMPILED_HEADER) \\\n ,' $(@:.o=.d); fi;
@ $(CXX) $(CXXFLAGS) $(CXXFLAG_PRECOMPILED_HEADER) -c $(subst $(OBJ_DIR),$(SRC_DIR),$(@:.o=.cc)) -o $@
$(PRECOMPILED_HEADER):
@ $(call printf,$(shell scripts/get_build_progress.sh) ,Building precompiled header $@,$(CYAN))
@ rm -f $(PRECOMPILED_HEADER)-*
@ if [ -f $(subst $(SRC_DIR),$(OBJ_DIR),$@).d2 ]; then rm $(subst $(SRC_DIR),$(OBJ_DIR),$@).d2; else $(CXX) $(CXXFLAGS) -x c++-header -MM $(@:.$(CXX_PRECOMPILED_HEADER_EXTENSION)=) -MT $@ -MF $(subst $(SRC_DIR),$(OBJ_DIR),$@).d; fi;
@ $(CXX) $(CXXFLAGS) -x c++-header $(@:.$(CXX_PRECOMPILED_HEADER_EXTENSION)=) -o $@
$(FREETYPE_GL_ARCHIVE):
@ $(call printf,$(shell scripts/get_build_progress.sh) ,Building archive for freetype-gl,$(GREEN))
@ cd $(FREETYPE_GL_DIR) && cmake . > /dev/null && $(MAKE) all > /dev/null
$(GLFW_ARCHIVE):
@ $(call printf,$(shell scripts/get_build_progress.sh) ,Building archive for glfw3,$(GREEN))
@ cd $(GLFW_DIR) && cmake . > /dev/null && $(MAKE) all > /dev/null
$(GLEW_ARCHIVE): $(GLEW_DEPS)
@ $(CC) -c -isystem $(GLEW_INCL) $(GLEW_ARCHIVE_SRC) -o $@
$(OGLWRAP_ARCHIVE): $(PRECOMPILED_HEADER)
@ $(CXX) -c $(CXXFLAGS) $(CXXFLAG_PRECOMPILED_HEADER) $(OGLWRAP_ARCHIVE_SRC) -o $@
$(BINARY): $(THIRD_PARTY_LIBS_FOUND) $(OBJECTS) $(FREETYPE_GL_ARCHIVE) $(GLEW_ARCHIVE) $(OGLWRAP_ARCHIVE)
@ $(call printf,[100%] ,Linking executable $@,$(BOLD)$(RED))
@ $(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
%.h:
@
%.hpp:
@
%.inl:
@
%:
@
$(MAGICKPP_FOUND):
@if `pkg-config --atleast-version=6.0 Magick++`; then touch $(MAGICKPP_FOUND); else /bin/echo -e "$(RED)Magick++ version 6.0 or newer is required $(NORMAL)"; exit 1; fi;
$(FREETYPE2_FOUND):
@if `pkg-config --atleast-version=15.0 freetype2`; then touch $(FREETYPE2_FOUND); else /bin/echo -e "$(RED)FreeType2 version 15.0 or newer is required $(NORMAL)"; exit 1; fi;