-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
61 lines (48 loc) · 1.87 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
# Choose your compiler (depending on your environment clang/gcc)
CC=gcc
# Add flags to the compilation
CC_FLAGS= -Wpedantic -Wall -Wextra -g
# These variables hold the name of all source files/headers/object files
SRCS=$(wildcard src/*.c)
HDRS=$(wildcard src/*.h)
OBJS=$(patsubst src/%.c,bin/%.o,$(SRCS))
TST_SRCS=$(wildcard tests/*.c)
TST_HDRS=$(wildcard tests/*.h)
TST_OBJS=$(filter-out bin/main.o, $(OBJS))
MU_TST_SRCS=$(wildcard mutests/*.c) mutests/munit/munit.c
MU_TST_HDRS=$(wildcard mutests/*.h) mutests/munit/munit.h
MU_TST_OBJS=$(filter-out bin/main.o, $(OBJS))
# To display one of the above variable, uncomment the next line
# $(info SRCS is $(SRCS))
# $(info HDRS is $(HDRS))
# $(info OBJS is $(OBJS))
# $(info TST_SRCS is $(TST_SRCS))
# $(info TST_OBJS is $(TST_OBJS))
# $(info MU_TST_SRCS is $(MU_TST_SRCS))
# $(info MU_TST_HDRS is $(MU_TST_HDRS))
# $(info MU_TST_OBJS is $(MU_TST_OBJS))
default: bin/womc
all: default tests mutests
tests: bin/tests
mutests: bin/mutests
# This rule produces the executable by compiling and linking all objects
# $^ are the names of all prerequisites (the object files)
# $@ is the name of the target (bin/womc in this case)
bin/womc: $(OBJS)
$(CC) $^ -o $@
# must start with TAB character
# This rule produces all object files
# -c option tells gcc to only compile one source file at a time
# $< is the name of the first prerequisite (the c file in this case)
bin/%.o: src/%.c $(HDRS)
$(CC) $< $(CC_FLAGS) -c -o $@
# must start with TAB character
# To use munit the test suite written in tests/mutests will be executed
bin/tests: $(TST_SRCS) $(TST_OBJS)
$(CC) $^ $(TST_HDRS) $() $(CC_FLAGS) -o $@
# To use munit the test suite written in tests/mutests will be executed
bin/mutests: $(MU_TST_SRCS) $(MU_TST_OBJS) $(MU_TST_HDRS)
$(CC) $(MU_TST_SRCS) $(MU_TST_OBJS) $(CC_FLAGS) -o $@
.PHONY: clean
clean:
rm -f $(OBJS) bin/womc bin/tests bin/mutests