aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 32fc61457ebc2ca72f603642a64bf44fa2870a80 (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
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
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_defines.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_map_dims.c
SRCS_NAME	+= ft_get_tex_nl.c
SRCS_NAME	+= ft_get_tex_extra.c
SRCS_NAME	+= ft_get_path_nl.c
SRCS_NAME	+= ft_get_nlvl_pos.c
SRCS_NAME	+= ft_get_skybox.c
SRCS_NAME	+= ft_get_player_spawn.c
SRCS_NAME	+= ft_get_music.c
SRCS_NAME	+= ft_get_darkness.c
SRCS_NAME	+= ft_get_traps.c
SRCS_NAME	+= ft_get_sprite_spawns.c
SRCS_NAME	+= ft_get_topsp.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_check_map_surrounds.c
SRCS_NAME	+= ft_free_words.c
SRCS_NAME	+= ft_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_draw_skybox.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_hex_to_rgb.c
SRCS_NAME	+= ft_darken_rgb.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_NAME	+= ft_draw_hud.c
SRCS_NAME	+= ft_music.c
SRCS_NAME	+= ft_draw_sprite.c
SRCS_NAME	+= ft_draw_sprite_extra.c
SRCS_NAME	+= ft_warp_level.c
SRCS_NAME	+= ft_save_to_bmp.c
SRCS_NAME	+= ft_treat_args.c
SRCS_NAME	+= ft_init_funptr.c
SRCS_NAME	+= ft_init_bmp.c
SRCS_NAME	+= ft_floor_cast.c
SRCS_NAME	+= ft_floor_cast_inits.c
SRCS_NAME	+= ft_suffer_animation.c
SRCS_NAME	+= ft_draw_traps.c
SRCS_NAME	+= ft_draw_traps_extra.c
SRCS_NAME	+= ft_draw_life_bar.c
SRCS_NAME	+= ft_del_extra_sprites.c
SRCS_NAME	+= ft_init_sfx.c
SRCS_NAME	+= ft_sfx_trap.c
SRCS_NAME	+= ft_sfx_death.c
SRCS_NAME	+= ft_sfx_footstep.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
MV			= mv
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
	USER	= $(shell w | grep tty7 | awk '{print $$1}')
	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		 = -D_POSIX_C_SOURCE
CDEFS		 += -DFT_SCR_SIZE=\"${SCR_SZE}\"
ifeq (${OS}, Darwin)
	CDEFS	+= -DFT_OS=1
else
	CDEFS	+= -DFT_OS=2
endif
#--------------------------------------------------------------------------------------------------#
NAME		= Cub3D
#==================================================================================================#
#------------------------------------------ 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)
	@$(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
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: ${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 ===============================================#