-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (38 loc) · 1.18 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
# Reference: https://makefiletutorial.com/#the-all-target
CXX := g++
CXXFLAGS := -std=c++2a -g -O0 # TODO: - add Wall flag.
# TODO: - need a release version.
TARGET_EXEC := eucleia
TESTPLAN_MAIN := test/unit/Main.ek
INSTALL_DIR := install
BUILD_DIR := build
SRC_DIR := src
# Find all source files.
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
# Find all object files.
_OBJS := $(patsubst %.cpp, %.o, $(SRCS))
OBJS := $(addprefix $(BUILD_DIR)/, $(_OBJS))
# Find all directories so compiler can find headers.
INC_DIRS := $(shell find $(SRC_DIR) -type d)
# Prepend directories with '-I'.
INC_FLAGS := $(addprefix -I, $(INC_DIRS))
# Linker flags.
LDFLAGS := $(INC_FLAGS)
# Final build step. Run on all object files.
$(INSTALL_DIR)/$(TARGET_EXEC): $(OBJS)
mkdir -p $(INSTALL_DIR)
$(CXX) $(OBJS) -o $@
# Build step for cpp source files. Run on all source files.
$(BUILD_DIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@ $(LDFLAGS)
all: $(INSTALL_DIR)/$(TARGET_EXEC)
.PHONY: test
test: $(INSTALL_DIR)/$(TARGET_EXEC)
$(INSTALL_DIR)/$(TARGET_EXEC) $(TESTPLAN_MAIN)
debug:
@echo "srcs: $(SRCS)"
@echo "objs: $(OBJS)"
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(INSTALL_DIR)