This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
502 lines (438 loc) · 16.3 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: nde-jesu <nde-jesu@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/09/10 16:16:29 by kibotrel #+# #+# #
# Updated: 2020/03/05 23:51:10 by nde-jesu ### ########.fr #
# #
# **************************************************************************** #
#---------------------------------- VARIABLES ---------------------------------#
# Environment.
RM = rm -rf
TAR = tar -xf
CURL = curl -L --output archive.tar
UNAME = $(shell uname -s)
ABSDIR = $(shell pwd)
URL_AO = http://downloads.xiph.org/releases/ao/libao-1.2.0.tar.gz
URL_SND = http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.28.tar.gz
SRCS_AO = libao-1.2.0
SRCS_SND = libsndfile-1.0.28
# Executable / Libraries.
FT = libft.a
BMP = libbmp.a
SND = libsndfile.a
NAME = doom-nukem
# Color codes.
RESET = \033[0m
GREEN = \033[32m
YELLOW = \033[33m
#--------------------------------- DIRECTORIES -------------------------------#
# Libraries.
LFT_DIR = libft
LBMP_DIR = libbmp
# I/O Compilation.
SRCS_DIR = srcs
OBJS_DIR = objs
# Location of all header files used in the project.
INCS_DIR := incs
INCS_DIR += libft/incs
INCS_DIR += libbmp/incs
# All the subdirectories used in the project.
OBJS_SUBDIRS := hud
OBJS_SUBDIRS += core
OBJS_SUBDIRS += game
OBJS_SUBDIRS += menu
OBJS_SUBDIRS += setup
OBJS_SUBDIRS += clean
OBJS_SUBDIRS += parse
OBJS_SUBDIRS += utils
OBJS_SUBDIRS += editor
OBJS_SUBDIRS += events
OBJS_SUBDIRS += texture
OBJS_SUBDIRS += settings
#------------------------------------ FILES -----------------------------------#
# Every libraries needed to compile the project.
LAO = $(LAO_DIR)/$(AO)
LFT = $(LFT_DIR)/$(FT)
LBMP = $(LBMP_DIR)/$(BMP)
LSDL = $(LSDL_DIR)/$(SDL)
LSND = $(LSND_DIR)/$(SND)
LTTF = $(LTTF_DIR)/$(TTF)
# Used header at each compilation to check file integrity.
INCS := incs/env.h
INCS += incs/hud.h
INCS += incs/core.h
INCS += incs/game.h
INCS += incs/menu.h
INCS += incs/clean.h
INCS += incs/parse.h
INCS += incs/enums.h
INCS += incs/setup.h
INCS += incs/utils.h
INCS += incs/editor.h
INCS += incs/events.h
INCS += incs/structs.h
INCS += incs/editor.h
INCS += incs/texture.h
INCS += incs/settings.h
# Source files.
SRCS := hud/debug.c
SRCS += hud/purse.c
SRCS += hud/weapon.c
SRCS += hud/lifebar.c
SRCS += hud/crosshair.c
SRCS += core/main.c
SRCS += core/game.c
SRCS += core/menu.c
SRCS += core/audio.c
SRCS += core/hooks.c
SRCS += core/editor.c
SRCS += core/selector.c
SRCS += core/settings.c
SRCS += core/tuto.c
SRCS += game/hud.c
SRCS += game/click.c
SRCS += game/camera.c
SRCS += game/engine.c
SRCS += game/effector.c
SRCS += game/reload.c
SRCS += game/physics.c
SRCS += game/movement.c
SRCS += game/keyboard.c
SRCS += game/message.c
SRCS += menu/click.c
SRCS += menu/motion.c
SRCS += clean/env.c
SRCS += clean/sdl.c
SRCS += clean/ttf.c
SRCS += clean/audio.c
SRCS += clean/engine.c
SRCS += parse/error.c
SRCS += parse/sector.c
SRCS += parse/main.c
SRCS += parse/tools.c
SRCS += parse/vertex.c
SRCS += parse/total.c
SRCS += parse/player_blank.c
SRCS += parse/hard_map.c
SRCS += parse/hard_map2.c
SRCS += parse/hard_map3.c
SRCS += setup/hud.c
SRCS += setup/game.c
SRCS += setup/audio.c
SRCS += setup/setup.c
SRCS += setup/graphic.c
SRCS += setup/settings.c
SRCS += setup/error_message.c
SRCS += utils/usage.c
SRCS += utils/data_0.c
SRCS += utils/data_1.c
SRCS += utils/data_2.c
SRCS += utils/data_3.c
SRCS += utils/data_4.c
SRCS += utils/data_5.c
SRCS += utils/data_6.c
SRCS += utils/engine.c
SRCS += utils/floats.c
SRCS += utils/maths_0.c
SRCS += utils/maths_1.c
SRCS += utils/ft_power.c
SRCS += utils/checks_00.c
SRCS += utils/checks_01.c
SRCS += utils/graphic_0.c
SRCS += utils/graphic_1.c
SRCS += utils/graphic_2.c
SRCS += utils/graphic_3.c
SRCS += utils/ft_strdel.c
SRCS += utils/ft_add_str.c
SRCS += utils/ft_mul_str.c
SRCS += utils/ft_realloc.c
SRCS += utils/ft_power_str.c
SRCS += utils/ft_strjoin_free.c
SRCS += utils/ft_str_binary_to_nb.c
SRCS += utils/ft_str_mantisse_to_nb.c
SRCS += events/mouse.c
SRCS += events/motion.c
SRCS += events/keyboard.c
SRCS += editor/keyboard.c
SRCS += editor/events.c
SRCS += editor/events_tools.c
SRCS += editor/setup.c
SRCS += editor/clean.c
SRCS += editor/delete.c
SRCS += editor/display.c
SRCS += editor/display_part2.c
SRCS += editor/display_utils.c
SRCS += editor/entity.c
SRCS += editor/entity_part2.c
SRCS += editor/edit_menu.c
SRCS += editor/edit_menu_utils.c
SRCS += editor/sec_edit_menu.c
SRCS += editor/sec_edit_menu_utils.c
SRCS += editor/picture.c
SRCS += editor/text.c
SRCS += editor/text_part2.c
SRCS += editor/player.c
SRCS += editor/portal.c
SRCS += editor/portal_part2.c
SRCS += editor/portal_utils.c
SRCS += editor/map_creation.c
SRCS += editor/map_creation_part2.c
SRCS += editor/map_creation_utils.c
SRCS += editor/vertex.c
SRCS += editor/sector.c
SRCS += editor/sector_part2.c
SRCS += editor/sector_check.c
SRCS += editor/sector_utils.c
SRCS += editor/effector.c
SRCS += texture/texture.c
SRCS += texture/texture_tools.c
SRCS += settings/settings_click.c
SRCS += settings/settings_click_tools.c
SRCS += settings/resize_window.c
SRCS += settings/settings_tools.c
SRCS += settings/settings_keyboard.c
SRCS += settings/draw_arrow_setting.c
SRCS += settings/draw_on_off_setting.c
SRCS += settings/draw_selector_setting.c
#------------------------------ OPERATING SYSTEM ------------------------------#
# Some changes have to be done depending on which OS we are currently
# dealing with. Darwin is for macOS else would include at least Linux.
ifeq ($(UNAME), Darwin)
AO = libao.dylib
SDL = libsdl2.a
TTF = libsdl2_ttf.a
CONFIG = ./configure --prefix
LAO_DIR = $(SRCS_AO)/OSX_lib/lib/
LSDL_DIR = $(HOME)/.brew/Cellar/sdl2/2.0.10/lib
LSND_DIR = $(SRCS_SND)/OSX_lib/lib/
LTTF_DIR = $(HOME)/.brew/Cellar/sdl2_ttf/2.0.15/lib
INCS_DIR += $(SRCS_AO)/include/ao
INCS_DIR += $(HOME)/.brew/Cellar/sdl2/2.0.10/include/SDL2
INCS_DIR += $(SRCS_SND)/OSX_lib/include
INCS_DIR += $(HOME)/.brew/Cellar/sdl2_ttf/2.0.15/include/SDL2
else
AO = libao.so
SDL = libSDL2.a
TTF = libSDL2_ttf.a
L_LIBS = /usr/local/lib
L_INCS = /usr/local/include
URL_SDL = https://www.libsdl.org/release/SDL2-2.0.10.tar.gz
URL_TTF = https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz
SRCS_SDL = SDL2-2.0.10
SRCS_TTF = SDL2_ttf-2.0.15
LAO_DIR = $(L_LIBS)
LSDL_DIR = $(L_LIBS)
LSND_DIR = $(L_LIBS)
LTTF_DIR = $(L_LIBS)
INCS_DIR += $(L_INCS)
INCS_DIR += $(L_INCS)/ao
INCS_DIR += $(L_INCS)/SDL2
endif
#-------------------------------- MISCELANEOUS --------------------------------#
# Some tricks in order to get the makefile doing his job.
D_SRCS = $(addsuffix /, $(SRCS_DIR))
D_OBJS = $(addsuffix /, $(OBJS_DIR))
C_OBJS = $(addprefix $(D_OBJS), $(OBJS))
C_INCS = $(foreach include, $(INCS_DIR), -I$(include))
C_SUBDIRS = $(foreach dir, $(OBJS_SUBDIRS), $(D_OBJS)$(dir))
#--------------------------------- COMPILATION --------------------------------#
# How files should be compiled.
CC = gcc
OBJS = $(SRCS:.c=.o)
# Linked libraries at compile time.
LIBS := -L$(LSDL_DIR) -lSDL2
LIBS += -L$(LTTF_DIR) -lSDL2_ttf
LIBS += -L$(LBMP_DIR) -lbmp
LIBS += -L$(LFT_DIR) -lft
LIBS += -L$(LSND_DIR) -lsndfile
LIBS += -L$(LAO_DIR) -lao
LIBS += -lm
LIBS += -lpthread
# Compilation flags.
CFLAGS = $(C_INCS) -Wall -Wextra -Werror
#------------------------------------ RULES -----------------------------------#
# Redefinition of the implicit compilation rule to prompt some informations.
$(D_OBJS)%.o: $(D_SRCS)%.c $(INCS)
@echo "$(YELLOW) - Compiling :$(RESET)" $<
@$(CC) $(CFLAGS) -c $< -o $@
# Implicit make rule simply using dependancies to compile our project.
all: $(OBJS_DIR) $(C_SUBDIRS) $(NAME)
$(NAME): $(LSDL) $(LTTF) $(LSND) $(LAO) $(LFT) $(LBMP) $(C_OBJS)
@echo "$(YELLOW)\n - Building $(RESET)$(NAME) $(YELLOW)...\n$(RESET)"
@$(CC) $(CFLAGS) -o $(NAME) $(C_OBJS) $(LIBS)
@echo "$(GREEN)*** Project $(NAME) successfully compiled ***\n$(RESET)"
# Libraries installation using brew or curl without prompting anything
# on standard output.
$(LAO):
@echo "$(GREEN)*** Installing library $(AO) ... ***\n$(RESET)"
@if [ $(UNAME) = Darwin ]; then \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_AO) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
echo "$(GREEN)*** Configure library ... ***\n$(RESET)"; \
cd $(SRCS_AO); mkdir -p OSX_lib; \
$(CONFIG) $(ABSDIR)/$(SRCS_AO)/OSX_lib > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
make -j > /dev/null 2>&1 && make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(AO) successfully compiled ***\n$(RESET)"; \
elif [ ! -d "$(SRCS_AO)" ]; then \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_AO) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
echo "$(GREEN)*** Configure library ... ***\n$(RESET)"; \
cd $(SRCS_AO); ./configure > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
sudo make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(AO) successfully compiled ***\n$(RESET)"; \
fi
$(LSDL):
@echo "$(GREEN)*** Installing library $(SDL) ... ***\n$(RESET)"
@if [ $(UNAME) = Darwin ]; then \
brew install sdl2 > /dev/null 2>&1; \
elif [ ! -d "$(SRCS_SDL)" ]; then \
sudo apt-get install curl -y > /dev/null 2>&1; \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_SDL) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
echo "$(GREEN)*** Configure library ... ***\n$(RESET)"; \
cd $(SRCS_SDL); ./configure > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
sudo make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(SDL) successfully compiled ***\n$(RESET)"; \
fi
$(LSND):
@echo "$(GREEN)*** Installing library $(SND) ... ***\n$(RESET)"
@if [ $(UNAME) = Darwin ]; then \
brew install curl autoconf autogen automake flac libogg libtool \
libvorbis libopus pkg-config > /dev/null 2>&1; \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_SND) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
echo "$(GREEN)*** Configure library ... ***\n$(RESET)"; \
cd $(SRCS_SND); mkdir -p OSX_lib; \
$(CONFIG) $(ABSDIR)/$(SRCS_SND)/OSX_lib > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
make -j > /dev/null 2>&1 && make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(SND) successfully compiled ***\n$(RESET)"; \
elif [ ! -d "$(SRCS_SND)" ]; then \
sudo apt-get install autoconf autogen automake build-essential \
libasound2-dev libflac-dev libogg-dev libtool libvorbis-dev libopus-dev \
pkg-config python -y > /dev/null 2>&1; \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_SND) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
cd $(SRCS_SND); ./configure > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
sudo make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(SND) successfully compiled ***\n$(RESET)"; \
fi
$(LTTF):
@echo "$(GREEN)*** Installing library $(TTF) ... ***\n$(RESET)"
@if [ $(UNAME) = Darwin ]; then \
brew install sdl2_ttf > /dev/null 2>&1; \
elif [ ! -d "$(SRCS_TTF)" ]; then \
sudo apt-get install libfreetype6-dev -y > /dev/null 2>&1; \
echo "$(GREEN)*** Curl sources ... ***\n$(RESET)"; \
$(CURL) $(URL_TTF) > /dev/null 2>&1; \
echo "$(GREEN)*** Unpacking sources ... ***\n$(RESET)"; \
$(TAR) archive.tar; $(RM) archive.tar; \
echo "$(GREEN)*** Configure library ... ***\n$(RESET)"; \
cd $(SRCS_TTF); ./configure > /dev/null 2>&1; \
echo "$(GREEN)*** Compile library ... ***\n$(RESET)"; \
sudo make install -j > /dev/null 2>&1; \
echo "$(GREEN)*** $(TTF) successfully compiled ***\n$(RESET)"; \
fi
# Libraries installion using their own Makefile.
$(LFT):
@make -sC $(LFT_DIR) -j
$(LBMP):
@make -sC $(LBMP_DIR) -j
# Rules used to create folders if they aren't already existing.
$(OBJS_DIR):
@mkdir -p $(OBJS_DIR)
$(C_SUBDIRS):
@mkdir -p $(C_SUBDIRS)
# Deleting all .o files.
clean:
@make -sC $(LFT_DIR) clean
@make -sC $(LBMP_DIR) clean
@echo "$(GREEN)*** Deleting all object from $(NAME) ... ***\n$(RESET)"
@$(RM) $(C_OBJS)
# Deleting all executables and libraries after cleaning up all .o files.
fclean: clean
@make -sC $(LFT_DIR) fclean
@make -sC $(LBMP_DIR) fclean
@echo "$(GREEN)*** Deleting executable file from $(NAME) ... ***\n$(RESET)"
@$(RM) $(NAME)
@if [ -f "$(LAO)" ]; then \
echo "$(GREEN)*** Deleting library $(AO) ... ***\n$(RESET)"; \
if [ $(UNAME) = Darwin ]; then \
$(RM) $(SRCS_AO); \
fi; \
fi
@if [ -f "$(LSND)" ]; then \
echo "$(GREEN)*** Deleting library $(SND) ... ***\n$(RESET)"; \
if [ $(UNAME) = Darwin ]; then \
$(RM) $(SRCS_SND); \
fi; \
fi
@if [ -f "$(LTTF)" ]; then \
echo "$(GREEN)*** Deleting library $(TTF) ... ***\n$(RESET)"; \
if [ $(UNAME) = Darwin ]; then \
brew uninstall sdl2_ttf > /dev/null 2>&1; \
fi; \
fi
@if [ -f "$(LSDL)" ]; then \
echo "$(GREEN)*** Deleting library $(SDL) ... ***\n$(RESET)"; \
if [ $(UNAME) = Darwin ]; then \
brew uninstall --ignore-dependencies sdl2 > /dev/null 2>&1; \
fi; \
fi
@if [ $(UNAME) = Linux ]; then \
if [ -d $(SRCS_AO) ]; then \
sudo $(RM) $(SRCS_AO); \
fi; \
if [ -d $(SRCS_SDL) ]; then \
sudo $(RM) $(SRCS_SDL); \
fi; \
if [ -d $(SRCS_SND) ]; then \
sudo $(RM) $(SRCS_SND); \
fi; \
if [ -d $(SRCS_TTF) ]; then \
sudo $(RM) $(SRCS_TTF); \
fi; \
if [ -f $(LAO) ]; then \
sudo $(RM) $(L_LIBS)/libao* $(L_LIBS)/ao $(L_LIBS)/ckport \
$(L_INCS)/ao; \
fi; \
if [ -f $(LSDL) ]; then \
sudo $(RM) $(L_LIBS)/libSDL2* $(L_INCS)/SDL2; \
fi; \
if [ -f $(LSND) ]; then \
sudo $(RM) $(L_LIBS)/libsndfile* $(L_INCS)/sndfile*; \
fi; \
if [ -f $(LTTF) ]; then \
sudo $(RM) $(L_LIBS)/libSDL2* $(L_INCS)/SDL2; \
fi; \
fi
# Re-build libs.
re-libs: $(OBJS_DIR) $(C_SUBDIRS) $(C_OBJS)
@make -sC $(LFT_DIR) re
@make -sC $(LBMP_DIR) re
@echo "$(YELLOW) - Building $(RESET)$(NAME) $(YELLOW)...\n$(RESET)"
@$(CC) $(CFLAGS) -o $(NAME) $(C_OBJS) $(LIBS)
@echo "$(GREEN)*** Project $(NAME) successfully compiled ***\n$(RESET)"
# Re-compile everything.
re: fclean all
# Avoid unexpected behaviour when regular files get the same name
# as the following variables.
.PHONY: all clean fclean re