aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 21e0f3fc3434fcc613e65363174e0effaa5c5113 (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
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
#------------------------------------------------------------------------------#
SRCS_NAME	 = main.c
SRCS_NAME	+= ft_init_lists.c
SRCS_NAME	+= ft_key_events.c
SRCS_NAME	+= ft_click_close.c
SRCS_NAME	+= ft_exit.c
SRCS_NAME	+= ft_drawsquare.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_map_line.c
SRCS_NAME	+= ft_free_words.c
SRCS_NAME	+= ft_map_error.c
SRCS_NAME	+= ft_init_winlx.c
SRCS_NAME	+= ft_drawmap.c
SRCS_NAME	+= ft_print_list.c
SRCS_NAME	+= ft_rgb_to_hex.c
#------------------------------------------------------------------------------#
SRCS		= $(addprefix ${SRCS_DIR},${SRCS_NAME})
#------------------------------------------------------------------------------#
OBJS		= $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS})
#==============================================================================#
#--------------------------------- 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 ------------------------------------#
#==============================================================================#
CC			= clang
CFLAGS		= -std=c89
CFLAGS		+= -Wall
CFLAGS		+= -Wextra
CFLAGS		+= -Werror
CFLAGS		+= -pedantic
CFLAGS		+= -DFT_SCR_SIZE=\"${SCR_SZE}\"
ifdef ASAN
	CFLAGS	+= ${DEBUG}
	CFLAGS	+= ${FSANITIZE}
endif
#------------------------------------------------------------------------------#
DEBUG		= -glldb
FSANITIZE	= -fsanitize=address
#------------------------------------------------------------------------------#
ifeq (${OS}, Darwin)
	NAME	= cub3d
else
	NAME	= a.out
endif
#==============================================================================#
#--------------------------------- Rules --------------------------------------#
#==============================================================================#
${OBJS_DIR}%.o:		${SRCS_DIR}%.c ${INCS_DIR}${INCS}
	@${MKDIR} ${OBJS_DIR}
ifeq (${OS}, Darwin)
	${CC} -c ${CFLAGS} -I${LFT_DIR}${INCS_DIR} -I${MLX_DIR} -I${INCS_DIR} -o $@ $<
else
	${CC} -c ${CFLAGS} -I${LFT_DIR}${INCS_DIR} -I${INCS_DIR} \
-DFT_W_KEY=119 -DFT_A_KEY=97 -DFT_S_KEY=115 -DFT_D_KEY=100 -DFT_ESC_KEY=65307 \
-o $@ $<
endif
#------------------------------------------------------------------------------#
${NAME}:	${OBJS}
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
endif
#------------------------------------------------------------------------------#
all:
	@printf "%s\n" ${SCR_SZE}
	@printf "%s\n" ${CFLAGS}
	@exit

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 =====================================#