-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (61 loc) · 2.23 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
TARGET = chip8
SOURCE_DIR = src/
INCLUDE_DIR = include/
BUILD_DIR = build/
LIBS = SDL2
CC = clang
CFLAGS = -Wall
CFLAGS += -Wextra
CFLAGS += -Wpointer-arith
CFLAGS += -Wcast-align
CFLAGS += -Wwrite-strings
CFLAGS += -Wswitch-default
CFLAGS += -Wunreachable-code
CFLAGS += -Winit-self
CFLAGS += -Wmissing-field-initializers
CFLAGS += -Wno-unknown-pragmas
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
CFLAGS += -Wold-style-definition
_OBJ = input.o output.o cpu.o cycles.o main.o debugging.o
OBJ = $(patsubst %,$(BUILD_DIR)%,$(_OBJ))
$(TARGET): $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) -l$(LIBS) -I$(INCLUDE_DIR)
$(BUILD_DIR)%.o: $(SOURCE_DIR)%.c
$(CC) -c -o $@ $< $(CFLAGS) -I$(INCLUDE_DIR)
# ---------------------------------------------------------
# Unit Testing
# ---------------------------------------------------------
TEST_DIR = test/
TEST_BUILD_DIR = build/tests/
TEST_RESULTS = test/results/
TEST_LIBS = cunit
_TEST_OBJ = cpu_test.o cycles_test.o
TEST_OBJ = $(patsubst %,$(TEST_BUILD_DIR)%,$(_TEST_OBJ))
SUITES_RUN = `grep Suite $(TEST_RESULTS)*.txt | sed "s/Suite: //g"`
PASSED_COUNT = `grep -c passed $(TEST_RESULTS)*.txt`
FAILED_COUNT = `grep -c FAILED $(TEST_RESULTS)*.txt`
FAILED = `grep FAILED $(TEST_RESULTS)*.txt`
.PHONY: test
test: clean $(TEST_RESULTS)test_results.txt
@echo "-----------------------\nTEST RESULTS\n-----------------------"
@echo "\nSUITES\n-----------------------"
@echo "$(SUITES_RUN)"
@echo "\nFAILED: $(FAILED_COUNT)\n-----------------------"
@echo "$(FAILED)"
@echo "\nPASSED: $(PASSED_COUNT)\n-----------------------"
@echo "\nDONE"
$(TEST_RESULTS)test_results.txt: $(TEST_OBJ)
@for test in $(TEST_OBJ) ; do \
./$$test >> $(TEST_RESULTS)test_results.txt ; done
$(TEST_BUILD_DIR)cpu_test.o: $(TEST_DIR)cpu_test.c
$(CC) $< $(SOURCE_DIR)cpu.c $(SOURCE_DIR)input.c -I$(INCLUDE_DIR) -l$(TEST_LIBS) -l$(LIBS) -o $@
$(TEST_BUILD_DIR)cycles_test.o: $(TEST_DIR)cycles_test.c
$(CC) $(CFLAGS) $< $(SOURCE_DIR)cycles.c -I$(INCLUDE_DIR) -l$(TEST_LIBS) -l$(LIBS) -o $@
# ---------------------------------------------------------
# Misc
# ---------------------------------------------------------
MKDIR = mkdir -p
.PHONY: clean
clean:
rm -f $(TARGET) $(BUILD_DIR)*.o $(TEST_BUILD_DIR)*.o $(TEST_RESULTS)*.txt