-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (84 loc) · 2.44 KB
/
Copy pathMakefile
File metadata and controls
105 lines (84 loc) · 2.44 KB
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
# Library and Project names
NAME = so_long
BONUS = so_long_bonus
PRINTF_LIB = ft_printf
# Headers
INC = -I. -I$(PRINTF_LIB)
INC_LINUX = -I/usr/include
MLX_LINUX = -Imlx_linux
MLX_MAC = -Imlx
# Sources & Objects
SRCDIR = src
SRCS = so_long load_map append_map validate_map \
exit_game animate so_long_utils
MSRCS = init_game hook
BSRCS = init_game hook \
enemy score
SHARED_SCRS = $(addprefix $(SRCDIR)/, $(addsuffix .c, $(SRCS)))
SHARED_OBJS = $(SHARED_SCRS:.c=.o)
MAN_SRCS = $(addprefix $(SRCDIR)/, $(addsuffix .c, $(MSRCS)))
MAN_OBJS = $(MAN_SRCS:.c=.o)
BONUS_SCRS = $(addprefix $(SRCDIR)/, $(addsuffix _bonus.c, $(BSRCS)))
BONUS_OBJS = $(BONUS_SCRS:.c=.o)
# Compiler and Flags
CC = cc
FLAGS = -Wall -Werror -Wextra
SFLAGS = -fsanitize=address
# API Flags
LINUX_API = -Lmlx_linux -lmlx_Linux -L/usr/lib -lXext -lX11 -lm -lz
MAC_API = -Lmlx -lmlx -framework OpenGL -framework AppKit
# Library
FT_PRINTF = -L$(PRINTF_LIB) -lftprintf
# Detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
CFLAGS = $(INC) $(INC_LINUX) $(MLX_LINUX) -O3
API_OS = $(LINUX_API)
else ifeq ($(UNAME_S), Darwin)
CFLAGS = $(INC) $(MLX_MAC)
API_OS = $(MAC_API)
else
$(error Unsupported OS: $(UNAME_S))
endif
$(SRCDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(FLAGS) -g $(CFLAGS) -c $< -o $@
all: mlx_lib lib $(NAME)
bonus: mlx_lib lib $(BONUS)
mlx_lib:
@if [ "$(UNAME_S)" = "Linux" ]; then \
if [ ! -d "mlx_linux" ]; then \
git clone https://github.com/42Paris/minilibx-linux.git mlx_linux; \
$(MAKE) -s -C mlx_linux >/dev/null 2>&1; \
echo "--mlx_linux built--"; \
else \
$(MAKE) -s -C mlx_linux >/dev/null 2>&1; \
fi; \
else \
if [ ! -d "mlx" ]; then \
git clone https://github.com/dannywillems/minilibx-mac-osx mlx; \
$(MAKE) -s -C mlx >/dev/null 2>&1; \
echo "--mlx built--"; \
else \
$(MAKE) -s -C mlx >/dev/null 2>&1; \
fi; \
fi
lib:
@make -C $(PRINTF_LIB)
$(NAME): $(SHARED_OBJS) $(MAN_OBJS)
$(CC) $(FLAGS) $(SFLAGS) -g $^ $(FT_PRINTF) $(API_OS) -o $@
$(BONUS): $(SHARED_OBJS) $(BONUS_OBJS)
$(CC) $(FLAGS) $(SFLAGS) -g $^ $(FT_PRINTF) $(API_OS) -o $@
clean:
@if [ -d "mlx_linux" ]; then \
make clean -C mlx_linux >/dev/null 2>&1; \
fi
@if [ -d "mlx" ]; then \
make clean -C mlx >/dev/null 2>&1; \
fi
make -C $(PRINTF_LIB) clean
rm -f $(SHARED_OBJS) $(MAN_OBJS) $(BONUS_OBJS)
fclean: clean
make -C $(PRINTF_LIB) fclean
rm -f $(NAME) $(BONUS)
re: fclean all bonus
.PHONY: all clean fclean re bonus mlx_lib lib