-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
94 lines (75 loc) · 2.61 KB
/
Makefile
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
NAME = pipex
# Collors
GREEN = \033[0;32m
RED = \033[0;31m
BLUE = \033[0;34m
RESET = \033[0m
# Paths
HEADERS_PATH = ./include/
SRCS_PATH = ./src/
OBJS_PATH = ./obj/
LIBS_PATH = ./lib/
BINS_PATH = ./bin/
# Compilation
CC = gcc -g
FLAGS = -Wall -Wextra -Werror
#Chedk Leak memory
LEAK = valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes -s
# Bash commands
RM = rm -f # -f Force
MKDIR = mkdir -p
MAKE_NOPRINT = $(MAKE) --no-print-directory
# Files
SRC_FILES = pipex.c error_handler.c file_handler.c free.c execute_cmd.c \
tokenization.c
SOURCES = $(addprefix $(SRCS_PATH), $(SRC_FILES))
OBJ_FILES = $(patsubst %.c, %.o, $(SRC_FILES))
OBJECTS = $(addprefix $(OBJS_PATH), $(OBJ_FILES))
EXECUTABLE = pipex
# Targets
all: libft $(NAME) main
# Compiles libft all over
libft:
@echo "$(NAME): $(BLUE)Generating... Just a minute$(RESET)"
@cd $(LIBS_PATH)libft && $(MAKE_NOPRINT)
@echo "$(NAME): $(GREEN)Done!$(RESET)"
# Creates static library libft.a inside ./libs/ folder
$(NAME): $(OBJECTS)
@cp $(LIBS_PATH)/libft.a $(LIBS_PATH)$(NAME)
@ar -rcs $(LIBS_PATH)$(NAME) $(OBJECTS)
# Creates object files for ft_pipex
$(OBJS_PATH)%.o : $(SRCS_PATH)%.c $(HEADERS_PATH)*.h
@$(MKDIR) $(OBJS_PATH)
@$(CC) $(FLAGS) -c $< -I $(HEADERS_PATH) -o $@
# Creates the executable file $(EXECUTABLE) to test development
main: ./apps/app.c
@$(MKDIR) $(BINS_PATH)
@$(CC) $(FLAGS) $(OBJECTS) $< $(LIBS_PATH)$(NAME) -I $(HEADERS_PATH) -o $(BINS_PATH)$(EXECUTABLE)
# Compile program and execute main file
run: all main
# @$(BINS_PATH)$(EXECUTABLE) ./files/file-in "cat" "wc -l" ./files/file-out
@$(BINS_PATH)$(EXECUTABLE) ./files/file-in "cat" "grep Avengers" ./files/file-out
# @$(BINS_PATH)$(EXECUTABLE) ./files/file-in "tr a b" "tr b ' '" ./files/file-out
# @$(BINS_PATH)$(EXECUTABLE) ./files/file-in "tr a b" "tr b '\n'" ./files/file-out
# @$(BINS_PATH)$(EXECUTABLE) ./files/file-in "tr ' ' _" "tr a 'A'" ./files/file-out
# Sanitize
clean:
@echo "$(GREEN)$(NAME): $(RED)object (*.o) files were deleted$(RESET)"
@$(RM) $(OBJECTS)
@echo "$(RED)Clean in progres...$(RESET)"
@cd $(LIBS_PATH)libft && $(MAKE_NOPRINT) $@
# Removing .o files, .a files
fclean: clean
@echo "$(GREEN)$(NAME): $(RED)was deleted$(RESET)"
@$(RM) $(BINS_PATH)$(EXECUTABLE)
@$(RM) $(LIBS_PATH)$(NAME)
@cd $(LIBS_PATH)libft && $(MAKE_NOPRINT) $@
@echo "$(GREEN)$(NAME): $(BLUE)Sanitized!$(RESET)"
norma:
norminette $(SOURCES)
valgrind:
$(LEAK) $(BINS_PATH)$(EXECUTABLE) ./files/file-in "cat" "wc -l" ./files/file-out
# Removing and running
re: fclean all
# All the variables that is not a file in source folder.
.PHONY: all run clean fclean re