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