-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (77 loc) · 2.18 KB
/
Copy pathMakefile
File metadata and controls
101 lines (77 loc) · 2.18 KB
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
CC=gcc
CFLAGS=-c -g -Wall
AR=ar
ARFLAGS=-rc
# Source directory
SRC=Src
TEST_SRC=tests
OBJ=build/obj
TEST_OBJ=tests/build/obj
# Returns all files with *.c extension from $(SRC) directory.
SRCS=$(wildcard $(SRC)/*.c)
TEST_SRCS=$(wildcard $(TEST_SRC)/*.c)
# This takes $(SRCS) as input,
# if the $(SRC)/%.c pattern is matched,
# then it is changed to $(OBJ)/%.o and added to return value.
# This way, it converts the list of C files specified in SRCS to list of .o
# files, to build object files.
OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
TEST_OBJS=$(patsubst $(TEST_SRC)/%.c, $(TEST_OBJ)/%.o, $(TEST_SRCS))
BINDIR=build/bin
BINNAME=ring
BIN=$(BINDIR)/lib$(BINNAME)
TEST_BINDIR=tests/build/bin
TEST_BINNAME=test
TEST_BIN=$(TEST_BINDIR)/$(TEST_BINNAME)
LIBDIR=lib
TEST_LD_FLAGS=-I$(LIBDIR) -L$(LIBDIR) -l$(BINNAME) -lcriterion
STATICLIB=$(BIN).a
CRITERION_FLAGS=--verbose --full-stats
init:
mkdir -p $(TEST_BINDIR)
mkdir -p $(TEST_OBJ)
mkdir -p $(BINDIR)
mkdir -p $(OBJ)
all: lib test
lib: $(BIN)
cp $(BINDIR)/* $(LIBDIR)/
cp $(SRC)/*.h $(LIBDIR)/
# Compiles static library
$(BIN): $(OBJS)
# $(CC) $(CFLAGS) $(OBJS) -o $@
$(AR) $(ARFLAGS) $(BIN).a $(OBJS)
# Creates object files from c files
$(OBJ)/%.o: $(SRC)/%.c
$(CC) $(CFLAGS) -c $< -o $@
test: lib $(TEST_BIN)
$(info Running unit tests...)
$(TEST_BIN) $(CRITERION_FLAGS)
# $(CC) $(TEST_CFLAGS) -c tests/test.c -o tests/test.o
$(TEST_BIN): $(TEST_OBJS)
$(CC) $(TEST_CFLAGS) $(TEST_OBJS) -o $@ $(TEST_LD_FLAGS)
$(TEST_OBJ)/%.o: $(TEST_SRC)/%.c
$(CC) $(TEST_CFLAGS) -c $< -o $@ $(TEST_LD_FLAGS)
cicd_run:
$(error Thi is supposed to be run by CI/CD system. Run unit tests, and\
generate docs if tests passed.)
# To assure it will work
.PHONY: clean
# Removes compiled files
clean:
$(RM) -rf $(BINDIR)/* $(OBJ)/*
.PHONY: clean_test
clean_test:
$(RM) -rf $(TEST_BINDIR)/* $(TEST_OBJ)/*
.PHONY: clean_all
clean_all: clean clean_test
# To assure it will work, whether docs directory is present or not
.PHONY: docs
docs:
ifeq (, $(shell which doxygen))
$(error No doxygen installed. Cannot generate docs.)
endif
$(RM) -rf docs
doxygen doxyConfig
# Prints all .h and .c files
print: $(SRCS) $(wildcard $(SRC)/*.h) $(TEST_SRCS)
ls -la $?