-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
87 lines (66 loc) · 2.02 KB
/
Makefile
File metadata and controls
87 lines (66 loc) · 2.02 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
#vars
TARGET_EXEC := pydotcpp
BUILD_DIR := build
SRC_DIR := src
TEST_DIR := tests
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
OBJS := $(SRCS:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INCS := $(shell find $(SRC_DIR) -type d)
ENTRYPOINT := entrypoint.cpp
ENTRY_OBJ := $(BUILD_DIR)/entrypoint.o
LEXER_TEST := $(BUILD_DIR)/$(TEST_DIR)/lexer_test
PARSER_TEST := $(BUILD_DIR)/$(TEST_DIR)/parser_test
EVALUATOR_TEST := $(BUILD_DIR)/$(TEST_DIR)/evaluator_test
TEST_DEPS := $(LEXER_TEST).d $(PARSER_TEST).d
INC_FLAGS := $(addprefix -I,$(INCS))
CPPFLAGS := $(INC_FLAGS) -MMD -MP
LDFLAGS :=
CXX := g++
#all
all: $(BUILD_DIR)/$(TARGET_EXEC)
#executable dependencies
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) $(ENTRY_OBJ)
@echo "Linking"
mkdir -p $(BUILD_DIR)
$(CXX) $(OBJS) $(ENTRY_OBJ) -o $@ $(LDFLAGS)
#object dependencies
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@echo "Building dependencies"
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) -c $< -o $@
@echo
$(ENTRY_OBJ): $(ENTRYPOINT)
mkdir -p $(BUILD_DIR)
$(CXX) $(CPPFLAGS) -c $< -o $@
#for change in header files
-include $(DEPS)
-include $(TEST_DEPS)
.PHONY: all clean run
run: all
./$(BUILD_DIR)/$(TARGET_EXEC)
clean:
rm -rf $(BUILD_DIR)
format:
find $(SRC_DIR)/ -name '*.cpp' -o -name '*.h' | xargs clang-format -i
check-format:
find $(SRC_DIR)/ -name '*.cpp' -o -name '*.h' | xargs clang-format --dry-run --Werror
# separate tests for lexer, parser, evaluator
test-lexer: $(LEXER_TEST)
./$(LEXER_TEST)
test-parser: $(PARSER_TEST)
./$(PARSER_TEST)
test-evaluator: $(EVALUATOR_TEST)
./$(EVALUATOR_TEST)
# macro for executable and object dependencies for tests
define TEST_RULE
$(1): $(OBJS) $(1).o
mkdir -p $(BUILD_DIR)/$(TEST_DIR)
$(CXX) $(CPPFLAGS) $$^ -o $$@
$(1).o: $(TEST_DIR)/$(notdir $(1)).cpp
mkdir -p $(BUILD_DIR)/$(TEST_DIR)
$(CXX) $(CPPFLAGS) -c $$< -o $$@
endef
$(eval $(call TEST_RULE,$(LEXER_TEST)))
$(eval $(call TEST_RULE,$(PARSER_TEST)))
$(eval $(call TEST_RULE,$(EVALUATOR_TEST)))