-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
162 lines (126 loc) · 5.18 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: pabeckha <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/02/22 17:56:15 by pabeckha #+# #+# #
# Updated: 2024/03/04 11:06:07 by pabeckha ### ########.fr #
# #
# **************************************************************************** #
# ar rcs $@ $^ is the recipe or command to build the target.
# ar: Archive command used for creating static libraries.
# rcs: Options for ar:
# r: Insert files into the archive.
# c: Create the archive if it doesn't exist.
# s: Write an index (symbol table) into the archive.
# $@: Automatic variable representing the target name
# $^: Automatic variable representing all the prerequisites(the object files)
# ar rcs $@ $^ is the recipe or command to build the target.
# ar: Archive command used for creating static libraries.
# rcs: Options for ar:
# r: Insert files into the archive.
# c: Create the archive if it doesn't exist.
# s: Write an index (symbol table) into the archive.
# $@: Automatic variable representing the target name
# $^: Automatic variable representing all the prerequisites(the object files)
# =============================================================================
# Color Variables
# =============================================================================
BLACK = "\033[0;30m"
GRAY = "\033[1;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
YELLOW = "\033[1;33m"
PURPLE = "\033[0;35m"
CYAN = "\033[0;36m"
WHITE = "\033[1;37m"
EOC = "\033[0;0m"
RESET_COLOR = "\033[0m"
# Standard
NAME = pipex
# Directories
SRC_DIR := src/
OBJ_DIR := obj/
# Compiler and Flags
CC := cc
# SANITIZER := #-fsanitize=address -g
RM := rm -f
CFLAGS := -Wall -Wextra -Werror
# Libraries
LIBFT := ./libs/libft/libft.a
SHARED_SRCS := $(SRC_DIR)store_commands.c \
$(SRC_DIR)store_commands_utils.c \
$(SRC_DIR)get_path_env.c \
$(SRC_DIR)command_split_concat.c \
$(SRC_DIR)command_split_concat_utils.c \
$(SRC_DIR)store_main_arguments.c \
$(SRC_DIR)ft_free.c \
$(SRC_DIR)get_number_commands.c \
$(SRC_DIR)store_command_full_string.c \
$(SRC_DIR)allocate_memory_commands.c \
$(SRC_DIR)store_path_commands.c \
$(SRC_DIR)store_variables.c \
$(SRC_DIR)open_input_output_fds.c \
$(SRC_DIR)create_pipes.c \
$(SRC_DIR)close_pipes_parent.c \
$(SRC_DIR)close_pipes_child.c \
$(SRC_DIR)allocate_memory_pid.c \
$(SRC_DIR)create_child_processes.c \
$(SRC_DIR)wait_child_processes.c \
$(SRC_DIR)execute_commands.c \
$(SRC_DIR)redirect_fds_child.c \
$(SRC_DIR)allocate_memory_path_commands.c \
$(SRC_DIR)get_path_command.c \
$(SRC_DIR)pipex_utils.c \
$(SRC_DIR)handle_single_quotes.c \
$(SRC_DIR)handle_double_quotes.c \
$(SRC_DIR)close_fds_parent.c \
#Source Files
SRCS := $(SRC_DIR)pipex.c \
$(SHARED_SRCS) \
SRCS_BONUS := $(SRC_DIR)pipex_bonus.c \
$(SRC_DIR)pipex_bonus_utils.c \
$(SHARED_SRCS)\
SRCS := $(SRC_DIR)pipex.c \
$(SRC_DIR)pipex_bonus_utils.c \
$(SHARED_SRCS)\
# Creation of Object Files for each Source File
OBJ := $(patsubst $(SRC_DIR)%.c, $(OBJ_DIR)%.o, $(SRCS))
# Creation of Object Files for each Bonus Source File
OBJ_BONUS := $(patsubst $(SRC_DIR)%.c, $(OBJ_DIR)%.o, $(SRCS_BONUS))
# Rules
all: ${NAME}
bonus: ${NAME}_bonus
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
@echo $(YELLOW) "Compiling...\t" $< $(EOC)
@mkdir -p $(@D)
@${CC} ${CFLAGS} $(SANITIZER) -I.libs/libft -c $? -o $@
${NAME}: ${OBJ}
@echo $(GREEN) "Source files are compiled!\n" $(EOC)
@echo $(WHITE) "Building pipex for" $(YELLOW) "Mandatory" $(WHITE) "..." $(EOC)
@make -s -C ./libs/libft
@${CC} ${CFLAGS} $(SANITIZER) $^ -L./libs/libft -lft -o ${NAME}
@echo $(GREEN) "Pipex Mandatory is created!\n" $(EOC) $(RESET_COLOR)
${NAME}_bonus: ${OBJ_BONUS}
@echo $(GREEN) "Source files are compiled!\n" $(EOC)
@echo $(WHITE) "Building pipex for" $(YELLOW) "Bonus" $(WHITE)
@make -s -C ./libs/libft
@${CC} ${CFLAGS} $^ -L./libs/libft -lft -o ${NAME}_bonus
@echo $(GREEN) "Pipex Bonus is created!\n" $(EOC) $(RESET_COLOR)
libft:
@make -C libs/libft
clean:
@echo $(YELLOW) "Cleaning object files..." $(EOC)
@make -s clean -C ./libs/libft
@${RM} ${OBJ} ${OBJ_BONUS}
@echo $(RED) "Object files are cleaned!\n" $(EOC)
fclean: clean
@echo $(YELLOW) "Removing pipex..." $(EOC)
@${RM} ${NAME} ${NAME}_bonus
@${RM} ./libs/libft/libft.a
@rm -rf ${OBJ_DIR}
@echo $(RED) "pipex is removed!\n" $(EOC)
re: fclean all
.PHONY: all clean fclean re libft bonus