-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
70 lines (58 loc) · 2.59 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
CC=gcc
CFLAGS=-Wall -g
PROGRAM_NAME=videostego
PREFIX=/usr/local/bin
VALGRINDFLAGS=--tool=memcheck --leak-check=full --show-leak-kinds=all -v
PROFILE_FLAGS=-fprofile-arcs -ftest-coverage
TST_LIBS=-lcheck -lm -lpthread -lrt -lsubunit
COV_LIBS=-lgcov -coverage
SRC_DIR=src
TST_DIR=tests
TST_BIN=check_$(PROGRAM_NAME)_tests
SRC_FILES=$(addprefix $(SRC_DIR)/, *.c)
LIB_FILES=$(addprefix $(SRC_DIR)/, lib*.*)
TST_FILES=$(addprefix $(TST_DIR)/, *.c)
GCOV=gcovr
GCONV_FLAGS=-r . --html --html-details
all: coverage
build_lib_objects: $(LIB_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Building object files for each library source files ..."
$(CC) -c $(CFLAGS) $(PROFILE_FLAGS) $(LIB_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
build_tst_objects: $(TST_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Building object files for each testing source files ..."
$(CC) -c $(CFLAGS) $(PROFILE_FLAGS) $(TST_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
$(TST_BIN): build_lib_objects build_tst_objects build
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Building $(TST_BIN) binary ..."
$(CC) lib*.o check_$(PROGRAM_NAME).o $(TST_LIBS) $(COV_LIBS) -o $(TST_BIN)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
test: $(TST_BIN)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Running unit tests ..."
./$(TST_BIN)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
coverage: test
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Generating code coverage report ..."
$(GCOV) $(GCONV_FLAGS) -o coverage_report.html
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
build: $(SRC_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Building $(PROGRAM_NAME) binary ..."
$(CC) $(CFLAGS) -o $(PROGRAM_NAME) $(SRC_FILES)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
install: build
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Installing $(PROGRAM_NAME) ..."
install -m 0755 $(PROGRAM_NAME) $(PREFIX)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
uninstall: $(PREFIX)/$(PROGRAM_NAME)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Uninstall $(PROGRAM_NAME) from '$(PREFIX)' ..."
rm -f $(PREFIX)/$(PROGRAM_NAME)
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
valgrind: build
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Running memory check ..."
valgrind $(VALGRINDFLAGS) ./$(PROGRAM_NAME) -f $(FILE) -w -m $(MSG) > /dev/null
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
clean:
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Cleaning workdir ..."
rm -f *.o *.html *.gcda *.gcno $(addprefix $(SRC_DIR)/, *.gch) *$(PROGRAM_NAME)*
@echo "`date +'%Y/%m/%d %H:%M:%S'` [$@] Done!"
.PHONY: all build_lib_objects build_tst_objects test coverage build install uninstall valgrind clean