build: adding the project's makefile

This commit is contained in:
Raphael 2026-03-23 15:00:39 +01:00
parent ce72da6106
commit 4a5a8bcae9
No known key found for this signature in database

152
Makefile Normal file
View file

@ -0,0 +1,152 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2026/03/23 14:53:55 by rparodi ### ########.fr #
# #
# **************************************************************************** #
# Variables
# Name
NAME = ft_ping
# Commands
CC ?= cc
RM = rm -rf
# Flags
CFLAGS = -Werror -Wall -Wextra
INC_DIR = ./parsing/includes
CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP
# Paths
LIBFT_DIR = ./libft
MLX_DIR = ./minilibx-linux
# Library flags
LDFLAGS = -L./build -lparsing
SRC = ./sources/ping.c
# Objects
OBJDIRNAME = ./build
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.c=.o))
# Colors
GREEN = \033[32m
GREY = \033[0;90m
RED = \033[0;31m
GOLD = \033[38;5;220m
END = \033[0m
export CC CFLAGS CPPFLAGS INC_DIR OBJDIRNAME MAKE RM
# Rules
build/parsing.a:
@make --no-print-directory -f ./parsing/parsing.mk
# All (make all)
all: header build/parsing.a $(NAME) footer
# Clean (make clean)
clean:
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'
@printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n'
@$(RM) $(OBJDIRNAME)
# Clean (make fclean)
fclean: clean
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
@$(RM) $(NAME)
@echo ""
# Restart (make re)
re: header fclean all
# Dependences for all
$(NAME): $(OBJ)
@mkdir -p $(OBJDIRNAME)
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
@$(CC) $(CFLAGS) $(CPPFLAGS) $(OBJ) $(LDFLAGS) -o $(NAME)
# Creating the objects
$(OBJDIRNAME)/%.o: %.c
@mkdir -p $(dir $@)
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
@$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
bonus: CFLAGS += -D BONUS=1
bonus: re
# Header
header:
@printf '\n\n'
@printf '$(GOLD) ******* ****** ******* $(END)\n'
@printf '$(GOLD) ****** *** ******* $(END)\n'
@printf '$(GOLD) ******* * ******* $(END)\n'
@printf '$(GOLD) ****** ******* $(END)\n'
@printf '$(GOLD) ******* ******* $(END)\n'
@printf '$(GOLD) ******************* ******* * $(END)\n'
@printf '$(GOLD) ******************* ******* *** $(END)\n'
@printf '$(GOLD) ****** ******* ****** $(END)\n'
@printf '$(GOLD) ****** $(END)\n'
@printf '$(GOLD) ****** $(END)\n'
@printf '$(GREY) Made by glaruell & rparodi$(END)\n\n'
# Footer
footer:
@printf "\n"
@printf "$(GOLD) ,_ _,$(END)\n"
@printf "$(GOLD) | \\___//|$(END)\n"
@printf "$(GOLD) |=6 6=|$(END)\n"
@printf "$(GOLD) \\=._Y_.=/$(END)\n"
@printf "$(GOLD) ) \` ( ,$(END)\n"
@printf "$(GOLD) / \\ (('$(END)\n"
@printf "$(GOLD) | | ))$(END)\n"
@printf "$(GOLD) /| | | |\\_//$(END)\n"
@printf "$(GOLD) \\| |._.| |/-\`$(END)\n"
@printf "$(GOLD) '\"' '\"'$(END)\n"
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
debug: CPPFLAGS += -D DEBUG=1 -g
# debug: CFLAGS += -fsanitize=address
debug: re
tmux:
@tmux new-session -d -s $(NAME)
@tmux send-keys -t $(NAME):0 'vim' C-m
@tmux split-window -h -t $(NAME):0
@tmux resize-pane -t $(NAME):0.0 -x 70
@tmux split-window -v -p 30 -t $(NAME):0.1
@tmux send-keys -t $(NAME):0.2 'watch -n0.5 norminette ./parsing ./includes' C-m
@tmux new-window -t $(NAME):1 -n 'lazygit'
@tmux send-keys -t $(NAME):1 'lazygit' C-m
@tmux select-window -t $(NAME):0
@tmux attach-session -t $(NAME)
clangd:
@printf "CompileFlags:\n" > ./.clangd
@printf " Add:\n" >> ./.clangd
@printf " - \"-xc\"\n" >> ./.clangd
@for FLAG in $(CFLAGS); do \
printf " - \"$$FLAG\"\n" >> ./.clangd; \
done
@printf " - \"-I"$(shell pwd)"/\"\n" >> .clangd;
@for file in $(INC_DIR); do \
printf " - \"-I"$(shell pwd)"/"$$file"\"\n" >> .clangd; \
done
@printf "\n" >> ./.clangd
@printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n'
# Phony targets
.PHONY: all clean fclean re clangd debug tmux
-include $(OBJ:.o=.d)