-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (49 loc) · 1.51 KB
/
Makefile
File metadata and controls
64 lines (49 loc) · 1.51 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
IDIR=include
CC=gcc
CFLAGS=-I$(IDIR) -g
CFLAGS_EXTRA=-Wall -Wextra -Wpedantic \
-Wformat=2 -Wno-unused-parameter -Wshadow \
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
-Wredundant-decls -Wnested-externs -Wmissing-include-dirs \
-Wjump-misses-init -Wlogical-op
EXEC=bake
VALGRIND=valgrind --leak-check=yes
SDIR=src
BDIR=build
TDIR=test
LIBS=-lm -lpcre -pthread
_DEPS=common.h tokenizer.h list.h rule.h parser.h e4c_lite.h map.h graph.h run.h
DEPS=$(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ=tokenizer.o list.o rule.o parser.o e4c_lite.o map.o graph.o
OBJ=$(patsubst %,$(BDIR)/%,$(_OBJ))
_TESTS=test_tokenizer test_list test_parser test_map test_graph
TESTS=$(patsubst %,$(BDIR)/%,$(_TESTS))
# mkdir the build directory when Makefile is parsed
$(shell mkdir -p $(BDIR))
all: $(EXEC) $(TESTS)
# run executable
run: $(EXEC)
$(BDIR)/$(EXEC)
# build executable
$(EXEC): $(SDIR)/main.c $(OBJ)
$(CC) -o $(BDIR)/$@ $(SDIR)/main.c $(OBJ) $(CFLAGS) $(CFLAGS_EXTRA) $(LIBS)
# build object files from source files
$(BDIR)/%.o: $(SDIR)/%.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CFLAGS_EXTRA) $(LIBS)
# run all tests
run-tests: $(TESTS)
@for file in $(TESTS); do \
echo "\n\nRunning $$file...\n"; \
$(VALGRIND) $$file; \
done
# run a particular test
run-test-%: $(BDIR)/test_%
$(VALGRIND) $(BDIR)/test_$*
# compiling tests
tests: $(TESTS)
$(BDIR)/test_%: $(TDIR)/test_%.c $(OBJ) $(DEPS)
$(CC) -o $@ $(TDIR)/test_$*.c $(OBJ) $(CFLAGS) -g $(LIBS)
# clean the build directory
.PHONY: clean
clean:
rm -rf $(BDIR)