# - - - - - - - - - - - - - - # name = value \ # variables names # value # - - - - - - - - - - - - - - # ! name is case sensitive SERVER = server CLIENT = client CC = gcc VPATH = srcs S_SRCS = server.c C_SRCS = client.c ODIR = ./builds S_OBJS = $(S_SRCS:%.c=$(ODIR)/%.o) C_OBJS = $(C_SRCS:%.c=$(ODIR)/%.o) DEPS = ./includes/minitalk.h \ ./libft/includes/libft.h IDIR = $(dir $(DEPS)) # $(dir PATH/TO/FILE) expands to "PATH/TO/" -> the directory of a file LDIR = ./libft _LIBS = libft.a LIBS = $(_LIBS:lib%.a=%) CFLAGS = $(IDIR:%=-I%) CFLAGS += -g3 -Wall -Wextra -Werror LFLAGS = -L./libft -lft # - - - - - - - - - - - - - - # target: prerequisites | $@ : target # rules to execute # recipe | $< : 1st prerequisite # - - - - - - - - - - - - - - # recipe | $^ : all prerequisites all: libft $(SERVER) $(CLIENT) libft: @echo "hello" make -C $(LDIR) $(SERVER): $(S_OBJS) $(DEPS) $(CC) $(CFLAGS) -o $@ $< $(LFLAGS) $(CLIENT): $(C_OBJS) $(DEPS) $(CC) $(CFLAGS) -o $@ $< $(LFLAGS) $(ODIR)/%.o: %.c | $(ODIR) $(CC) $(CFLAGS) -c -o $@ $< $(ODIR): mkdir $@ leaks: CFLAGS += -fsanitize=address leaks: clean $(NAME) # or: valgrind --leak-check=full --show-leak-kinds=all ./prgrm # or: valgrind --leak-check=full --leak-resolution=low --show-reachable=yes ./prgrm clean: /bin/rm -f $(S_OBJS) $(C_OBJS) fclean: clean /bin/rm -rf $(ODIR) /bin/rm -f $(SERVER) $(CLIENT) /bin/rm -rf a.out a.out.dSYM libfclean: make fclean -C $(LDIR) re: fclean all relib: libfclean re .PHONY: all clean fclean re gcc