-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
132 lines (98 loc) · 3.18 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#
# Makefile of prismocr
#
# To build the project run `make`, it will create an executable called **ocr**
# in the **build/** directory
#
# TODO: add support for .c not at the root of src/
CC := gcc
CPPFLAGS := -MMD -Iinclude/
CFLAGS := -std=c99 -Wall -Wextra -Werror -Wpedantic $$(pkg-config --cflags gtk+-3.0)
LDLIBS := -lm $$(pkg-config --libs gtk+-3.0) -export-dynamic -rdynamic
BUILDDIR := build
EXEC := ocr
SRC_SUBDIRS := $(sort $(patsubst src/%,%,$(dir $(wildcard src/*) $(wildcard src/**/*.c))))
OBJS := $(patsubst src/%.c,%.o,$(wildcard src/*.c) $(wildcard src/**/*.c))
#
# Debug variables
#
DBGCFLAGS := $(CFLAGS) -g -O0 -DDEBUG -fsanitize=address
DBGDIR := $(BUILDDIR)/debug
DBGOBJDIR := $(DBGDIR)/obj
DBGOBJSUBDIRS := $(addprefix $(DBGOBJDIR)/,$(SRC_SUBDIRS))
DBGOBJS := $(addprefix $(DBGOBJDIR)/,$(OBJS))
#
# Release variables
#
RLSCFLAGS := $(CFLAGS) -O3 -DNDEBUG
RLSDIR := $(BUILDDIR)/release
RLSOBJDIR := $(RLSDIR)/obj
RLSOBJSUBDIRS := $(addprefix $(RLSOBJDIR)/,$(SRC_SUBDIRS))
RLSOBJS := $(addprefix $(RLSOBJDIR)/,$(OBJS))
#
# Test variables
#
TSTCFLAGS := $(CFLAGS) -g -O0 -DDEBUG
TSTDIR := $(BUILDDIR)/test
TSTOBJDIR := $(TSTDIR)/obj
TSTEXEC := $(addprefix $(TSTDIR)/,$(basename $(notdir $(wildcard test/*.c))))
TSTOBJS := $(addprefix $(TSTOBJDIR)/,$(addsuffix .o,$(notdir $(TSTEXEC))))
#
# Temp variables
#
TMPDIR := $(BUILDDIR)/temp
TMPOBJDIR := $(TMPDIR)/obj
TMPOBJSUBDIRS := $(addprefix $(TMPOBJDIR)/,$(SRC_SUBDIRS))
TMPOBJS := $(addprefix $(TMPOBJDIR)/,$(OBJS))
.PHONY: all prep remake debug release test clean mrproper format cppcheck temp prep-temp
all: release
#
# Debug rules
#
debug: prep $(DBGDIR)/$(EXEC)
$(DBGDIR)/$(EXEC): $(DBGOBJS)
$(CC) $^ -o $@ $(CPPFLAGS) $(DBGCFLAGS) $(LDLIBS)
$(DBGOBJDIR)/%.o: src/%.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(DBGCFLAGS)
#
# Release rules
#
release: prep $(RLSDIR)/$(EXEC)
$(RLSDIR)/$(EXEC): $(RLSOBJS)
$(CC) $^ -o $@ $(CPPFLAGS) $(RLSCFLAGS) $(LDLIBS)
$(RLSOBJDIR)/%.o: src/%.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(RLSCFLAGS)
#
# Test rules
#
test: clean release Unity $(TSTEXEC)
$(foreach TEST,$(filter $(TSTDIR)/%,$^),./$(TEST) &&) echo "All test passed"
Unity:
@git clone https://github.com/ThrowTheSwitch/Unity.git
$(TSTDIR)/%: $(TSTOBJDIR)/%.o $(filter-out $(RLSOBJDIR)/main.o,$(RLSOBJS)) Unity/src/unity.c
$(CC) $^ -o $@ $(CPPFLAGS) $(TSTCFLAGS) $(LDLIBS) -IUnity/src
$(TSTOBJDIR)/%.o: test/%.c $(filter-out $(RLSOBJDIR)/main.o,$(RLSOBJS))
$(CC) -c $^ -o $@ $(CPPFLAGS) $(TSTCFLAGS) -IUnity/src
#
# Other rules
#
prep:
@mkdir -p $(TSTOBJDIR) $(DBGOBJSUBDIRS) $(RLSOBJSUBDIRS)
remake: clean all
clean:
$(RM) -r $(DBGOBJDIR) $(RLSOBJDIR)
mrproper:
$(RM) -r $(BUILDDIR)
format: src/*.c src/**/*.c include/*.h include/**/*.h test/*.c
@clang-format --style=file -i $^
cppcheck: src/*.c src/**/*.c
@cppcheck --enable=warning,style,performance,portability,information,\
missingInclude -q --std=c99 -Iinclude/ $^
temp: prep-temp $(TMPDIR)/$(EXEC)
prep-temp:
@if [ -d $(TMPDIR) ] ; then rm -r $(TMPDIR) ; fi
@mkdir -p $(TMPOBJSUBDIRS)
$(TMPDIR)/$(EXEC): $(TMPOBJS)
$(CC) $^ -o $@ $(CPPFLAGS) $(TMPCFLAGS) $(LDLIBS) $$(pkg-config --cflags gtk+-3.0)
$(TMPOBJDIR)/%.o: src/%.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(TMPCFLAGS) $$(pkg-config --cflags gtk+-3.0)