-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (56 loc) · 1.77 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
# Manual for Makefile
# https://www.gnu.org/software/make/manual/html_node/index.html
SERVER = server
CLIENT = client
SRC_SERV = server.c
SRC_CLNT = client.c
HEADER = minitalk.h
SRCDIR = ./
OBJDIR = ./obj/
OBJ_SERV = $(addprefix $(OBJDIR), $(notdir $(SRC_SERV:.c=.o)))
OBJ_CLNT = $(addprefix $(OBJDIR), $(notdir $(SRC_CLNT:.c=.o)))
OBJ_UTIL = $(addprefix $(OBJDIR), $(notdir $(SRC_UTIL:.c=.o)))
D_FILES += $(addprefix $(OBJDIR), $(notdir $(SRC_SERV:.c=.d)))
D_FILES += $(addprefix $(OBJDIR), $(notdir $(SRC_CLNT:.c=.d)))
D_FILES += $(addprefix $(OBJDIR), $(notdir $(SRC_UTIL:.c=.d)))
CC = gcc -Wall -Werror -Wextra
DEBUG = -g
OPTIMIZATION = -O2
LIB += -lft
LIBPATH += -L./libraries/libft/
LIBINC += -I./libraries/libft/
all: $(SERVER) $(CLIENT)
# translation of assembly language code into machine code
# -c, stops after assembly stage
# -MD lists both system header files and user header files, dependencies
# -MMD lists only user header files, dependencies
# $< the first prerequisite (usually a source file) main.c (dependency %.c)
# $@ is the name of the target being generated main.o (target %.o)
$(OBJDIR)%.o: $(SRCDIR)%.c $(HEADER) | obj
$(CC) $(DEBUG) $(LIBINC) -c $< -o $@ -MMD
# linking stage
$(SERVER): $(OBJ_SERV)
make -C ./libraries/libft/
$(CC) $(OBJ_SERV) $(LIBPATH) $(LIB) $(LIBINC) -o $(SERVER)
$(CLIENT): $(OBJ_CLNT)
make -C ./libraries/libft/
$(CC) $(OBJ_CLNT) $(LIBPATH) $(LIB) $(LIBINC) -o $(CLIENT)
obj:
mkdir -p $(OBJDIR)
include $(wildcard $(D_FILES))
bonus: all
norm:
norminette $(SRC)
# rule for the cleaning
clean:
make clean -C ./libraries/libft/
rm -rf $(OBJDIR)
fclean:
make fclean -C ./libraries/libft/
rm -rf $(OBJDIR)
rm -f $(SERVER)
rm -f $(CLIENT)
# rule for rebuild a project
re: fclean all
# directory exceptions
.PHONY: all clean fclean norm re bonus