-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
36 lines (26 loc) · 886 Bytes
/
Copy pathMakefile
File metadata and controls
36 lines (26 loc) · 886 Bytes
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
CXX ?= g++
CXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra
SRC_DIR = src
BUILD_DIR = build
TARGET = FlashTerm
TEST_TARGET = $(BUILD_DIR)/run_tests
# Everything except main.cpp, so the tests can link against it.
LIB_SRCS = $(filter-out $(SRC_DIR)/main.cpp,$(wildcard $(SRC_DIR)/*.cpp))
SRCS = $(LIB_SRCS) $(SRC_DIR)/main.cpp
LIB_OBJS = $(LIB_SRCS:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -I$(SRC_DIR) -MMD -MP -c $< -o $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
test: $(TEST_TARGET)
./$(TEST_TARGET)
$(TEST_TARGET): tests/tests.cpp $(LIB_OBJS) | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -I$(SRC_DIR) -o $@ tests/tests.cpp $(LIB_OBJS)
clean:
rm -rf $(BUILD_DIR) $(TARGET)
-include $(OBJS:.o=.d)
.PHONY: all test clean