build(make): adding the makefile of the project

This commit is contained in:
Raphael 2025-12-06 19:58:47 +01:00
parent 6ed34984e0
commit a605101d97
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
# By: rparodi <marvin@42.fr> +#+ +:+ +#+ # # By: rparodi <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2025/11/30 20:14:15 by rparodi ### ########.fr # # Updated: 2025/12/06 19:58:12 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -14,7 +14,7 @@
# Name # Name
NAME = libasm.a NAME = libasm.a
TEST_OUTPUT = test TEST_OUTPUT = result
# ASM Variables # ASM Variables
AS ?= nasm AS ?= nasm
@ -27,6 +27,7 @@ RM = rm -rf
CFLAGS = -Werror -Wextra -Wall CFLAGS = -Werror -Wextra -Wall
TEST_FILE = test/main.c TEST_FILE = test/main.c
INC_DIR = includes INC_DIR = includes
LDFLAGS = -L $(shell pwd)/build/
CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP
# Objects # Objects
@ -34,7 +35,8 @@ OBJDIRNAME = ./build
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.s=.o)) OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.s=.o))
OBJ_BONUS = $(addprefix $(OBJDIRNAME)/,$(SRC_BONUS:.s=.o)) OBJ_BONUS = $(addprefix $(OBJDIRNAME)/,$(SRC_BONUS:.s=.o))
SRC = ft_write.s SRC = src/ft_strlen.s \
src/ft_strcmp.s
# Colors # Colors
GREEN = \033[32m GREEN = \033[32m
@ -62,22 +64,29 @@ clean:
fclean: clean fclean: clean
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
@$(RM) $(NAME) @$(RM) $(NAME)
@$(RM) $(TEST_OUTPUT)
@echo "" @echo ""
re: header fclean all re: header fclean all
$(NAME): $(OBJ) $(NAME): $(OBJ)
@mkdir -p $(OBJDIRNAME) @mkdir -p $(OBJDIRNAME)
@ar rc $(NAME) $(OBJ) @ar rc $(OBJDIRNAME)/$(NAME) $(OBJ)
@ranlib $(NAME)
$(OBJDIRNAME)/%.o: %.s $(OBJDIRNAME)/%.o: %.s
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
@$(AS) $(ASFLAGS) -o $@ $< @$(AS) $(ASFLAGS) -o $@ $<
test: $(NAME) test: header $(NAME) run_compile footer
$(CC) $(CFLAGS) $(LDFLAGS) -lasm $(TEST_FILE) -o $(test-lib)
run: test
test_compile:
@printf '$(GREY) Start $(END)$(GREEN)Testing on $(TEST_OUTPUT)$(END)\n'
@$(CC) $(CFLAGS) $(CPPFLAGS) $(TEST_FILE) -o $(TEST_OUTPUT) ./build/libasm.a
@echo ""
@./result
header: header:
@clear @clear
@ -108,5 +117,20 @@ footer:
@printf "$(GOLD) '\"' '\"'$(END)\n" @printf "$(GOLD) '\"' '\"'$(END)\n"
@printf ' $(GREY)The compilation is$(END) $(GOLD)finished$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' @printf ' $(GREY)The compilation is$(END) $(GOLD)finished$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
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 # Phony
.PHONY: all bonus clean fclean re footer header .PHONY: all bonus clean fclean re footer header test run test_compile clangd