-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
95 lines (78 loc) · 3.16 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
include Makefile.env
PROJNAME=circbuf
INCLUDEDIRS=include
LIBDIRS=
LIBNAMES=
OUTLIBDIR=lib
OUTLIBNAME_DEBUG=$(PROJNAME).debug
OUTLIBNAME_OPT=$(PROJNAME)
SRCDIR=src
TEST_SRCDIR=test
TEST_DEBUG_OUTDIR=test_out_debug
TEST_OPT_OUTDIR=test_out_opt
TEST_BIN=testrunner
OUTBIN=main.out
SHELL=/bin/bash
SRC_EXTENSION=.c
CC=gcc
CPP=g++
SHAREDFLAGS=-g3 -Wall -Werror -pedantic
CFLAGS=-std=c11 $(SHAREDFLAGS)
CPPFLAGS=-std=c++14 $(SHAREDFLAGS)
PROFILEFLAGS=--coverage
DEBUGFLAGS=-DCIRCBUF_DEBUG -O0
OPTIMIZEFLAGS=-O3 -Wno-unused
TEST_INCLUDEDIRS=$(INCLUDEDIRS) $(CXXTESTDIR)
TEST_LIBDIRS=$(LIBDIRS) $(OUTLIBDIR)
TEST_DEBUG_LIBNAMES=$(OUTLIBNAME_DEBUG) $(LIBNAMES)
TEST_OPT_LIBNAMES=$(OUTLIBNAME_OPT) $(LIBNAMES)
OBJDIR_DEBUG=obj_debug
OBJDIR_OPT=obj
SOURCES=$(shell find $(SRCDIR) -type f -name "*$(SRC_EXTENSION)")
TEST_SOURCES=$(shell find $(TEST_SRCDIR) -type f -name "*test.hpp")
OBJECTS_DEBUG=$(addprefix $(OBJDIR_DEBUG)/,$(SOURCES:$(SRC_EXTENSION)=.o))
OBJECTS_OPT=$(addprefix $(OBJDIR_OPT)/,$(SOURCES:$(SRC_EXTENSION)=.o))
INCLUDELINE=$(addprefix -I,$(INCLUDEDIRS))
LIBLINE=$(addprefix -L,$(LIBDIRS))
LIBNAMELINE=$(addprefix -l,$(LIBNAMES))
TEST_INCLUDELINE=$(addprefix -I,$(TEST_INCLUDEDIRS))
TEST_LIBLINE=$(addprefix -L,$(TEST_LIBDIRS))
TEST_DEBUG_LIBNAMELINE=$(addprefix -l,$(TEST_DEBUG_LIBNAMES))
TEST_OPT_LIBNAMELINE=$(addprefix -l,$(TEST_OPT_LIBNAMES))
default: debug opt
$(OBJECTS_DEBUG): $(OBJDIR_DEBUG)/%.o: %$(SRC_EXTENSION)
@[ -d $@ ] || mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(DEBUGFLAGS) $(PROFILEFLAGS) $(INCLUDELINE) $(LIBLINE) -o $@ $< $(LIBNAMELINE)
$(OBJECTS_OPT): $(OBJDIR_OPT)/%.o: %$(SRC_EXTENSION)
@[ -d $@ ] || mkdir -p $(@D)
$(CC) -c $(CFLAGS) $(OPTIMIZEFLAGS) $(INCLUDELINE) $(LIBLINE) -o $@ $< $(LIBNAMELINE)
debug: clean_profile $(OBJECTS_DEBUG)
mkdir -p $(OUTLIBDIR)
ar rcs $(OUTLIBDIR)/lib$(OUTLIBNAME_DEBUG).a $(OBJECTS_DEBUG)
opt: $(OBJECTS_OPT)
mkdir -p $(OUTLIBDIR)
ar rcs $(OUTLIBDIR)/lib$(OUTLIBNAME_OPT).a $(OBJECTS_OPT)
test: clean_test debug
mkdir -p $(TEST_DEBUG_OUTDIR)
$(CXXTESTDIR)/bin/cxxtestgen --error-printer -o $(TEST_DEBUG_OUTDIR)/tests.cpp $(TEST_SOURCES)
$(CPP) $(CPPFLAGS) $(DEBUGFLAGS) $(PROFILEFLAGS) $(TEST_INCLUDELINE) $(TEST_LIBLINE) -o $(TEST_DEBUG_OUTDIR)/tests.o $(TEST_DEBUG_OUTDIR)/tests.cpp $(TEST_DEBUG_LIBNAMELINE)
$(TEST_DEBUG_OUTDIR)/tests.o -v
coverage: test
lcov -q --capture --directory . --output-file coverage.info --no-external --exclude '*/$(TEST_DEBUG_OUTDIR)/*' --exclude '*/$(TEST_SRCDIR)/*'
genhtml coverage.info -q --output-directory coverage
test_opt: clean_test opt
mkdir -p $(TEST_OPT_OUTDIR)
$(CXXTESTDIR)/bin/cxxtestgen --error-printer -o $(TEST_OPT_OUTDIR)/tests.cpp $(TEST_SOURCES)
$(CPP) $(CPPFLAGS) $(OPTIMIZEFLAGS) $(TEST_INCLUDELINE) $(TEST_LIBLINE) -o $(TEST_OPT_OUTDIR)/tests.o $(TEST_OPT_OUTDIR)/tests.cpp $(TEST_OPT_LIBNAMELINE)
$(TEST_OPT_OUTDIR)/tests.o -v
clean_profile:
rm -f *.info
rm -rf coverage
rm -f tests.gcda tests.gcno
clean_test: clean_profile
rm -f $(TEST_DEBUG_OUTDIR)/*.o $(TEST_DEBUG_OUTDIR)/tests.cpp
rm -f $(TEST_OPT_OUTDIR)/*.o $(TEST_OPT_OUTDIR)/tests.cpp
clean: clean_profile clean_test
rm -rf $(OBJDIR_DEBUG) $(OBJDIR_OPT)
rm -f lib/*.a
all: clean debug opt test coverage test_opt