generated from ravi688/TemplateRepository
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
349 lines (282 loc) · 11.2 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#-------------------------------------------
# Requirements
#-------------------------------------------
# 1. mcpp: http://mcpp.sourceforge.net/
# 2. dot or graphviz: https://graphviz.org/
# 3. uncrustify: https://github.com/uncrustify/uncrustify
# 4. ar
# 5. gcc
#-------------------------------------------
#-------------------------------------------
# Project Configuration
#-------------------------------------------
PROJECT_NAME = PlayVk
STATIC_LIB_NAME = playvk.a
DYNAMIC_LIB_NAME = playvk.dll
EXECUTABLE_NAME = main
MAIN_SOURCE_LANG = c
MAIN_SOURCES=source/main.c
EXTERNAL_INCLUDES = -I"$(VK_SDK_PATH)/Include/"
EXTERNAL_LIBS =-L./external-dependency-libs -lglfw3 -L"$(VK_SDK_PATH)/Lib/" -lvulkan-1 -lgdi32
BUILD_DEFINES=
DEPENDENCIES = Common Common/dependencies/BufferLib Common/dependencies/BufferLib/dependencies/CallTrace
DEPENDENCY_LIBS = Common/lib/common.a Common/dependencies/BufferLib/lib/bufferlib.a Common/dependencies/BufferLib/dependencies/CallTrace/lib/calltrace.a
DEPENDENCIES_DIR = ./dependencies
SHARED_DEPENDENCIES =
SHARED_DEPENDENCY_LIBS =
SHARED_DEPENDENCIES_DIR = ./shared-dependencies
#-------------------------------------------
#-------------------------------------------
# Project Initialization and Uitilty commands
#-------------------------------------------
__DEPENDENCIES = $(addprefix $(DEPENDENCIES_DIR)/, $(DEPENDENCIES))
__DEPENDENCY_LIBS = $(addprefix $(DEPENDENCIES_DIR)/, $(DEPENDENCY_LIBS))
__SHARED_DEPENDENCIES = $(addprefix $(SHARED_DEPENDENCIES_DIR)/, $(SHARED_DEPENDENCIES))
__SHARED_DEPENDENCY_LIBS = $(addprefix $(SHARED_DEPENDENCIES_DIR)/, $(SHARED_DEPENDENCY_LIBS))
ifdef COMSPEC
__EXECUTABLE_NAME = $(addsuffix .exe, $(basename $(EXECUTABLE_NAME)))
else
__EXECUTABLE_NAME = $(basename $(EXECUTABLE_NAME))
endif
.PHONY: all
.PHONY: init
all: dgraph release
%.gv:
echo digraph $(PROJECT_NAME) { $(PROJECT_NAME); } > $@
@echo [Log] $@ created successfully!
$(DEPENDENCIES_DIR) $(SHARED_DEPENDENCIES_DIR):
mkdir $(subst /,\,$@)
@echo [Log] $@ created successfully!
init: $(PROJECT_NAME).gv $(DEPENDENCIES_DIR) $(SHARED_DEPENDENCIES_DIR)
@echo [Log] $(PROJECT_NAME) init successfully!
#-------------------------------------------
#-------------------------------------------
# Dependency Graph Generation
#-------------------------------------------
DGRAPH_TARGET = ./dependency_graph/$(PROJECT_NAME).png
DGRAPH_TARGET_DIR = dependency_graph
DGRAPH_SCRIPT = $(PROJECT_NAME).gv
DGRAPH_INCLUDES = $(addprefix -I, $(__DEPENDENCIES) $(__SHARED_DEPENDENCIES))
DGRAPH_COMPILER = dot
DGRAPH_FLAGS = -Tpng
DGRAPH_PREPROCESSOR = mcpp
DGRAPH_PREPROCESSOR_FLAGS = -P
DGRAPH_PREPROCESSED_SCRIPT = $(addsuffix .i, $(DGRAPH_SCRIPT))
.PHONY: dgraph
.PHONY: dgraph-clean
%.gv.i:
$(DGRAPH_PREPROCESSOR) $(DGRAPH_PREPROCESSOR_FLAGS) $(DGRAPH_INCLUDES) $(basename $@) -o $@
$(DGRAPH_TARGET_DIR):
mkdir $@
dgraph: $(DGRAPH_PREPROCESSED_SCRIPT) | $(DGRAPH_TARGET_DIR)
$(DGRAPH_COMPILER) $(DGRAPH_FLAGS) $(DGRAPH_PREPROCESSED_SCRIPT) > $(DGRAPH_TARGET)
dgraph-clean:
del dependency_graph\$(PROJECT_NAME).png
rmdir dependency_graph
del $(PROJECT_NAME).gv.i
@echo [Log] Dependency graphs cleaned successfully!
#-------------------------------------------
#-------------------------------------------
#
#-------------------------------------------
#-------------------------------------------
# Binary Generation
#-------------------------------------------
TARGET_LIB_DIR = ./lib
TARGET_STATIC_LIB = $(join $(TARGET_LIB_DIR)/, $(STATIC_LIB_NAME))
TARGET_DYNAMIC_LIB = $(join $(TARGET_LIB_DIR)/, $(DYNAMIC_LIB_NAME))
TARGET = $(__EXECUTABLE_NAME)
#Dependencies
DEPENDENCY_INCLUDES = $(addsuffix /include, $(__DEPENDENCIES))
SHARED_DEPENDENCY_INCLUDES = $(addsuffix /include, $(__SHARED_DEPENDENCIES))
MAIN_OBJECT=$(addsuffix .o, $(wildcard $(MAIN_SOURCES)))
INCLUDES= -I./include $(EXTERNAL_INCLUDES) $(addprefix -I, $(DEPENDENCY_INCLUDES) $(SHARED_DEPENDENCY_INCLUDES))
C_SOURCES=$(wildcard source/*.c source/*/*.c)
CPP_SOURCES=$(wildcard source/*.cpp source/*/*.cpp)
SOURCES= $(C_SOURCES) $(CPP_SOURCES)
OBJECTS= $(addsuffix .o, $(SOURCES))
LIBS = $(EXTERNAL_LIBS)
#Flags and Defines
DEBUG_DEFINES = -DGLOBAL_DEBUG -DDEBUG -DLOG_DEBUG
RELEASE_DEFINES = -DGLOBAL_RELEASE -DRELEASE -DLOG_RELEASE
DEFINES = $(BUILD_DEFINES)
COMPILER_FLAGS= -m64
C_COMPILER_FLAGS = $(COMPILER_FLAGS)
CPP_COMPILER_FLAGS = $(COMPILER_FLAGS)
LINKER_FLAGS= -m64
LINKER=g++
DYNAMIC_LIBRARY_COMPILATION_FLAG = -shared
DYNAMIC_IMPORT_LIBRARY_FLAG = -Wl,--out-implib,
C_COMPILER = gcc
CPP_COMPILER = g++
ARCHIVER_FLAGS = -rc
ARCHIVER = ar
ifeq ($(STACK_PROTECT),1)
COMPILER_FLAGS += -fstack-protector
LINKER_FLAGS += -fstack-protector
endif
ifeq ($(ADDRESS_SANITIZE),1)
COMPILER_FLAGS += -fsanitize=address -static-libasan
LINKER_FLAGS += -fsanitize=address -static-libasan
endif
ifeq ($(SHADOW_CALL_STACK_SANITIZE),1)
COMPILER_FLAGS += -fsanitize=shadow-call-stack
LINKER_FLAGS += -fsanitize=shadow-call-stack
endif
ifeq ($(LEAK_SANITIZE),1)
# no need to add it to COMPILER_FLAGS, as this flag only causes a library linking which overrides the malloc
LINKER_FLAGS += -fsanitize=leak
endif
ifeq ($(PROF),1)
COMPILER_FLAGS += -p
LINKER_FLAGS += -p
endif
ifeq ($(GPROF),1)
COMPILER_FLAGS += -pg
LINKER_FLAGS += -pg
endif
ifeq ($(NOOPT),1)
COMPILER_FLAGS += -O0
LINKER_FLAGS += -O0
endif
DEBUG_COMPILER_FLAGS= -g #-fsanitize=integer-divide-by-zero // why it is not working on windows 64 bit?
RELEASE_COMPILER_FLAGS= -O3
DEBUG_LINKER_FLAGS= -g #-fsanitize=integer-divide-by-zero // why it is not working on windows 64 bit?
RELEASE_LINKER_FLAGS= -flto
TARGET_DYNAMIC_IMPORT_LIB = $(addprefix $(dir $(TARGET_DYNAMIC_LIB)), $(addprefix lib, $(notdir $(TARGET_DYNAMIC_LIB).a)))
.PHONY: lib-static
.PHONY: lib-static-debug
.PHONY: lib-static-release
.PHONY: lib-dynamic
.PHONY: lib-dynamic-debug
.PHONY: lib-dynamic-release
.PHONY: lib-static-dynamic
.PHONY: lib-static-dynamic-debug
.PHONY: lib-static-dynamic-release
.PHONY: release
.PHONY: debug
.PHONY: $(TARGET)
.PHONY: bin-clean
.PHONY: PRINT_MESSAGE1
all: release
lib-static: lib-static-release
lib-static-debug: DEFINES += $(DEBUG_DEFINES) -DBUILD_STATIC_LIBRARY
lib-static-debug: __STATIC_LIB_COMMAND = lib-static-debug
lib-static-debug: COMPILER_FLAGS += $(DEBUG_COMPILER_FLAGS)
lib-static-debug: LINKER_FLAGS += $(DEBUG_LINKER_FLAGS)
lib-static-debug: $(TARGET_STATIC_LIB)
lib-static-release: DEFINES += $(RELEASE_DEFINES) -DBUILD_STATIC_LIBRARY
lib-static-release: __STATIC_LIB_COMMAND = lib-static-release
lib-static-release: COMPILER_FLAGS += $(RELEASE_COMPILER_FLAGS)
lib-static-release: LINKER_FLAGS += $(RELEASE_LINKER_FLAGS)
lib-static-release: $(TARGET_STATIC_LIB)
lib-dynamic: lib-dynamic-release
lib-dynamic-debug: DEFINES += $(DEBUG_DEFINES) -DBUILD_DYNAMIC_LIBRARY
lib-dynamic-debug: __STATIC_LIB_COMMAND = lib-static-dynamic-debug
lib-dynamic-debug: COMPILER_FLAGS += $(DEBUG_COMPILER_FLAGS) -fPIC
lib-dynamic-debug: LINKER_FLAGS += $(DEBUG_LINKER_FLAGS) -fPIC
lib-dynamic-debug: $(TARGET_DYNAMIC_LIB)
lib-dynamic-release: DEFINES += $(RELEASE_DEFINES) -DBUILD_DYNAMIC_LIBRARY
lib-dynamic-release: __STATIC_LIB_COMMAND = lib-static-dynamic-release
lib-dynamic-release: COMPILER_FLAGS += $(RELEASE_COMPILER_FLAGS) -fPIC
lib-dynamic-release: LINKER_FLAGS += $(RELEASE_LINKER_FLAGS) -fPIC
lib-dynamic-release: COMPILER_FLAGS += -fPIC
lib-dynamic-release: LINKER_FLAGS += -fPIC
lib-dynamic-release: $(TARGET_DYNAMIC_LIB)
.PHONY: lib-dynamic-packed-debug
lib-dynamic-packed-debug: DEFINES += $(DEBUG_DEFINES) -DBUILD_DYNAMIC_LIBRARY
lib-dynamic-packed-debug: __STATIC_LIB_COMMAND = lib-static-dynamic-debug
lib-dynamic-packed-debug: COMPILER_FLAGS += $(DEBUG_COMPILER_FLAGS) -fPIC
lib-dynamic-packed-debug: LINKER_FLAGS += $(DEBUG_LINKER_FLAGS) -fPIC
lib-dynamic-packed-debug: $(TARGET_DYNAMIC_PACKED_LIB)
release: DEFINES += $(RELEASE_DEFINES) -DBUILD_EXECUTABLE
release: __STATIC_LIB_COMMAND = lib-static-release
release: $(TARGET)
debug: DEFINES += $(DEBUG_DEFINES) -DBUILD_EXECUTABLE
debug: __STATIC_LIB_COMMAND = lib-static-debug
debug: COMPILER_FLAGS += $(DEBUG_COMPILER_FLAGS)
debug: LINKER_FLAGS += $(DEBUG_LINKER_FLAGS)
debug: $(TARGET)
%.c.o : %.c
@echo [Log] Compiling $< to $@
$(C_COMPILER) $(C_COMPILER_FLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@
%.cpp.o: %.cpp
@echo [Log] Compiling $< to $@
$(CPP_COMPILER) $(CPP_COMPILER_FLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@
%.a:
@echo [Log] Building $@ ...
$(MAKE) --directory=$(subst lib/, ,$(dir $@)) $(__STATIC_LIB_COMMAND)
@echo [Log] $@ built successfully!
$(TARGET_LIB_DIR):
mkdir $@
PRINT_STATIC_INFO:
@echo [Log] Building $(TARGET_STATIC_LIB) ...
PRINT_DYNAMIC_INFO:
@echo [Log] Building $(TARGET_DYNAMIC_LIB) ...
$(TARGET_STATIC_LIB) : PRINT_STATIC_INFO $(filter-out $(MAIN_OBJECT), $(OBJECTS)) | $(TARGET_LIB_DIR)
$(ARCHIVER) $(ARCHIVER_FLAGS) $@ $(filter-out $<, $^)
@echo [Log] $@ built successfully!
$(TARGET_DYNAMIC_LIB) : PRINT_DYNAMIC_INFO $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS) $(filter-out $(MAIN_OBJECT), $(OBJECTS)) | $(TARGET_LIB_DIR)
@echo [Log] Linking $@ ...
$(LINKER) $(LINKER_FLAGS) $(DYNAMIC_LIBRARY_COMPILATION_FLAG) $(filter-out $(MAIN_OBJECT), $(OBJECTS)) $(LIBS)\
$(addprefix -L, $(dir $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS))) \
$(addprefix -l:, $(notdir $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS))) \
-o $@ $(DYNAMIC_IMPORT_LIBRARY_FLAG)$(TARGET_DYNAMIC_IMPORT_LIB)
@echo [Log] $@ and lib$(notdir [email protected]) built successfully!
$(TARGET): $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS) $(TARGET_STATIC_LIB) $(MAIN_OBJECT)
@echo [Log] Linking $@ ...
$(LINKER) $(LINKER_FLAGS) $(MAIN_OBJECT) \
$(addprefix -L, $(dir $(TARGET_STATIC_LIB) $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS))) \
$(addprefix -l:, $(notdir $(TARGET_STATIC_LIB) $(__DEPENDENCY_LIBS) $(__SHARED_DEPENDENCY_LIBS))) $(LIBS) \
-o $@
@echo [Log] $(PROJECT_NAME) built successfully!
RM := rm -f
RM_DIR := rm -rf
bin-clean:
$(RM) $(OBJECTS)
$(RM) $(MAIN_OBJECT)
$(RM) $(__EXECUTABLE_NAME)
$(RM) $(TARGET_STATIC_LIB)
$(RM) $(TARGET_DYNAMIC_LIB)
$(RM) $(TARGET_DYNAMIC_IMPORT_LIB)
$(RM_DIR) $(TARGET_LIB_DIR)
@echo [Log] Binaries cleaned successfully!
$(MAKE) --directory=./dependencies/Common clean
# $(MAKE) --directory=./shared-dependencies/CallTrace clean
# $(MAKE) --directory=./dependencies/HPML clean
# $(MAKE) --directory=../../shared-dependencies/HPML clean
# $(MAKE) --directory=./dependencies/tgc clean
#-------------------------------------------
#-------------------------------------------
# Cleaning
#-------------------------------------------
.PHONY: clean-project-internal
clean-project-internal:
$(MAKE) -f $(addsuffix .makefile, $(PROJECT_NAME)) clean
.PHONY: clean
clean: bin-clean clean-project-internal
@echo [Log] All cleaned successfully!
#-------------------------------------------
.PHONY: build
.PHONY: build-run
.PHONY: build-release
.PHONY: build-debug
.PHONY: run
.PHONY: build-project-internal-debug
.PHONY: build-project-internal-release
build-project-internal-debug:
$(MAKE) -f $(addsuffix .makefile, $(PROJECT_NAME)) debug
build-project-internal-release:
$(MAKE) -f $(addsuffix .makefile, $(PROJECT_NAME)) release
build-release:
$(MAKE) build-project-internal-release
$(MAKE) lib-static-release
$(MAKE) release
build-debug:
$(MAKE) build-project-internal-debug
$(MAKE) lib-static-debug
$(MAKE) debug
build: build-debug
build-run: build
$(__EXECUTABLE_NAME)
run: build-run