|
1 | 1 | NAME = pipex |
| 2 | +LIB = libft |
2 | 3 |
|
| 4 | +# Source files |
3 | 5 | SRC = source/main.c source/pipex.c source/path.c source/child.c |
4 | | - |
5 | 6 | OBJ = $(SRC:.c=.o) |
6 | | -#-fsanitize=address |
7 | | -FLAGS = -Wall -Wextra -Werror |
8 | 7 |
|
9 | | -LIB = libft |
| 8 | +# Compiler flags |
| 9 | +CFLAGS = -Wall -Wextra -Werror |
| 10 | +DEBUG_FLAGS = -g3 -fsanitize=address |
| 11 | + |
| 12 | +# Test files |
| 13 | +TEST_DIR = tests |
| 14 | +BASIC_TEST = basic_test.sh |
| 15 | +MULTI_TEST = multi_pipe_test.sh |
| 16 | +HERE_DOC_TEST = here_doc_test.sh |
10 | 17 |
|
11 | | -all: ${NAME} |
| 18 | +# Colors for output |
| 19 | +GREEN = \033[0;32m |
| 20 | +YELLOW = \033[1;33m |
| 21 | +RED = \033[0;31m |
| 22 | +NC = \033[0m # No Color |
12 | 23 |
|
13 | | -${NAME}: ${OBJ} |
14 | | - make -C $(LIB) |
15 | | - @gcc $(FLAGS) $(OBJ) -o $(NAME) $(LIB)/libft.a |
| 24 | +.PHONY: all clean fclean re debug test help |
16 | 25 |
|
17 | | -#$(OBJ): $(SRC) |
18 | | -# @gcc $(FLAGS) -c $(SRC) |
| 26 | +# Default target |
| 27 | +all: $(NAME) |
19 | 28 |
|
20 | | -exe: all |
21 | | - @./$(NAME) file1 "ls" "cat -e" file2 |
22 | | - < file1 ls | cat -e > file3 |
23 | | - cmp file2 file3 |
| 29 | +# Main executable |
| 30 | +$(NAME): $(OBJ) |
| 31 | + @make -C $(LIB) > /dev/null 2>&1 |
| 32 | + @gcc $(CFLAGS) $(OBJ) -o $(NAME) $(LIB)/libft.a |
| 33 | + @echo "$(GREEN)✓$(NC) $(NAME) compiled successfully!" |
24 | 34 |
|
25 | | -#cmd << LIMITER | cmd1 >> file |
| 35 | +# Object files |
| 36 | +source/%.o: source/%.c |
| 37 | + @gcc $(CFLAGS) -c $< -o $@ |
26 | 38 |
|
27 | | -exe2: all |
28 | | - @./$(NAME) file1 "ls" "wc -l" "cat -e" "cat -e" "cat -e" file2 |
29 | | - < file1 ls | wc -l | cat -e | cat -e | cat -e > file3 |
30 | | - cmp file2 file3 |
| 39 | +# Debug version with sanitizers |
| 40 | +debug: CFLAGS += $(DEBUG_FLAGS) |
| 41 | +debug: fclean $(NAME) |
| 42 | + @echo "$(YELLOW)⚠$(NC) Debug build with address sanitizer enabled" |
31 | 43 |
|
| 44 | +# Clean object files |
32 | 45 | clean: |
33 | 46 | @rm -rf $(OBJ) |
34 | | - @make -C $(LIB) clean |
| 47 | + @make -C $(LIB) clean > /dev/null 2>&1 |
| 48 | + @echo "$(YELLOW)🧹$(NC) Object files cleaned" |
35 | 49 |
|
| 50 | +# Clean everything including executable |
36 | 51 | fclean: clean |
37 | 52 | @rm -rf $(NAME) |
38 | | - @make -C $(LIB) fclean |
| 53 | + @rm -rf $(TEST_DIR) |
| 54 | + @echo "$(YELLOW)🧹$(NC) All files cleaned" |
39 | 55 |
|
| 56 | +# Rebuild everything |
40 | 57 | re: fclean all |
41 | 58 |
|
42 | | -.PHONY: clean fclean all re |
| 59 | +# Test the program |
| 60 | +test: $(NAME) |
| 61 | + @chmod +x $(TEST_DIR)/$(BASIC_TEST) |
| 62 | + @chmod +x $(TEST_DIR)/$(MULTI_TEST) |
| 63 | + @chmod +x $(TEST_DIR)/$(HERE_DOC_TEST) |
| 64 | + @echo "$(GREEN)🧪$(NC) Running tests..." |
| 65 | + @$(TEST_DIR)/$(BASIC_TEST) |
| 66 | + @$(TEST_DIR)/$(MULTI_TEST) |
| 67 | + @$(TEST_DIR)/$(HERE_DOC_TEST) |
| 68 | + @echo "$(GREEN)✓$(NC) All tests completed!" |
| 69 | + |
| 70 | +# Create test directory and scripts |
| 71 | +$(TEST_DIR): |
| 72 | + @mkdir -p $(TEST_DIR) |
| 73 | + |
| 74 | +# Create test files |
| 75 | +test-files: $(TEST_DIR) |
| 76 | + @echo "Creating test files..." |
| 77 | + @echo "Hello World\nThis is a test file\n42 is awesome" > $(TEST_DIR)/input.txt |
| 78 | + @echo -e "apple\nbanana\nApple\ncherry\nbanana\nApple" > $(TEST_DIR)/fruits.txt |
| 79 | + @echo "This is line 1\nThis is line 2" > $(TEST_DIR)/multiline.txt |
| 80 | + |
| 81 | +# Help target |
| 82 | +help: |
| 83 | + @echo "$(GREEN)Pipex Build System$(NC)" |
| 84 | + @echo "" |
| 85 | + @echo "Available targets:" |
| 86 | + @echo " $(YELLOW)make$(NC) - Build the main executable" |
| 87 | + @echo " $(YELLOW)make debug$(NC) - Build with debug flags and sanitizers" |
| 88 | + @echo " $(YELLOW)make clean$(NC) - Remove object files" |
| 89 | + @echo " $(YELLOW)make fclean$(NC) - Remove all generated files" |
| 90 | + @echo " $(YELLOW)make re$(NC) - Rebuild everything" |
| 91 | + @echo " $(YELLOW)make test$(NC) - Run test suite" |
| 92 | + @echo " $(YELLOW)make help$(NC) - Show this help message" |
| 93 | + @echo "" |
| 94 | + @echo "Usage examples:" |
| 95 | + @echo " ./pipex input.txt \"cat\" \"wc -l\" output.txt" |
| 96 | + @echo " ./pipex here_doc EOF \"cat\" \"tr 'a-z' 'A-Z'\" output.txt" |
| 97 | + @echo " ./pipex input.txt \"grep error\" \"sort\" \"uniq -c\" output.txt" |
0 commit comments