1TEST_PROGRAM=test_multi_heap
2all: $(TEST_PROGRAM)
3
4ifneq ($(filter clean,$(MAKECMDGOALS)),)
5.NOTPARALLEL:  # prevent make clean racing the other targets
6endif
7
8SOURCE_FILES = $(abspath \
9    ../multi_heap.c \
10    ../heap_tlsf.c \
11	../multi_heap_poisoning.c \
12	test_multi_heap.cpp \
13	main.cpp \
14    )
15
16INCLUDE_FLAGS = -I../include -I../../../tools/catch
17
18GCOV ?= gcov
19
20CPPFLAGS += $(INCLUDE_FLAGS) -D CONFIG_LOG_DEFAULT_LEVEL -g -fstack-protector-all -m32  -DCONFIG_HEAP_POISONING_COMPREHENSIVE
21CFLAGS += -Wall -Werror -fprofile-arcs -ftest-coverage
22CXXFLAGS += -std=c++11 -Wall -Werror  -fprofile-arcs -ftest-coverage
23LDFLAGS += -lstdc++ -fprofile-arcs -ftest-coverage -m32
24
25OBJ_FILES = $(filter %.o, $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o))
26
27COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
28
29$(TEST_PROGRAM): $(OBJ_FILES)
30	g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES)
31
32$(OUTPUT_DIR):
33	mkdir -p $(OUTPUT_DIR)
34
35test: $(TEST_PROGRAM)
36	./$(TEST_PROGRAM)
37
38$(COVERAGE_FILES): $(TEST_PROGRAM) test
39
40coverage.info: $(COVERAGE_FILES)
41	find ../ -name "*.gcno" -exec $(GCOV) -r -pb {} +
42	lcov --capture --directory $(abspath ../) --no-external --output-file coverage.info --gcov-tool $(GCOV)
43
44coverage_report: coverage.info
45	genhtml coverage.info --output-directory coverage_report
46	@echo "Coverage report is in coverage_report/index.html"
47
48clean:
49	rm -f $(OBJ_FILES) $(TEST_PROGRAM)
50	rm -f $(COVERAGE_FILES) *.gcov
51	rm -rf coverage_report/
52	rm -f coverage.info
53
54.PHONY: clean all test
55