Files
42_INT_05_minitalk/Makefile
2021-08-26 12:38:52 +02:00

74 lines
1.5 KiB
Makefile

# - - - - - - - - - - - - - - # 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
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$(LDIR) -l$(LIBS)
# - - - - - - - - - - - - - - # target: prerequisites | $@ : target
# rules to execute # recipe | $< : 1st prerequisite
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
all: libft $(SERVER) $(CLIENT)
libft:
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 $(NAME)
/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