-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
465 lines (362 loc) · 15 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# Copyright (c) 2021 sashamakarenko
# https://github.com/sashamakarenko/makefile/blob/main/LICENSE
MAKEFILE_UUID=2620b733ccdf47f1bd1b569d96f0d92d
define checkvar
ifeq ($$($1),)
$$(error $(1) must be defined)
endif
ifneq ($$($1),$$(word 1,$$($1)))
$$(error $(1) may not contain white spaces)
endif
endef
$(foreach var,PRJ_NAME PRJ_BRANCH PRJ_VERSION PRJ_TYPE,$(eval $(call checkvar,$(var))))
ifeq ($(filter $(PRJ_TYPE),inc lib exe),)
$(error PRJ_TYPE must be either inc, lib or exe)
endif
MAKECMD = $(MAKE) -s --no-print-directory BUILD_MODE=$(BUILD_MODE)
SUBMAKE = $(MAKECMD) -j1 IS_SUBMAKE=true MAKEFLAGS= MFLAGS=
REMAKE = +$(V)$(MAKECMD)
PRJ_INFO ?= PrjInfo.h
####################### files #########################
SRCDIR := src
CPPEXT ?= cpp
OBJEXT := o
DEPEXT := mk
TESTEXT:= exe
TESTIND:= done
BUILDDIR := build
BUILD_MODE ?= release
ifeq ($(filter $(BUILD_MODE),release debug),)
$(error BUILD_MODE must be either release or debug)
endif
OBJDIR := $(BUILDDIR)/obj/$(BUILD_MODE)
DEPDIR := $(BUILDDIR)/dep/$(BUILD_MODE)
LIBDIR := $(BUILDDIR)/lib/$(BUILD_MODE)
BINDIR := $(BUILDDIR)/bin/$(BUILD_MODE)
PRJSRCDIR := $(SRCDIR)/$(PRJ_NAME)
CPP_FILES := $(wildcard $(PRJSRCDIR)/*.$(CPPEXT)) $(GENERATED_CPP_FILES)
ifneq ($(SRCSUBDIRS),)
CPP_FILES := $(CPP_FILES) $(foreach dir,$(SRCSUBDIRS),$(wildcard $(PRJSRCDIR)/$(dir)/*.$(CPPEXT)))
endif
CPP_HEADERS := $(foreach e,h hpp hxx hh,$(wildcard $(PRJSRCDIR)/*.$e))
ifneq ($(SRCSUBDIRS),)
CPP_HEADERS := $(CPP_HEADERS) $(foreach dir,$(SRCSUBDIRS),$(foreach e,h hpp hxx hh,$(wildcard $(PRJSRCDIR)/$(dir)/*.$e)))
endif
ifneq ($(PRJ_INFO),)
PRJ_INFO_HEADER = $(shell if ( test ! -f $(PRJSRCDIR)/$(PRJ_INFO) ) || grep -q $(MAKEFILE_UUID) $(PRJSRCDIR)/$(PRJ_INFO); then echo $(PRJSRCDIR)/$(PRJ_INFO); fi)
PREBUILD_TARGETS += $(PRJ_INFO_HEADER)
endif
OBJ_FILES := $(CPP_FILES:$(SRCDIR)/%.$(CPPEXT)=$(OBJDIR)/%.$(OBJEXT))
DEP_FILES := $(CPP_FILES:$(SRCDIR)/%.$(CPPEXT)=$(DEPDIR)/%.$(DEPEXT))
ifneq ($(IS_SUBMAKE),true)
TESTDIR := tests
TEST_CPP_DISABLED := $(foreach n,$(DISABLED_TESTS),$(SRCDIR)/$(TESTDIR)/Test$(n).$(CPPEXT))
TEST_CPP_FILES := $(filter-out $(TEST_CPP_DISABLED),$(wildcard $(SRCDIR)/$(TESTDIR)/Test*.$(CPPEXT)))
TEST_ALLCPP_FILES := $(wildcard $(SRCDIR)/$(TESTDIR)/*.$(CPPEXT))
TEST_OBJ_FILES := $(TEST_CPP_FILES:$(SRCDIR)/%.$(CPPEXT)=$(OBJDIR)/%.$(OBJEXT))
TEST_DEP_FILES := $(TEST_ALLCPP_FILES:$(SRCDIR)/%.$(CPPEXT)=$(DEPDIR)/%.$(DEPEXT))
TEST_TARGETS := $(TEST_CPP_FILES:$(SRCDIR)/%.$(CPPEXT)=$(BINDIR)/%.$(TESTEXT))
TEST_RUNS := $(TEST_TARGETS:$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)=test-%)
TEST_GDBS := $(TEST_TARGETS:$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)=gdb-test-%)
TEST_INDICATORS := $(TEST_TARGETS:%.$(TESTEXT)=%.$(TESTIND))
TEST_NAMES := $(filter-out $(DISABLED_TESTS),$(TEST_TARGETS:$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)=%))
testdeps = $(BINDIR)/$(TESTDIR)/Test$(1).$(TESTEXT): $(OBJDIR)/$(TESTDIR)/Test$(1).$(OBJEXT) $(TEST_EXTRA_OBJS_$(1)) $(TARGET) $(TEST_EXTRA_DEPENDENCY) $(Test$(1)_EXTRA_DEPENDENCY)
$(foreach n,$(TEST_NAMES),$(eval TEST_EXTRA_CPPS_$(n):=$(wildcard $(SRCDIR)/$(TESTDIR)/$(n)*.$(CPPEXT))))
$(foreach n,$(TEST_NAMES),$(eval TEST_EXTRA_OBJS_$(n):=$(patsubst $(SRCDIR)/$(TESTDIR)/%.$(CPPEXT),$(OBJDIR)/$(TESTDIR)/%.$(OBJEXT),$(TEST_EXTRA_CPPS_$(n)))))
endif
####################### target #########################
TARGET :=
ifeq ($(PRJ_TYPE),inc)
TARGET := $(BUILDDIR)
endif
TARGET_IS_DYMANIC := true
ifeq ($(PRJ_TYPE),lib)
ifeq ($(PRJ_BRANCH),)
$(error PRJ_BRANCH must be defined for libraries)
endif
ifeq ($(PRJ_LIB_TYPE),)
PRJ_LIB_TYPE := dynamic
endif
LIB_BASE_NAME := $(PRJ_NAME)-$(PRJ_BRANCH)
LIB_NAME :=
ifeq ($(PRJ_LIB_TYPE),dynamic)
LIB_NAME := lib$(LIB_BASE_NAME).so
TARGET := $(LIBDIR)/$(LIB_NAME)
LINK_OPTIONS += -shared -Wl,--no-undefined -Wl,-soname,$(LIB_NAME)
SRC_GDB_PRINTER := $(wildcard $(SRCDIR)/gdb/printers.py)
ifneq ($(SRC_GDB_PRINTER),)
GDB_PRINTER := $(TARGET)-gdb.py
endif
endif
ifeq ($(PRJ_LIB_TYPE),static)
LIB_NAME := lib$(LIB_BASE_NAME).a
TARGET := $(LIBDIR)/$(LIB_NAME)
TARGET_IS_DYMANIC := false
endif
ifeq ($(LIB_NAME),)
$(error PRJ_LIB_TYPE must be either dynamic or static)
endif
LINK_MY_LIB := -L$(CURDIR)/$(LIBDIR) -l$(LIB_BASE_NAME)
endif
ifeq ($(PRJ_TYPE),exe)
EXE_NAME := $(PRJ_NAME)
TARGET := $(BINDIR)/$(EXE_NAME)
LINK_OPTIONS +=
PRJ_LIB_TYPE :=
SRC_GDB_PRINTER := $(wildcard $(SRCDIR)/gdb/printers.py)
ifneq ($(SRC_GDB_PRINTER),)
GDB_PRINTER := $(TARGET)-gdb.py
endif
endif
####################### deps #########################
DEP_DIRS :=
DEPVARS := $(BUILDDIR)/dependencies-$(BUILD_MODE).mk
ifneq ($(PRJ_DEPENDENCIES),)
-include $(DEPVARS)
ifeq ($(DEP_DIRS),)
DEP_DIRECT_DIRS := $(foreach d,$(PRJ_DEPENDENCIES),$(shell readlink -e $d))
DEP_DEP_DIRS := $(foreach d,$(PRJ_DEPENDENCIES),$(shell $(SUBMAKE) -C $d show-var-DEP_DIRECT_DIRS show-var-DEP_DEP_DIRS 2>/dev/null))
ifneq ($(IS_SUBMAKE),true)
depdirs = DEP_DIRS:=$(filter-out $(1),$(DEP_DIRS)) $(1)
deprevdirs = DEP_REV_DIRS:=$(1) $(filter-out $(1),$(DEP_REV_DIRS))
blank :=
space := $(blank) $(blank)
$(foreach d,$(DEP_DIRECT_DIRS) $(DEP_DEP_DIRS),$(eval $(call depdirs,$(d)) ) )
$(foreach d,$(DEP_DIRS),$(eval $(call deprevdirs,$(d)) ) )
DEP_LINK_OPTIONS:= $(foreach d,$(DEP_DIRS),$(shell $(SUBMAKE) -C $d show-var-LINK_MY_LIB 2>/dev/null))
DEP_INCLUDES := $(foreach d,$(DEP_DIRS),-I$d/src)
DEP_TARGETS := $(foreach d,$(DEP_DIRS),$d/$(shell $(SUBMAKE) -C $d show-var-TARGET 2>/dev/null))
DEP_LD_LIB_PATH := $(foreach d,$(DEP_DIRS),$d/$(LIBDIR):)
DEP_LD_LIB_PATH := $(subst $(space),,$(DEP_LD_LIB_PATH))
endif
endif
BUILD_DEPS := build-deps
endif
####################### c++ #########################
COMPILER := c++
CPP_STD ?= -std=c++17
ifeq ($(BUILD_MODE),release)
CPP_OPTIM := -O3 -DNDEBUG
else
CPP_OPTIM := -O0
endif
ifneq ($(MAKECMDGOALS),$(filter-out lcov,$(MAKECMDGOALS)))
COVERAGE=true
endif
COVERAGE_FLAGS := --coverage -fprofile-arcs
ifeq ($(COVERAGE),true)
CPP_COVERAGE :=$(COVERAGE_FLAGS)
LINK_COVERAGE :=$(COVERAGE_FLAGS)
else
CPP_COVERAGE :=
LINK_COVERAGE :=
endif
CPP_PLT := -fno-plt
CPP_PIC ?= -fPIC
CPP_PSABI ?= -Wno-psabi
CPP_OPTIONS += $(CPP_STD) $(CPP_OPTIM) $(CPP_PIC) $(CPP_PLT) $(CPP_PSABI) $(CPP_COVERAGE) -g -I$(SRCDIR) $(CPP_INCLUDES) $(DEP_INCLUDES) $(CPP_DEFINES) $(CPP_EXTRA_FLAGS)
# V stands for Verbose
# use 'make V=' or 'make VERBOSE=true' to make it verbose
ifneq ($(VERBOSE),true)
V ?= @
endif
####################### rules #########################
all: $(TARGET) | $(PREBUILD_TARGETS)
debug release:
$(REMAKE) BUILD_MODE=$@
ifeq ($(PRJ_TYPE),inc)
$(TARGET): $(PRJ_INFO_HEADER) $(DEP_TARGETS) $(CPP_HEADERS) $(TARGET_EXTRA_DEPENDENCY) $(GDB_PRINTER) #$(BUILD_DEPS)
$(V)mkdir -p $@
$(V)touch $@
$(V)echo " checking $(PRJ_NAME) $(words $(CPP_HEADERS)) headers"
ifneq ($(PRJ_POSTBUILD_TARGET),)
$(REMAKE) $(PRJ_POSTBUILD_TARGET)
endif
else # PRJ_TYPE != inc
$(TARGET): $(PRJ_INFO_HEADER) $(OBJ_FILES) $(DEP_TARGETS) $(TARGET_EXTRA_DEPENDENCY) $(GDB_PRINTER) #$(BUILD_DEPS)
$(V)mkdir -p $(@D)
$(V)echo " linking $@"
ifeq ($(PRJ_LIB_TYPE),static)
$(V)ar csr $@ $(OBJ_FILES)
else
$(V)$(COMPILER) $(CPP_OPTIM) $(LINK_OPTIONS) $(CPP_PLT) $(LINK_COVERAGE) -g -o $@ $(OBJ_FILES) $(DEP_LINK_OPTIONS) $(LINK_EXTRA_LIBS)
endif
ifneq ($(PRJ_POSTBUILD_TARGET),)
$(REMAKE) $(PRJ_POSTBUILD_TARGET)
endif
endif # PRJ_TYPE
ifneq ($(SRC_GDB_PRINTER),)
$(GDB_PRINTER): $(SRC_GDB_PRINTER)
$(V)mkdir -p $(@D)
$(V)echo " making $@"
$(V)cp -f $< $@
$(V)sed -e "s/__PRJ_NAME__/$(PRJ_NAME)/g" -e "s/__PRJ_BRANCH__/$(PRJ_BRANCH)/g" -i $@
endif
$(OBJDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(CPPEXT)
$(V)echo " [$(BUILD_MODE)] compiling $<"
$(V)mkdir -p $(dir $(DEPDIR)/$*)
$(V)$(COMPILER) $(CPP_OPTIONS) -MT $@ -MM -MP -MF $(DEPDIR)/$*.$(DEPEXT) $<
$(V)sed "s%$@:%$@ $(DEPDIR)/$*.$(DEPEXT):%g" -i $(DEPDIR)/$*.$(DEPEXT)
$(V)mkdir -p $(@D)
$(V)$(COMPILER) $(CPP_OPTIONS) -c -o $@ $$PWD/$<
$(DEPDIR)/$(TESTDIR)/Test%.$(DEPEXT): $(OBJDIR)/$(TESTDIR)/Test%.$(OBJEXT)
ifneq ($(PRJ_DEPENDENCIES),)
$(DEPVARS): Makefile
$(V)mkdir -p $(@D)
$(V)echo "DEP_DIRS:=$(DEP_DIRS)" > $@
$(V)echo "DEP_REV_DIRS:=$(DEP_REV_DIRS)" >> $@
$(V)echo "DEP_INCLUDES:=$(DEP_INCLUDES)" >> $@
$(V)echo "DEP_LINK_OPTIONS:=$(DEP_LINK_OPTIONS)" >> $@
$(V)echo "DEP_LD_LIB_PATH:=$(DEP_LD_LIB_PATH)" >> $@
$(V)echo "DEP_TARGETS:=$(DEP_TARGETS)" >> $@
endif
fake-prjinfo-header $(PRJ_INFO_HEADER): Makefile
$(V)echo " [$(BUILD_MODE)] created $@"
$(V)mkdir -p $(@D)
$(V)echo "#pragma once" > $@
$(V)echo "#ifndef DECLARE_$(PRJ_NAME)_PrjInfo_h" >> $@
$(V)echo "#define DECLARE_$(PRJ_NAME)_PrjInfo_h" >> $@
$(V)echo "// remove the line below if you edit this file" >> $@
$(V)echo "// generated by Makefile $(MAKEFILE_UUID)" >> $@
$(V)echo "namespace $(PRJ_NAME) {" >> $@
$(V)echo "constexpr const char * const PRJ_NAME = \"$(PRJ_NAME)\";" >> $@
$(V)echo "constexpr const char * const PRJ_BRANCH = \"$(PRJ_BRANCH)\";" >> $@
$(V)echo "constexpr const char * const PRJ_VERSION = \"$(PRJ_VERSION)\";" >> $@
$(V)echo "}" >> $@
$(V)echo "#endif" >> $@
####################### dependencies #########################
.PHONY: build-deps clean-deps rebuild-all rebuild
ifneq ($(DEP_DIRS),)
ifneq ($(DEP_TARGETS),)
$(DEP_TARGETS): $(BUILD_DEPS)
endif
define builddep =
$(REMAKE) -C $(1) BUILD_DEPS=
endef
build-deps:
# $(V)echo " $@"
+$(foreach d,$(DEP_REV_DIRS),$(call builddep,$d) )
# +$(V)for d in $(DEP_REV_DIRS); do $(MAKECMD) -C $$d BUILD_DEPS= ; done
clean-deps:
+$(V)for d in $(DEP_DIRS); do $(MAKECMD) -C $$d clean; done
clean-all: clean-deps clean
else
build-deps clean-deps:
endif
rebuild:
$(REMAKE) clean
$(REMAKE)
rebuild-all:
$(REMAKE) clean-deps clean
$(REMAKE)
####################### tests #########################
.SECONDARY:
$(OBJDIR)/$(TESTDIR)/Test%.$(OBJEXT): CPP_INCLUDES += $(TEST_INCLUDES) -I$(THIS_MAKEFILE_DIR)
$(OBJDIR)/$(TESTDIR)/Test%.$(OBJEXT): CPP_DEFINES += $(TEST_DEFINES)
$(OBJDIR)/$(TESTDIR)/Test%.$(OBJEXT): CPP_EXTRA_FLAGS += $($(*F)_EXTRA_CPP_FLAGS)
$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT): TEST_CPP_EXTRA_FILES = $(wildcard $(SRCDIR)/$(TESTDIR)/$**.$(CPPEXT))
$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT): TEST_OBJ_EXTRA_FILES = $(TEST_CPP_EXTRA_FILES:$(SRCDIR)/%.$(CPPEXT)=$(OBJDIR)/%.$(OBJEXT))
$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT): TEST_SPECIFIC_LINK = $(Test$(*F)_EXTRA_LINK_FLAGS)
$(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT): $(Test$*_EXTRA_DEPENDENCY)
$(V)mkdir -p $(@D)
$(V)echo " linking $@"
$(V)$(COMPILER) $(CPP_OPTIM) $(CPP_PLT) -g -o $@ $< $(TEST_OBJ_EXTRA_FILES) $(LINK_MY_LIB) $(DEP_LINK_OPTIONS) $(LINK_COVERAGE) $(LINK_EXTRA_LIBS) $(TEST_EXTRA_LINK_LIBS) $(TEST_SPECIFIC_LINK)
$(BINDIR)/$(TESTDIR)/Test%.$(TESTIND): $(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)
$(V)echo; echo; str="########################### testing $* ###########################"; if test -t 1; then printf "\e[36;1m$$str\e[0m\n"; else echo "$$str"; fi
$(V)export LD_LIBRARY_PATH=$(LIBDIR):$(DEP_LD_LIB_PATH)$(TEST_EXTRA_LD_PATH):$(Test$*_EXTRA_LD_PATH):$$LD_LIBRARY_PATH; $(TEST_LAUNCHER) $(Test$*_EXTRA_LAUNCHER) ./$< $(TEST_ARGS_$*)
$(V)echo; echo; echo "########################### end of test $* ###########################"; echo; echo
$(V)touch $@
test-%: $(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)
$(V)export LD_LIBRARY_PATH=$(LIBDIR):$(DEP_LD_LIB_PATH)$(TEST_EXTRA_LD_PATH):$(Test$*_EXTRA_LD_PATH):$$LD_LIBRARY_PATH; $(TEST_LAUNCHER) $(Test$*_EXTRA_LAUNCHER) ./$< $(TEST_ARGS_$*)
gdb-test-%: $(BINDIR)/$(TESTDIR)/Test%.$(TESTEXT)
$(V)export LD_LIBRARY_PATH=$(LIBDIR):$(DEP_LD_LIB_PATH)$(TEST_EXTRA_LD_PATH):$$LD_LIBRARY_PATH; gdb ./$<
ifneq ($(TEST_DEP_FILES),)
$(foreach n,$(TEST_NAMES),$(eval $(call testdeps,$(n))))
build-all-tests: $(TEST_TARGETS)
-include $(TEST_DEP_FILES)
endif
####################### internals #########################
.PHONY: find-makefile-dir # show-var-DEP_DIRECT_DIRS show-var-DEP_DEP_DIRS show-var-LINK_MY_LIB show-var-TARGET
show-var-%:
@echo $($*)
THIS_MAKEFILE_DIR = $(shell readlink -e $(dir $(foreach m,$(MAKEFILE_LIST),$(wildcard $(dir $m)/bash-completion-to-source.sh))))
find-makefile-dir:
@echo $(THIS_MAKEFILE_DIR)
find-makefile-dir-uuid:
$(V)for f in $(MAKEFILE_LIST); do \
if test Makefile = $$(basename $$f) -a "x$(MAKEFILE_UUID)" = "x$$(sed -n '/^MAKEFILE_UUID=/s/.*=\(.*\)/\1/gp' $$f)"; then \
readlink -e $$(dirname $$f); \
break; \
fi;\
done
help:
$(V)cat $(THIS_MAKEFILE_DIR)/README.md | sed 's/^##\(.*\)/\x1b[93;1m##\1\x1b[0m/g' | less -r
####################### generators #########################
generate-vscode:
$(V)$(THIS_MAKEFILE_DIR)/generate-vscode.sh $(CURDIR) $(DEP_DIRS)
new-class: NEW_FILES = $(wildcard $(PRJSRCDIR)/$(CLASS).h $(PRJSRCDIR)/$(CLASS).cpp)
new-class:
$(V)if test x = "x$(CLASS)"; then \
echo "usage: make $@ CLASS=NewClassName"; \
false; \
fi
$(V)if test x != "x$(NEW_FILES)"; then \
echo "file already exist: $(NEW_FILES)"; \
false; \
fi
$(V)set -e; for ext in h cpp; do\
echo " creating $(THIS_MAKEFILE_DIR)/templates/NewClass.$$ext -> $(PRJSRCDIR)/$(CLASS).$$ext";\
cat $(THIS_MAKEFILE_DIR)/templates/NewClass.$$ext | sed -e "s/NAMESPACE/$(PRJ_NAME)/g" -e "s/CLASS/$(CLASS)/g" > $(PRJSRCDIR)/$(CLASS).$$ext;\
done
####################### launching #########################
.PHONY: check go ldd recheck clean-test-indicators clean-tests build-all-tests
ifeq ($(PRJ_TYPE),exe)
go: $(TARGET)
$(V)export LD_LIBRARY_PATH=$(LD_PATH):$(DEP_LD_LIB_PATH):$$LD_LIBRARY_PATH; $(EXE_RUNNER) ./$< $(ARGS)
else
go:
$(V)echo "project is not an executable"
$(V)false
endif
gdb-%:
$(REMAKE) BUILD_MODE=$* gdb
ifeq ($(PRJ_TYPE),exe)
gdb: $(TARGET)
$(V)export LD_LIBRARY_PATH=$(LD_PATH):$(DEP_LD_LIB_PATH):$$LD_LIBRARY_PATH; gdb ./$<
else
gdb:
$(V)echo "project is not an executable"
$(V)false
endif
ifeq ($(TARGET_IS_DYMANIC),true)
ldd: $(TARGET)
$(V)export LD_LIBRARY_PATH=$(LD_PATH):$(DEP_LD_LIB_PATH):$$LD_LIBRARY_PATH; ldd ./$<
else
ldd:
$(V)echo "project is neither executable nor dynamic library"
$(V)false
endif
check: $(TEST_INDICATORS)
recheck: clean-test-indicators
$(REMAKE) check
LCOVDIR := build/coverage/$(BUILD_MODE)
LCOVHTML := $(LCOVDIR)/index.html
lcov: $(LCOVHTML)
$(LCOVHTML): $(TEST_INDICATORS)
$(V)mkdir -p $(@D)
$(V)lcov --capture --directory . --output-file $(LCOVDIR)/lcov.info --no-external 2>&1 | xargs -i echo " [lcov] {}"
$(V)genhtml $(LCOVDIR)/lcov.info --demangle-cpp --output-directory $(LCOVDIR) 2>&1 | xargs -i echo " [genhtml] {}"
$(V)echo
$(V)echo " You can open now file://$$(readlink -e $@)"
####################### cleaning #########################
clean-test-indicators:
$(V)rm -f $(TEST_INDICATORS)
clean-tests::
$(V)rm -rf $(BINDIR)/$(TESTDIR) $(OBJDIR)/$(TESTDIR) $(DEPDIR)/$(TESTDIR)
clean-test-%:
$(V)rm -f $(OBJDIR)/$(TESTDIR)/Test$*.$(OBJEXT) $(BINDIR)/$(TESTDIR)/Test$*.$(TESTEXT)
clean-lcov:
$(V)rm -rf $(LCOVDIR)
clean::
$(V)rm -rf $(BUILDDIR) $(PRJ_INFO_HEADER)
-include $(DEP_FILES)