-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (81 loc) · 2.84 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
NAME = solong
CC = gcc
CFLAGS = -Wall -Werror -Wextra -Iheaders
PRINTF_A = archives/libftprintf.a
OBJ_DEST = objects
HEADER_DEST = headers
ARCHIVE_DEST = archives
PRINTF = $(OBJ_DEST) $(HEADER_DEST) $(ARCHIVE_DEST)
OBJS = $(SRCS:srcs/%.c=objects/%.o)
GNL = gnl
MLX = headers/mlx.h
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
MLX_FLAGS = -Lmlx -lmlx_Linux -L/usr/lib -Imlx -lXext -lX11 -lm -lz
else
MLX_FLAGS = -Imlx -Lmlx -lmlx -framework OpenGL -framework AppKit
endif
RM = rm -f
SRCS = srcs/count.c srcs/enemy.c srcs/error.c srcs/exit.c srcs/images.c \
srcs/loop.c srcs/map_error.c srcs/map.c srcs/movement.c srcs/initilise.c
CHECKER = tester/checker.c
GET_NEXT_LINE = gnl/get_next_line.c -D BUFFER_SIZE=100
REMOVE_MESSAGE = echo "removing object files"
REMOVE_ARCHIVE = echo "removing archives and application"
COMPILE_PRINTF = echo "compiling printf archive..."
COMPILE_SOLONG = echo "compiling solong application"
COMPILE_COMPLETE = echo "Ready! To play the game:\n./solong maps/<map name>"
all: $(NAME)
$(NAME): $(GNL) $(PRINTF) $(MLX) $(OBJS)
@if [ $(MLX) ]; then \
$(COMPILE_SOLONG); \
$(CC) $(CFLAGS) $(OBJS) $(PRINTF_A) $(MLX_FLAGS) $(GET_NEXT_LINE) -o $(NAME) >/dev/null; \
$(COMPILE_COMPLETE); \
fi
bonus: all
$(GNL):
@if [ ! -d "gnl/" ]; then\
printf "get_next_line dependency needed. Download now? [y/N]" \
&& read ans && [ $${ans:-N} = y ] \
&& git clone https://github.com/t0mmusic/get_next_line.git gnl; \
fi
@cp -r gnl/get_next_line.h $(HEADER_DEST)
$(PRINTF):
@$(COMPILE_PRINTF)
@if [ ! -d "printf/" ]; then\
printf "printf dependency needed. Download now? [y/N]" \
&& read ans && [ $${ans:-N} = y ] \
&& git clone https://github.com/t0mmusic/ft_printf.git printf; \
fi
@$(MAKE) bonus -C ./printf --no-print-directory
@cp -r printf/$(ARCHIVE_DEST) $(ARCHIVE_DEST)
@cp -r printf/$(OBJ_DEST) $(OBJ_DEST)
@cp -r printf/$(HEADER_DEST)/. $(HEADER_DEST)
$(MLX):
@if [ $(UNAME) != Linux ]; then \
printf "MacOS mlx repository must be downloaded separately.\n";\
fi
@if [ ! -d "mlx/" ]; then\
printf "mlx dependency needed. Download now? [y/N]" \
&& read ans && [ $${ans:-N} = y ] \
&& git clone https://github.com/42Paris/minilibx-linux.git mlx; \
cd mlx && bash configure;\
cd .. && cp -r mlx/mlx.h $(HEADER_DEST); \
fi
objects/%.o: srcs/%.c
@if [ $(MLX) ]; then \
$(CC) $(CFLAGS) $(MLX_LINUX_FLAGS) -c $< -o $@; \
printf "Linked source: %s into object: %s\n" $< $@; \
fi
clean:
@$(REMOVE_MESSAGE)
@$(MAKE) clean -C ./printf >/dev/null
@$(MAKE) clean -C ./printf/libft >/dev/null
rm -rf $(OBJ_DEST) $(ARCHIVE_DEST)
fclean: clean
@$(REMOVE_ARCHIVE)
@$(MAKE) fclean -C ./printf >/dev/null
@$(MAKE) clean -C ./printf/libft >/dev/null
@$(RM) $(NAME) >/dev/null
re: fclean all
.PHONY: all clean fclean bonus re