-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (72 loc) · 2.47 KB
/
Makefile
File metadata and controls
92 lines (72 loc) · 2.47 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
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
CC ?= cc
# Stronger warnings for code quality
CFLAGS ?= -O2 -Iinclude -Wall -Wextra -Wpedantic -Wconversion -Wshadow \
-Wcast-align -Wcast-qual -Wpointer-arith -Wformat=2 \
-Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wundef \
-std=c11
AR ?= ar
CFLAGS += -I./external/EmbeddedSpacePacket/include -fPIC
BUILD_DIR ?= build
OBJ_DIR := $(BUILD_DIR)/obj
LIB_DIR := $(BUILD_DIR)/lib
BIN_DIR := $(BUILD_DIR)/bin
# Source files
CORE_SRCS := src/spacewire_codec.c \
src/spacewire_frame.c \
src/spacewire_router.c \
src/spacewire_packet.c
ESP_SRCS := external/EmbeddedSpacePacket/src/space_packet.c
EXAMPLE_SRCS := examples/main.c
TEST_SRCS := tests/unit_tests.c
# Object files
CORE_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(CORE_SRCS))
ESP_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(ESP_SRCS))
EXAMPLE_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(EXAMPLE_SRCS))
TEST_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(TEST_SRCS))
# Output files
LIB_STATIC := $(LIB_DIR)/libspacewire.a
LIB_SHARED := $(LIB_DIR)/libspacewire.so
EXAMPLE_BIN := $(BIN_DIR)/spacewire_example
TEST_BIN := $(BIN_DIR)/spacewire_tests
# Build targets
.PHONY: all clean test example lib coverage-html help distclean
all: lib example
lib: $(LIB_STATIC) $(LIB_SHARED)
$(LIB_STATIC): $(CORE_OBJS) $(ESP_OBJS)
@mkdir -p $(dir $@)
$(AR) rcs $@ $^
$(LIB_SHARED): $(CORE_OBJS) $(ESP_OBJS)
@mkdir -p $(dir $@)
$(CC) -shared -o $@ $^
example: $(EXAMPLE_BIN)
$(EXAMPLE_BIN): $(EXAMPLE_OBJS) $(LIB_STATIC)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $^
test: $(TEST_BIN)
./$(TEST_BIN)
$(TEST_BIN): $(TEST_OBJS) $(LIB_STATIC)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $^
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -rf $(BUILD_DIR)
rm -f libspacewire.a libspacewire.so spacewire_example spacewire_tests
coverage-html:
bash scripts/coverage_html.sh
distclean: clean
find . -name "*.o" -delete
help:
@echo "EmbeddedSpaceWire Build System"
@echo "=============================="
@echo "Targets:"
@echo " all - Build library and examples (default)"
@echo " lib - Build static and shared libraries"
@echo " example - Build example application"
@echo " test - Build and run unit tests"
@echo " coverage-html - Generate HTML coverage report"
@echo " output - Build artifacts are written to ./build"
@echo " clean - Remove build artifacts"
@echo " distclean - Clean including object files"
@echo " help - Display this help message"