-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (92 loc) · 4.02 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
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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: amarquez <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2017/06/20 10:10:12 by amarquez #+# #+# #
# Updated: 2017/07/14 10:10:49 by amarquez ### ########.fr #
# #
# **************************************************************************** #
# Compiler
CC = gcc
LINKER = gcc
# Flags
FLAGS = -Wall -Wextra -Werror -g3
# Project Directory
CWD = .
# Genereic File Structure
INCDIR = $(CWD)/inc
SRCDIR = $(CWD)/src
OBJDIR = $(CWD)/obj
# Server & Client directories
SERVER_DIR = server
CLIENT_DIR = client
# Include Files
INC := $(wildcard $(INCDIR)/*.h)
# Server & Client source Files
SERVER_SRC := $(wildcard $(SRCDIR)/$(SERVER_DIR)/*.c)
CLIENT_SRC := $(wildcard $(SRCDIR)/$(CLIENT_DIR)/*.c)
# Server & Client object Files
SERVER_OBJ := $(SERVER_SRC:$(SRCDIR)/$(SERVER_DIR)/%.c=$(OBJDIR)/$(SERVER_DIR)/%.o)
CLIENT_OBJ := $(CLIENT_SRC:$(SRCDIR)/$(CLIENT_DIR)/%.c=$(OBJDIR)/$(CLIENT_DIR)/%.o)
# libs dependencies
LIBFT = -L ./libft -lft
LIBFTP = -L ./libftp -lftp
LIBFT_H = -I libft
LIBFTP_H = -I libftp/inc
# Executabe name
SERVER = server
CLIENT = client
# OS for linking libraries (linux and os x different)
OS := $(shell uname)
ifneq ($(OS),Darwin)
LINK = $(LIBFTP) $(LIBFT)
endif
# Bin directory
BINDIR = .
##### NB: Check if directories exists before you try to use them
# rules begin:
all: $(OBJDIR) $(BINDIR)/$(SERVER) $(BINDIR)/$(CLIENT)
$(OBJDIR):
@echo "\033[0;31m[server]: \033[0m\033[0;36mCreating "$@" directory!\033[0m"
@mkdir -p $@/$(SERVER_DIR) $@/$(CLIENT_DIR)
@echo "\033[0;31m[server]: \033[0m\033[0;32mComplete!\033[0m"
$(BINDIR)/$(SERVER): $(SERVER_OBJ)
@echo "\033[0;31m[server]: \033[0m\033[0;36mLinking object files!\033[0m"
@$(LINKER) $(SERVER_OBJ) $(FLAGS) -o $@ $(LIBFTP) $(LIBFT) -I $(INCDIR) $(LIBFTP_H) $(LIBFT_H)
@echo "\033[0;31m[server]: \033[0m\033[0;32mLinking complete!\033[0m"
$(SERVER_OBJ): $(OBJDIR)/$(SERVER_DIR)/%.o : $(SRCDIR)/$(SERVER_DIR)/%.c
@make --silent -C libftp
@echo "\033[0;31m[server]: \033[0m\033[0;36mCompiling source file "$<"!\033[0m"
@$(CC) $(FLAGS) -c $< -o $@ $(LINK) -I $(INCDIR) $(LIBFTP_H) $(LIBFT_H)
@echo "\033[0;31m[server]: \033[0m\033[0;32mCompiled "$<" successfully!\033[0m"
$(BINDIR)/$(CLIENT): $(CLIENT_OBJ)
@echo "\033[0;33m[client]: \033[0m\033[0;36mLinking object files!\033[0m"
@$(LINKER) $(CLIENT_OBJ) $(FLAGS) -o $@ $(LIBFTP) $(LIBFT) -I $(INCDIR) $(LIBFTP_H) $(LIBFT_H)
@echo "\033[0;33m[client]: \033[0m\033[0;32mLinking complete!\033[0m"
$(CLIENT_OBJ): $(OBJDIR)/$(CLIENT_DIR)/%.o : $(SRCDIR)/$(CLIENT_DIR)/%.c
@make --silent -C libftp
@echo "\033[0;33m[client]: \033[0m\033[0;36mCompiling source file "$<"!\033[0m"
@$(CC) $(FLAGS) -c $< -o $@ $(LINK) -I $(INCDIR) $(LIBFTP_H) $(LIBFT_H)
@echo "\033[0;33m[client]: \033[0m\033[0;32mCompiled "$<" successfully!\033[0m"
.PHONY: clean
clean:
@make --silent clean -C libftp
@echo "\033[0;36mRemoving object files\033[0m"
@rm -f $(SERVER_OBJ) $(CLIENT_OBJ)
@echo "\033[0;32mCleanup complete\033[0m"
.PHONY: fclean
fclean: clean
@make --silent fclean -C libftp
@echo "\033[0;36mRemoving executables '$(BINDIR)/$(SERVER), $(BINDIR)/$(CLIENT)'\033[0m"
@rm -f $(BINDIR)/$(SERVER) $(BINDIR)/$(CLIENT)
@echo "\033[0;32mExecutable removed\033[0m"
.PHONY: re
re: fclean all
norm:
@echo "\033[0;31m[server]: \033[0m\033[0;36mnorming files!\033[0m"
@norminette $(SERVER_SRC)
@echo "\033[0;33m[client]: \033[0m\033[0;36mnorming files!\033[0m"
@norminette $(CLIENT_SRC)