# Program name NAME = rip # Compiler and flags CC = gcc CFLAGS = -Wall -Wextra -Werror # Source files SRCS = rip.c # Object files OBJS = $(SRCS:.c=.o) # Colors for output GREEN = \033[0;32m RED = \033[0;31m YELLOW = \033[0;33m NC = \033[0m # No Color # Default target all: $(NAME) # Build the executable $(NAME): $(OBJS) @echo "$(YELLOW)Linking $(NAME)...$(NC)" @$(CC) $(CFLAGS) $(OBJS) -o $(NAME) @echo "$(GREEN)โœ… $(NAME) created successfully!$(NC)" # Compile source files to object files %.o: %.c @echo "$(YELLOW)Compiling $<...$(NC)" @$(CC) $(CFLAGS) -c $< -o $@ # Clean object files clean: @echo "$(RED)๐Ÿงน Cleaning object files...$(NC)" @rm -f $(OBJS) @echo "$(GREEN)โœ… Object files cleaned!$(NC)" # Clean object files and executable fclean: clean @echo "$(RED)๐Ÿงน Cleaning executable...$(NC)" @rm -f $(NAME) @echo "$(GREEN)โœ… Everything cleaned!$(NC)" # Rebuild everything re: fclean all # Test the program with provided examples test: $(NAME) @echo "$(YELLOW)๐Ÿงช Running tests...$(NC)" @echo "$(YELLOW)Test 1: '(()'$(NC)" @./$(NAME) '(((' | cat -e @echo "$(YELLOW)Test 2: '((()()())())'$(NC)" @./$(NAME) '((()()())())' | cat -e @echo "$(YELLOW)Test 3: '()())()''$(NC)" @./$(NAME) '()())()' | cat -e @echo "$(YELLOW)Test 4: '(()(()('$(NC)" @./$(NAME) '(()(()(' | cat -e @echo "$(GREEN)โœ… All tests completed!$(NC)" # Check for memory leaks (requires valgrind) valgrind: $(NAME) @echo "$(YELLOW)๐Ÿ” Checking for memory leaks...$(NC)" @valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) '(()' @echo "$(GREEN)โœ… Memory check completed!$(NC)" # Show help help: @echo "$(GREEN)Available targets:$(NC)" @echo " $(YELLOW)all$(NC) - Build the program" @echo " $(YELLOW)clean$(NC) - Remove object files" @echo " $(YELLOW)fclean$(NC) - Remove object files and executable" @echo " $(YELLOW)re$(NC) - Rebuild everything (fclean + all)" @echo " $(YELLOW)test$(NC) - Run all test cases" @echo " $(YELLOW)valgrind$(NC) - Check for memory leaks" @echo " $(YELLOW)help$(NC) - Show this help message" # Declare phony targets .PHONY: all clean fclean re test valgrind help