-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
91 lines (66 loc) · 2.4 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
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
INC_DIR = inc
SRC_DIR = src
MISC_DIR = misc
OBJ_DIR = obj
BISON_INPUT = $(MISC_DIR)/parser.y
BISON_OUTPUT = $(MISC_DIR)/parser.cpp
FLEX_INPUT = $(MISC_DIR)/lexer.l
FLEX_OUTPUT = $(MISC_DIR)/lexer.cpp
MISC_SRCS = $(BISON_OUTPUT) $(FLEX_OUTPUT)
MISC_OBJ = $(patsubst $(MISC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(MISC_SRCS))
MISC_DEP = $(patsubst $(MISC_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(MISC_SRCS))
COMMON_DIR = $(SRC_DIR)/common
COMMON_SRCS = $(wildcard $(COMMON_DIR)/*.cpp)
COMMON_OBJ = $(patsubst $(COMMON_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(COMMON_SRCS))
COMMON_DEP = $(patsubst $(COMMON_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(COMMON_SRCS))
ASM_DIR = $(SRC_DIR)/assembler
ASM_SRCS = $(wildcard $(ASM_DIR)/*.cpp)
ASM_OBJ = $(patsubst $(ASM_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(ASM_SRCS))
ASM_OBJ += $(MISC_OBJ)
ASM_OBJ += $(COMMON_OBJ)
ASM_DEP = $(patsubst $(ASM_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(ASM_SRCS))
LINKER_DIR = $(SRC_DIR)/linker
LINKER_SRCS = $(wildcard $(LINKER_DIR)/*.cpp)
LINKER_OBJ = $(patsubst $(LINKER_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(LINKER_SRCS))
LINKER_OBJ += $(COMMON_OBJ)
LINKER_DEP = $(patsubst $(LINKER_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(LINKER_SRCS))
EMULATOR_DIR = $(SRC_DIR)/emulator
EMULATOR_SRCS = $(wildcard $(EMULATOR_DIR)/*.cpp)
EMULATOR_OBJ = $(patsubst $(EMULATOR_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(EMULATOR_SRCS))
EMULATOR_OBJ += $(COMMON_OBJ)
EMULATOR_DEP = $(patsubst $(EMULATOR_DIR)/%.cpp, $(OBJ_DIR)/%.d, $(EMULATOR_SRCS))
CXX = g++ -std=c++17
CXXFLAGS = -MMD -MP -I$(INC_DIR)
all: assembler linker emulator
assembler: $(ASM_OBJ)
$(CXX) -o $@ $^
linker: $(LINKER_OBJ)
$(CXX) -o $@ $^
emulator: $(EMULATOR_OBJ)
$(CXX) -o $@ $^
$(OBJ_DIR)/%.o: $(ASM_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(OBJ_DIR)/%.o: $(LINKER_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(OBJ_DIR)/%.o: $(MISC_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(OBJ_DIR)/%.o: $(EMULATOR_DIR)/%.cpp | $(EMULATOR_DIR)
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(OBJ_DIR):
mkdir -p $@
-include $(ASM_DEP)
-include $(LINKER_DEP)
-include $(MISC_DEP)
-include $(COMMON_DEP)
-include $(EMULATOR_DEP)
$(BISON_OUTPUT): $(BISON_INPUT)
bison -d $^
$(FLEX_OUTPUT): $(FLEX_INPUT)
flex $^
clean:
rm -rf assembler linker emulator
rm -rf $(OBJ_DIR)
rm -f $(MISC_DIR)/*.hpp $(MISC_DIR)/*.cpp
find . -type f \( -name "*.o" -o -name "*.hex" -o -name "*.objdump" \) -delete