-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
61 lines (45 loc) · 1.54 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
CC = gcc
CFLAGS = -Wall -Werror -I$(SRC_DIR) -I$(UNITY_SRC_DIR) -I$(TEST_DIR)
LDFLAGS =
SRC_DIR = src
UNITY_SRC_DIR = Unity/src
TEST_DIR = test
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
RESULT_DIR = $(BUILD_DIR)/results
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
UNITY_SRC_FILES = $(wildcard $(UNITY_SRC_DIR)/*.c)
TEST_FILES = $(wildcard $(TEST_DIR)/*.c)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES)) \
$(patsubst $(UNITY_SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(UNITY_SRC_FILES)) \
$(patsubst $(TEST_DIR)/%.c, $(OBJ_DIR)/%.o, $(TEST_FILES))
TARGET = $(BUILD_DIR)/firmware
RESULTS = $(patsubst $(TEST_DIR)/Test%.c, $(RESULT_DIR)/Test%.txt, $(TEST_FILES))
all: create_dirs $(TARGET)
$(TARGET): $(OBJ_FILES)
@$(CC) $(LDFLAGS) $^ -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(UNITY_SRC_DIR)/%.c
@$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(TEST_DIR)/%.c
@$(CC) $(CFLAGS) -c $< -o $@
create_dirs:
@mkdir -p $(BUILD_DIR)
@mkdir -p $(OBJ_DIR)
@mkdir -p $(RESULT_DIR)
clean:
@rm -rf $(BUILD_DIR)/*
.PHONY: all clean create_dirs test
# The extracted Unity part for displaying results
$(RESULT_DIR)/Test%.txt: $(TARGET)
@./$< > $@ 2>&1
test: CFLAGS += -DTEST
test: create_dirs $(RESULTS)
@echo "-----------------------\nIGNORES:\n-----------------------"
@grep -s IGNORE $^ || true
@echo "-----------------------\nFAILURES:\n-----------------------"
@grep -s FAIL $^ || true
@echo "-----------------------\nPASSED:\n-----------------------"
@grep -s PASS $^ || true
@echo "\nDONE"