-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
executable file
·244 lines (208 loc) · 5.15 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/make -f
UNAME = $(shell uname -s)
################################################################################
# SETTINGS #
################################################################################
# [ COMPILATION ]
CC = gcc
CFLAGS += -Wall -Werror -Wextra
CFLAGS += -Ofast -funroll-loops
CFLAGS += #-g -fsanitize=address
ifeq ($(UNAME),Linux)
CFLAGS += -Wno-unused-result
endif
OBJ_DIR = obj
# [ LIBRARIES ]
LIB = lib
LIBFT_DIR = $(LIB)/libft
LIBFT = $(LIBFT_DIR)/libft.a
LIBFT_INC = -I $(LIBFT_DIR)/inc
ifeq ($(UNAME),Linux)
GFX_FRAMEWORK = -lX11 -lXext -lbsd -lm
MLX_DIR = $(LIB)/libmlx/linux
MLX_INC = -I $(MLX_DIR)/inc
endif
ifeq ($(UNAME),Darwin)
GFX_FRAMEWORK = -framework OpenGL -framework AppKit
MLX_DIR = $(LIB)/libmlx/macos
MLX_INC = -I $(MLX_DIR)/inc
endif
LIBMLX = $(MLX_DIR)/libmlx.a
RVM_DIR = $(LIB)/refvm
RVM_INC = -I $(RVM_DIR)/inc
RVM_SRC_DIR = $(RVM_DIR)/src
RVM_SRC = \
zaz_op
RVM_OBJ_DIR = $(OBJ_DIR)/$(RVM_DIR)
RVM_OBJ = $(patsubst %, $(RVM_OBJ_DIR)/%.o, $(RVM_SRC))
# [ ASSEMBLER ]
ASM = asm
ASM_DIR = assembler
ASM_INC = -I $(ASM_DIR)/inc $(RVM_INC) $(LIBFT_INC)
ASM_SRC_DIR = $(ASM_DIR)/src
ASM_SRC = \
char_array\
count\
error\
file_op\
header_utils\
hexdump\
instruction_utils\
instructions\
is_operand\
label_utils\
main\
operand_error\
output\
queue_add\
resolve_labels\
string\
trim\
util\
validate_header\
whitespace
ASM_OBJ_DIR = $(OBJ_DIR)/$(ASM_DIR)
ASM_OBJ = $(patsubst %, $(ASM_OBJ_DIR)/%.o, $(ASM_SRC))
# [ DISASSEMBLER ]
DISASM = disasm
DISASM_DIR = disassembler
DISASM_INC = -I $(DISASM_DIR)/inc $(RVM_INC) $(LIBFT_INC)
DISASM_SRC_DIR = $(DISASM_DIR)/src
DISASM_SRC = \
file_op\
instruction\
main\
print\
stdin\
util
DISASM_OBJ_DIR = $(OBJ_DIR)/$(DISASM_DIR)
DISASM_OBJ = $(patsubst %, $(DISASM_OBJ_DIR)/%.o, $(DISASM_SRC))
# [ VIRTUAL MACHINE ]
VM = corewar
VM_DIR = vm
VM_INC = -I $(VM_DIR)/inc $(MLX_INC) $(LIBFT_INC)
ifeq ($(UNAME),Linux)
VM_INC += -I $(VM_DIR)/inc/linux
endif
ifeq ($(UNAME),Darwin)
VM_INC += -I $(VM_DIR)/inc/macos
endif
VM_SRC_DIR = $(VM_DIR)/src
VM_SRC = \
champ\
coreio\
execution\
gui/gui_bars\
gui/gui_blocks\
gui/gui_colors\
gui/gui_cpf\
gui/gui_hooks\
gui/gui_loop\
gui/gui_main
ifeq ($(UNAME),Linux)
VM_SRC += gui/gui_mlx_linux
endif
ifeq ($(UNAME),Darwin)
VM_SRC += gui/gui_mlx_macos
endif
VM_SRC += \
gui/gui_pc_boxes\
gui/gui_text\
main\
msg\
ops\
ops/op_add\
ops/op_aff\
ops/op_and\
ops/op_fork\
ops/op_ld\
ops/op_ldi\
ops/op_lfork\
ops/op_live\
ops/op_lld\
ops/op_lldi\
ops/op_nop\
ops/op_or\
ops/op_st\
ops/op_sti\
ops/op_sub\
ops/op_xor\
ops/op_zjmp\
process
VM_OBJ_DIR = $(OBJ_DIR)/$(VM_DIR)
VM_OBJ = $(patsubst %, $(VM_OBJ_DIR)/%.o, $(VM_SRC))
################################################################################
# COLORS #
################################################################################
COLSIZE = 50
NC = \033[0m
GREEN = \033[1;32m
RED = \033[1;31m
YELLOW = \033[1;33m
################################################################################
# RULES #
################################################################################
all: $(ASM) $(DISASM) $(VM)
# [ LINKING ]
$(ASM): $(LIBFT) $(ASM_OBJ) $(RVM_OBJ)
@printf "$(YELLOW)%-$(COLSIZE)s$(NC)" "Building $@... "
@$(CC) $(CFLAGS) $(LIBFT) $(ASM_OBJ) $(RVM_OBJ) -o $@
@echo "$(GREEN)DONE$(NC)"
$(DISASM): $(LIBFT) $(DISASM_OBJ) $(RVM_OBJ)
@printf "$(YELLOW)%-$(COLSIZE)s$(NC)" "Building $@... "
@$(CC) $(CFLAGS) $(LIBFT) $(DISASM_OBJ) $(RVM_OBJ) -o $@
@echo "$(GREEN)DONE$(NC)"
$(VM): $(LIBFT) $(LIBMLX) $(VM_OBJ)
@printf "$(YELLOW)%-$(COLSIZE)s$(NC)" "Building $@... "
@$(CC) $(CFLAGS) $(GFX_FRAMEWORK) $(LIBFT) $(LIBMLX) $(VM_OBJ) -o $@
@echo "$(GREEN)DONE$(NC)"
# [ COMPILING ]
$(ASM_OBJ_DIR)/%.o: $(ASM_SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo " > Compiling $<..."
@$(CC) $(CFLAGS) $(ASM_INC) -c $< -o $@
$(DISASM_OBJ_DIR)/%.o: $(DISASM_SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo " > Compiling $<..."
@$(CC) $(CFLAGS) $(DISASM_INC) -c $< -o $@
$(VM_OBJ_DIR)/%.o: $(VM_SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo " > Compiling $<..."
@$(CC) $(CFLAGS) $(VM_INC) -c $< -o $@
# [ LIBRARIES ]
$(LIBFT):
@printf "$(YELLOW)%-$(COLSIZE)s$(NC)" "Building $@... "
@make -C $(LIBFT_DIR)
$(LIBMLX):
@printf "$(YELLOW)%-$(COLSIZE)s$(NC)" "Building $@... "
@make -C $(MLX_DIR)
$(RVM_OBJ_DIR)/%.o: $(RVM_SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo " > Compiling $<..."
@$(CC) $(CFLAGS) $(ASM_INC) $(RVM_INC) -c $< -o $@
# [ CLEANING ]
again:
@rm -rf $(OBJ_DIR)
@echo "$(RED)Object files removed"
@rm -f $(ASM)
@echo "$(ASM) removed"
@rm -f $(DISASM)
@echo "$(DISASM) removed"
@rm -f $(VM)
@echo "$(VM) removed$(NC)"
@make
clean:
@make -C $(LIBFT_DIR) $@
@make -C $(MLX_DIR) $@
@rm -rf $(OBJ_DIR)
@echo "$(RED)Object files removed$(NC)"
fclean: clean
@make -C $(LIBFT_DIR) $@
@make -C $(MLX_DIR) $@
@rm -f $(ASM)
@echo "$(RED)$(ASM) removed"
@rm -f $(DISASM)
@echo "$(DISASM) removed"
@rm -f $(VM)
@echo "$(VM) removed$(NC)"
re: fclean all