aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 3db5516baf89024478816508f954bce366e7e147 (plain)
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
default: all

#==================================================================================================#
#-------------------------------------------- Shell -----------------------------------------------#
#==================================================================================================#
SHELL		:= /bin/sh
#==================================================================================================#
#-------------------------------------------- Directories -----------------------------------------#
#==================================================================================================#
INCS_DIR	= inc/
SRCS_DIR	= src/
OBJS_DIR	= obj/
LFT_DIR		= libft/
MLX_DIR		= minilibx/
#==================================================================================================#
#---------------------------------------------- Files ---------------------------------------------#
#==================================================================================================#
INCS		= cub3d.h
INCS		+= cub3d_structs.h
#--------------------------------------------------------------------------------------------------#
SRCS_NAME	 = main.c
SRCS_NAME	+= ft_init_lists.c
SRCS_NAME	+= ft_hooks_and_loops.c
SRCS_NAME	+= ft_key_events.c
SRCS_NAME	+= ft_click_close.c
SRCS_NAME	+= ft_exit.c
SRCS_NAME	+= ft_parse_map.c
SRCS_NAME	+= ft_select_get.c
SRCS_NAME	+= ft_get_screen_size.c
SRCS_NAME	+= ft_get_res.c
SRCS_NAME	+= ft_get_tex.c
SRCS_NAME	+= ft_get_sprite.c
SRCS_NAME	+= ft_get_colors.c
SRCS_NAME	+= ft_get_map.c
SRCS_NAME	+= ft_get_player_spawn.c
SRCS_NAME	+= ft_set_minimap_scale.c
SRCS_NAME	+= ft_check_missing.c
SRCS_NAME	+= ft_check_not_found.c
SRCS_NAME	+= ft_check_map_line.c
SRCS_NAME	+= ft_free_words.c
SRCS_NAME	+= ft_map_error.c
SRCS_NAME	+= ft_init_winlx.c
SRCS_NAME	+= ft_draw_square.c
SRCS_NAME	+= ft_draw_circle.c
SRCS_NAME	+= ft_draw_map.c
SRCS_NAME	+= ft_draw_scene.c
SRCS_NAME	+= ft_basic_keys.c
SRCS_NAME	+= ft_extra_keys.c
SRCS_NAME	+= ft_draw_verline.c
SRCS_NAME	+= ft_rgb_to_hex.c
SRCS_NAME	+= ft_raycasting.c
SRCS_NAME	+= ft_init_s_ray.c
SRCS_NAME	+= ft_init_map.c
SRCS_NAME	+= ft_tex_init.c
SRCS_NAME	+= ft_detect.c
SRCS_NAME	+= ft_check_ext.c
SRCS_NAME	+= ft_draw_textures.c
SRCS_NAME	+= ft_key_release.c
SRCS_NAME	+= ft_convert_keycode.c
SRCS_NAME	+= ft_key_loop.c
#--------------------------------------------------------------------------------------------------#
SRCS		= $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
OBJS		= $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS})
#--------------------------------------------------------------------------------------------------#
LFT_SRCS	= $(shell find libft/src -name "*.c")
#==================================================================================================#
#--------------------------------------------- UNIX -----------------------------------------------#
#==================================================================================================#
MKDIR		= mkdir -p
RM			= rm -rf
OS			= $(shell uname)
ifeq (${OS}, Darwin)
	SCR_SZE = $(shell osascript -e 'tell application "Finder" to get bounds of window of desktop' \
| tr ',' 'x' | tr -d '\n' | tr -d ' ' | cut -c 5-)
else
	SCR_SZE	= $(shell xdpyinfo | grep dimensions | awk '{print $$2}')
endif
#==================================================================================================#
#------------------------------------------ Compiler ----------------------------------------------#
#==================================================================================================#
DEBUG		= -glldb
FSANITIZE	= -fsanitize=address
#--------------------------------------------------------------------------------------------------#
CC			= clang
#--------------------------------------------------------------------------------------------------#
CFLAGS		 = -std=c89
CFLAGS		+= -Wall
CFLAGS		+= -Wextra
CFLAGS		+= -Werror
CFLAGS		+= -pedantic
#--------------------------------------------------------------------------------------------------#
ifdef ASAN
	CFLAGS	+= ${DEBUG}
	CFLAGS	+= ${FSANITIZE}
endif
#--------------------------------------------------------------------------------------------------#
CDEFS		 = -DFT_SCR_SIZE=\"${SCR_SZE}\"
ifneq (${OS}, Darwin)
	CDEFS	+= -DFT_W_KEY=119
	CDEFS	+= -DFT_A_KEY=97
	CDEFS	+= -DFT_S_KEY=115
	CDEFS	+= -DFT_D_KEY=100
	CDEFS	+= -DFT_F1_KEY=65470
	CDEFS	+= -DFT_TAB_KEY=65289
	CDEFS	+= -DFT_L_ARR_KEY=65361
	CDEFS	+= -DFT_R_ARR_KEY=65363
	CDEFS	+= -DFT_ESC_KEY=65307
endif
#--------------------------------------------------------------------------------------------------#
ifeq (${OS}, Darwin)
	NAME	= Cub3D
else
	NAME	= a.out
endif
#==================================================================================================#
#------------------------------------------ Rules -------------------------------------------------#
#==================================================================================================#
${OBJS_DIR}%.o:		${SRCS_DIR}%.c ${INCS_DIR}
	@${MKDIR} ${OBJS_DIR}
ifeq (${OS}, Darwin)
	${CC} -c ${CFLAGS} ${CDEFS} -I${LFT_DIR}${INCS_DIR} -I${MLX_DIR} -I${INCS_DIR} -o $@ $<
else
	${CC} -c ${CFLAGS} ${CDEFS} -I${LFT_DIR}${INCS_DIR} -I${INCS_DIR} -o $@ $<
endif
#--------------------------------------------------------------------------------------------------#
${NAME}:	${OBJS} ${LFT_SRCS} ${LFT_DIR}${INCS_DIR}libft.h
ifeq (${OS}, Darwin)
	${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -L${MLX_DIR} -lft -lmlx -lm -framework OpenGL \
-framework AppKit
else
	${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -lft -lX11 -lXext -lmlx -lm -lbsd
endif
#--------------------------------------------------------------------------------------------------#
all:
ifeq (${OS}, Darwin)
	@$(MAKE) --no-print-directory -C ${MLX_DIR} all
endif
ifdef ASAN
	@$(MAKE) --no-print-directory -C ${LFT_DIR} all ASAN=1
else
	@$(MAKE) --no-print-directory -C ${LFT_DIR} all
endif
	@$(MAKE) ${NAME}
#--------------------------------------------------------------------------------------------------#
clean: 
ifeq (${OS}, Darwin)
	@$(MAKE) --no-print-directory -C ${MLX_DIR} clean
endif
	@$(MAKE) --no-print-directory -C ${LFT_DIR} clean
	${RM} ${OBJS_DIR}
#--------------------------------------------------------------------------------------------------#
fclean: clean
	@$(MAKE) --no-print-directory -C ${LFT_DIR} fclean
	${RM} ${NAME}
	${RM} ${NAME}.dSYM
#--------------------------------------------------------------------------------------------------#
re: fclean all
#--------------------------------------------------------------------------------------------------#
run: all
	@./${NAME} "map/map_one.cub"
#--------------------------------------------------------------------------------------------------#
.PHONY:	all clean clean fclean re run default
#============================================== EOF ===============================================#