-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
260 lines (228 loc) · 7.49 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
##
## EPITECH PROJECT, 2023
## Makefile 42sh
## File description:
## Makefile
##
SOURCES = . built-in execute parse errors environment history line_edition
SRCS = main.c \
shell.c \
sighandler.c \
built-in/alias_unalias.c \
built-in/cd.c \
built-in/chose_builtin.c \
built-in/command_is_a_builtin.c \
built-in/echo.c \
built-in/exit.c \
built-in/repeat.c \
built-in/setenv.c \
built-in/set_unset_var.c \
built-in/show_environment.c \
built-in/unsetenv.c \
built-in/where.c \
built-in/which.c \
execute/check_program_exit_status.c \
execute/detect_command_type.c \
execute/execute_binary_file.c \
execute/execute_parentheses.c \
execute/execute_pipes_rotation.c \
execute/execute_using_path.c \
execute/run_user_input.c \
parse/check_argv_length.c \
parse/clean_commands.c \
parse/cut_input_to_commands.c \
parse/get_binary_name.c \
parse/handle_redirections.c \
parse/inhibitors.c \
parse/line_with_parentheses.c \
parse/load_redirections_for_command.c \
parse/my_strchr_escape.c \
parse/parse_single_command.c \
parse/quotes.c \
parse/remove_spaces_in_command.c \
parse/replace_aliases.c \
parse/replace_variables.c \
parse/separate_args.c \
parse/smart_strtok.c \
errors/execution_errors.c \
errors/parsing_error.c \
errors/redirection_errors.c \
errors/setenv_errors.c \
environment/aliases.c \
environment/aliases_management.c \
environment/environment.c \
environment/environment_variables.c \
environment/getter.c \
environment/initialize_environment.c \
environment/initialize_fallback_environment.c \
environment/linked_lists_management.c \
environment/path.c \
environment/variables.c \
environment/variables_management.c \
history/get_file_nb_lines.c \
history/get_from_history.c \
history/history.c \
history/previous_args_operations.c \
history/previous_commands_operations.c \
history/show_history.c \
line_edition/autocomplete_builtin.c \
line_edition/autocomplete_dir.c \
line_edition/autocomplete_path.c \
line_edition/autocompletion_utils.c \
line_edition/configure_terminal.c \
line_edition/line_edition_utils.c \
line_edition/process_arrow_keys.c \
line_edition/process_backspace_key.c \
line_edition/process_ctrl_d.c \
line_edition/process_delete_key.c \
line_edition/process_enter_key.c \
line_edition/process_home_end_keys.c \
line_edition/process_key_arrow_up_down.c \
line_edition/process_regular_key.c \
line_edition/process_tab_key.c \
OBJS = obj/main.o \
obj/shell.o \
obj/sighandler.o \
obj/built-in-alias_unalias.o \
obj/built-in-cd.o \
obj/built-in-chose_builtin.o \
obj/built-in-command_is_a_builtin.o \
obj/built-in-echo.o \
obj/built-in-exit.o \
obj/built-in-repeat.o \
obj/built-in-setenv.o \
obj/built-in-set_unset_var.o \
obj/built-in-show_environment.o \
obj/built-in-unsetenv.o \
obj/built-in-where.o \
obj/built-in-which.o \
obj/execute-check_program_exit_status.o \
obj/execute-detect_command_type.o \
obj/execute-execute_binary_file.o \
obj/execute-execute_parentheses.o \
obj/execute-execute_pipes_rotation.o \
obj/execute-execute_using_path.o \
obj/execute-run_user_input.o \
obj/parse-check_argv_length.o \
obj/parse-clean_commands.o \
obj/parse-cut_input_to_commands.o \
obj/parse-get_binary_name.o \
obj/parse-handle_redirections.o \
obj/parse-inhibitors.o \
obj/parse-line_with_parentheses.o \
obj/parse-load_redirections_for_command.o \
obj/parse-my_strchr_escape.o \
obj/parse-parse_single_command.o \
obj/parse-quotes.o \
obj/parse-remove_spaces_in_command.o \
obj/parse-replace_aliases.o \
obj/parse-replace_variables.o \
obj/parse-separate_args.o \
obj/parse-smart_strtok.o \
obj/errors-execution_errors.o \
obj/errors-parsing_error.o \
obj/errors-redirection_errors.o \
obj/errors-setenv_errors.o \
obj/environment-aliases.o \
obj/environment-aliases_management.o \
obj/environment-environment.o \
obj/environment-environment_variables.o \
obj/environment-getter.o \
obj/environment-initialize_environment.o \
obj/environment-initialize_fallback_environment.o \
obj/environment-linked_lists_management.o \
obj/environment-path.o \
obj/environment-variables.o \
obj/environment-variables_management.o \
obj/history-get_file_nb_lines.o \
obj/history-get_from_history.o \
obj/history-history.o \
obj/history-previous_args_operations.o \
obj/history-previous_commands_operations.o \
obj/history-show_history.o \
obj/line_edition-autocomplete_builtin.o \
obj/line_edition-autocomplete_dir.o \
obj/line_edition-autocomplete_path.o \
obj/line_edition-autocompletion_utils.o \
obj/line_edition-configure_terminal.o \
obj/line_edition-line_edition_utils.o \
obj/line_edition-process_arrow_keys.o \
obj/line_edition-process_backspace_key.o \
obj/line_edition-process_ctrl_d.o \
obj/line_edition-process_delete_key.o \
obj/line_edition-process_enter_key.o \
obj/line_edition-process_home_end_keys.o \
obj/line_edition-process_key_arrow_up_down.o \
obj/line_edition-process_regular_key.o \
obj/line_edition-process_tab_key.o \
OBJ_DIR = obj
OBJ = $(SRCS:%.c=obj/%.o)
OPTI = -O3 -Ofast \
-ftree-vectorize \
-ftree-loop-distribution -funroll-all-loops -funswitch-loops \
-march=native -mtune=native -fopenmp -mavx2 \
-lm -ffast-math -mfpmath=sse \
-fno-omit-frame-pointer -fno-optimize-sibling-calls \
-flto=auto
# Optimization flags:
# -O3: Enables all optimizations that do not involve a space-speed tradeoff.
# -Ofast: Enables all optimizations allowed by the language standard,
# including potentially unsafe ones.
# Vectorization flags:
# -fopt-info-vec -all-ftree-vectorize: Provides information about vectorization
# and tree vectorization.
# Loop unrolling flags:
# -ftree-loop-distribution: Distributes loop iterations over multiple threads.
# -funroll-loops: Unrolls loops to reduce loop overhead.
# -funroll-all-loops: Unrolls all loops, regardless of their size.
# -funswitch-loops: Enables loop inversion for better instruction scheduling.
# CPU-specific flags:
# -march=native: Generates code optimized for the host machine architecture.
# -mtune=native: Generates code optimized for the host machine CPU.
# -fopenmp: Enables OpenMP parallelization.
# -mavx2: Enables use of Advanced Vector Extensions 2.
# Linker flags:
# -lm: Links the math library.
# -ffast-math: Enables fast math operations, which may not be IEEE compliant.
# -mfpmath=sse: Uses SSE instructions for floating-point math.
# Link-time optimization flags:
# -flto: Enables link-time optimization, which allows the compiler to optimize
# across object files.
NAME = 42sh
CC = gcc
LIB = -L. -lall \
HEADER = -I./include/ \
-I./parse/include \
-I./history/include \
-I./execute/include \
-I./built-in/include \
-I./errors/include \
-I./environment/include \
-I./line_edition/include \
CFLAGS += -Wall -Wextra -Wshadow $(OPTI)\
$(LIB) $(HEADER)
DEBUGFLAGS += -Wall -Wextra -Wshadow -Wduplicated-cond -Wcast-align \
$(LIB) $(HEADER) -ggdb
all: $(NAME)
$(OBJ_DIR)/%.o: %.c
@$(CC) $(CFLAGS) -c $< -o \
$(addprefix $(OBJ_DIR)/, $(basename $(subst /,-,$<)).o)
$(NAME): $(OBJ)
@make -s -C ./lib/all
@$(CC) -o $(NAME) $(OBJS) $(CFLAGS)
@echo -e "[1;32mProject built successfully[0m"
debug: clean
@$(CC) $(SRCS) -o $(NAME) $(DEBUGFLAGS)
@echo -e "[1;33mProject built in debug mode[0m"
clean:
@rm $(OBJS) .idea/ -rf
@rm *.gcno -rf
@find . -type f,d \( -name "*~" -o -name "\#*\#" \) -delete
@find . -type f,d -name "vgcore*" -delete
@echo -e "[1;34mRepo cleaned[0m"
fclean: clean
@rm $(NAME) -rf
@find . -type f,d -name "*.a" -delete
@echo -e "[1;31mProject binary deleted[0m"
re: fclean $(NAME)
.PHONY: all $(NAME) clean fclean re