-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
92 lines (72 loc) · 2.82 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: cwenz <cwenz@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/08/10 14:27:42 by cwenz #+# #+# #
# Updated: 2023/08/19 14:22:55 by cwenz ### ########.fr #
# #
# **************************************************************************** #
# Program name
CLIENT_NAME := client
SERVER_NAME := server
# Compiler flags
CC := cc
CFLAGS := -Wall -Werror -Wextra
INCLUDES := -I./includes
# Remove command
RM := rm -f
# Libraries
LIBFT_PATH := ./libraries/42c-library
LIBFT := $(LIBFT_PATH)/libft.a
LIBFT_MAKE := make -C $(LIBFT_PATH)
LIBFT_FCLEAN := make fclean -C $(LIBFT_PATH)
# Source file directories
CLIENT_DIR := ./src/client/
SERVER_DIR := ./src/server/
ERROR_DIR := ./src/error/
UTILS_DIR := ./src/utils/
# Source files
CLIENT_FILES := client.c
SERVER_FILES := server.c
ERROR_FILES := error.c
UTIL_FILES := server_utils.c client_utils.c
CLIENT_SRC += $(addprefix $(CLIENT_DIR), $(CLIENT_FILES))
SERVER_SRC += $(addprefix $(SERVER_DIR), $(SERVER_FILES))
SRC += $(addprefix $(ERROR_DIR), $(ERROR_FILES))
SRC += $(addprefix $(UTILS_DIR), $(UTIL_FILES))
# Object files
CLIENT_OBJ := $(CLIENT_SRC:.c=.o)
SERVER_OBJ := $(SERVER_SRC:.c=.o)
SRC_OBJ := $(SRC:.c=.o)
# Default makefile target
all: init-submodule $(LIBFT) $(SERVER_NAME) $(CLIENT_NAME)
$(LIBFT):
@$(LIBFT_MAKE)
$(CLIENT_NAME): $(CLIENT_OBJ) $(SRC_OBJ)
@$(CC) $(CFLAGS) $(INCLUDES) $(CLIENT_OBJ) $(SRC_OBJ) $(LIBFT) -o $(CLIENT_NAME)
@echo $(GREEN)"MINITALK: Linking $(CLIENT_NAME)"$(DEFAULT);
$(SERVER_NAME): $(SERVER_OBJ) $(SRC_OBJ)
@$(CC) $(CFLAGS) $(INCLUDES) $(SERVER_OBJ) $(SRC_OBJ) $(LIBFT) -o $(SERVER_NAME)
@echo $(GREEN)"MINITALK: Linking $(SERVER_NAME)"$(DEFAULT);
%.o: %.c
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
init-submodule:
@if [ -z "$(shell ls -A $(LIBFT_PATH))" ]; then \
git submodule init $(LIBFT_PATH); \
git submodule update $(LIBFT_PATH); \
fi
clean:
@$(RM) $(SRC_OBJ) $(CLIENT_OBJ) $(SERVER_OBJ)
fclean: clean
@$(LIBFT_FCLEAN)
@$(RM) $(SERVER_NAME) $(CLIENT_NAME)
@echo $(RED)"MINITALK: Removing executables and objects"$(DEFAULT);
re: fclean all
.PHONY: all init-submodule clean fclean re
# Colours to make it look nice :)
DEFAULT = "\033[39m"
GREEN = "\033[32m"
RED = "\033[31m"