2025-02-06 13:43:26 +01:00
|
|
|
NAME = minishell
|
2025-02-26 14:07:55 +01:00
|
|
|
DEBUG = -g -O0
|
2025-02-14 13:30:18 +01:00
|
|
|
# -fno-omit-frame-pointer is to prevent malloc stacktraces from being truncated,
|
|
|
|
|
# see "My malloc stacktraces are too short" here:
|
|
|
|
|
# https://github.com/google/sanitizers/wiki/AddressSanitizer
|
|
|
|
|
ASAN = -fsanitize=address -fno-omit-frame-pointer
|
2025-02-06 13:43:26 +01:00
|
|
|
TSAN = -fsanitize=thread
|
|
|
|
|
UBSAN = -fsanitize=undefined
|
2025-02-06 13:58:50 +01:00
|
|
|
LDLIBS = \
|
|
|
|
|
-lreadline \
|
2025-02-12 14:51:05 +01:00
|
|
|
-lft
|
|
|
|
|
LIBFTDIR = ./libft/
|
|
|
|
|
LIBFT = $(LIBFTDIR)libft.a
|
|
|
|
|
IFLAGS = -I$(LIBFTDIR)
|
|
|
|
|
LINCLUDE = -L$(LIBFTDIR)
|
2025-02-06 13:58:50 +01:00
|
|
|
|
2025-02-06 13:43:26 +01:00
|
|
|
ifeq ($(CFLAGS),)
|
2025-04-15 15:25:28 +02:00
|
|
|
CFLAGS = -Wall -Wextra -Werror \
|
2025-04-15 11:19:24 +02:00
|
|
|
$(DEBUG) \
|
|
|
|
|
|
2025-02-06 13:43:26 +01:00
|
|
|
endif
|
|
|
|
|
export CFLAGS
|
|
|
|
|
srcs = \
|
2025-02-14 17:55:26 +01:00
|
|
|
src/buffer/buffer.c \
|
2025-03-10 18:44:37 +01:00
|
|
|
src/buffer/buffer_charptr.c \
|
2025-02-19 13:29:44 +01:00
|
|
|
src/env/env.c \
|
|
|
|
|
src/env/env_convert.c \
|
|
|
|
|
src/env/env_manip.c \
|
|
|
|
|
src/env/envp.c \
|
2025-04-04 19:26:57 +02:00
|
|
|
src/executing/cmd/cmd_execute.c \
|
2025-04-04 19:56:54 +02:00
|
|
|
src/executing/common/do_waitpid.c \
|
2025-04-07 10:40:31 +02:00
|
|
|
src/executing/connec_cmd/connec_cmd_execute.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/executing/connec_cmd/connec_pipe_cmd_execute.c \
|
2025-04-04 19:52:29 +02:00
|
|
|
src/executing/group_cmd/group_cmd_execute.c \
|
2025-03-07 11:52:28 +01:00
|
|
|
src/executing/here_doc/here_doc.c \
|
2025-03-28 18:28:27 +01:00
|
|
|
src/executing/here_doc/here_doc_errors.c \
|
2025-03-13 17:26:44 +01:00
|
|
|
src/executing/here_doc/here_doc_expand_line.c \
|
2025-04-17 09:44:04 +02:00
|
|
|
src/executing/here_doc/here_doc_utils.c \
|
2025-03-11 13:30:40 +01:00
|
|
|
src/executing/here_doc/random_filename.c \
|
|
|
|
|
src/executing/here_doc/strip_newline.c \
|
2025-03-31 16:33:46 +02:00
|
|
|
src/executing/simple_cmd/builtin_cd.c \
|
2025-04-03 13:50:56 +02:00
|
|
|
src/executing/simple_cmd/builtin_echo.c \
|
2025-04-02 19:45:18 +02:00
|
|
|
src/executing/simple_cmd/builtin_env.c \
|
2025-04-01 18:31:38 +02:00
|
|
|
src/executing/simple_cmd/builtin_exit.c \
|
2025-04-01 13:53:53 +02:00
|
|
|
src/executing/simple_cmd/builtin_export.c \
|
2025-03-31 14:53:05 +02:00
|
|
|
src/executing/simple_cmd/builtin_invalid.c \
|
|
|
|
|
src/executing/simple_cmd/builtin_pwd.c \
|
2025-04-03 14:30:44 +02:00
|
|
|
src/executing/simple_cmd/builtin_unset.c \
|
2025-04-17 10:09:20 +02:00
|
|
|
src/executing/simple_cmd/builtins.c \
|
|
|
|
|
src/executing/simple_cmd/handle_redirections.c \
|
2025-03-27 16:10:41 +01:00
|
|
|
src/executing/simple_cmd/simple_cmd_execute.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/executing/simple_cmd/simple_cmd_execute_debug.c \
|
2025-04-28 12:11:27 +02:00
|
|
|
src/executing/simple_cmd/std_fds.c \
|
2025-04-02 18:17:37 +02:00
|
|
|
src/executing/simple_cmd/subprocess.c \
|
2025-02-17 16:52:17 +01:00
|
|
|
src/ft_errno.c \
|
2025-02-19 18:04:34 +01:00
|
|
|
src/get_command.c \
|
2025-04-14 17:53:20 +02:00
|
|
|
src/parser/cmd/cmd.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/parser/cmd/cmd_debug.c \
|
|
|
|
|
src/parser/cmd/cmd_destroy.c \
|
2025-04-16 13:13:19 +02:00
|
|
|
src/parser/cmd/cmds_parse.c \
|
2025-04-16 13:03:28 +02:00
|
|
|
src/parser/cmd/opt_cmds_parse.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/parser/connec_cmd/connec_cmd_debug.c \
|
2025-04-15 11:40:16 +02:00
|
|
|
src/parser/connec_cmd/connec_reorient_subtree.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/parser/group_cmd/group_cmd_debug.c \
|
2025-04-15 10:48:00 +02:00
|
|
|
src/parser/group_cmd/group_cmd_parse.c \
|
2025-02-14 15:06:01 +01:00
|
|
|
src/parser/matchers/blank.c \
|
2025-02-19 13:29:44 +01:00
|
|
|
src/parser/matchers/identifier.c \
|
2025-02-18 15:07:05 +01:00
|
|
|
src/parser/matchers/metacharacter.c \
|
2025-02-17 16:14:14 +01:00
|
|
|
src/parser/matchers/operator_combo.c \
|
|
|
|
|
src/parser/matchers/operator_start.c \
|
2025-02-21 14:13:51 +01:00
|
|
|
src/parser/matchers/pipe.c \
|
2025-02-20 13:22:32 +01:00
|
|
|
src/parser/matchers/quote.c \
|
2025-04-15 10:44:27 +02:00
|
|
|
src/parser/pipeline/optional_pipeline_parse.c \
|
2025-04-15 11:40:16 +02:00
|
|
|
src/parser/pipeline/pipeline_parse.c \
|
2025-04-14 17:33:25 +02:00
|
|
|
src/parser/redirect/redirect.c \
|
2025-04-08 16:18:57 +02:00
|
|
|
src/parser/redirect/redirect_debug.c \
|
2025-04-14 17:33:25 +02:00
|
|
|
src/parser/redirect/redirect_from_words.c \
|
2025-04-15 10:16:02 +02:00
|
|
|
src/parser/redirect/redirect_parse.c \
|
2025-03-20 17:34:07 +01:00
|
|
|
src/parser/remove_quotes/cmdgroup_remove_quotes.c \
|
2025-02-28 13:51:16 +01:00
|
|
|
src/parser/remove_quotes/remove_quotes.c \
|
2025-02-21 12:35:51 +01:00
|
|
|
src/parser/simple_cmd/simple_cmd.c \
|
2025-04-15 10:36:55 +02:00
|
|
|
src/parser/simple_cmd/simple_cmd_parse.c \
|
2025-02-13 15:17:30 +01:00
|
|
|
src/parser/worddesc/worddesc.c \
|
2025-04-17 14:30:13 +02:00
|
|
|
src/parser/worddesc/worddesc_debug.c \
|
2025-02-13 15:17:30 +01:00
|
|
|
src/parser/wordlist/wordlist.c \
|
2025-02-26 14:07:55 +01:00
|
|
|
src/parser/wordlist/wordlist_copy.c \
|
2025-02-24 18:18:15 +01:00
|
|
|
src/parser/wordlist/wordlist_debug.c \
|
2025-03-10 14:22:58 +01:00
|
|
|
src/parser/wordlist/wordlist_idx.c \
|
2025-03-15 15:44:23 +01:00
|
|
|
src/parser/wordlist/wordlist_quicksort.c \
|
|
|
|
|
src/parser/wordlist/wordlist_utils.c \
|
2025-04-09 13:25:58 +02:00
|
|
|
src/parser/wordsplit/get_token_type.c \
|
2025-02-20 12:06:34 +01:00
|
|
|
src/parser/wordsplit/rule_utils.c \
|
2025-02-19 18:41:26 +01:00
|
|
|
src/parser/wordsplit/tokenizing_1_5.c \
|
|
|
|
|
src/parser/wordsplit/tokenizing_6_10.c \
|
2025-02-13 15:17:30 +01:00
|
|
|
src/parser/wordsplit/wordsplit.c \
|
2025-02-19 18:41:26 +01:00
|
|
|
src/parser/wordsplit/wordsplit_utils.c \
|
2025-04-21 13:07:02 +02:00
|
|
|
src/postprocess/ambiguous_redirect.c \
|
2025-04-01 13:28:14 +02:00
|
|
|
src/postprocess/expansion/expand_vars.c \
|
2025-04-03 15:50:32 +02:00
|
|
|
src/postprocess/expansion/expand_wildcard.c \
|
2025-04-03 13:50:56 +02:00
|
|
|
src/postprocess/fieldsplit/fieldsplit.c \
|
2025-04-21 08:25:49 +02:00
|
|
|
src/postprocess/fieldsplit/redirect_fieldsplit.c \
|
2025-04-04 14:23:09 +02:00
|
|
|
src/sig/sig.c \
|
2025-04-17 09:44:04 +02:00
|
|
|
src/sig/sig_handlers.c \
|
2025-03-15 15:44:23 +01:00
|
|
|
src/subst/path_split.c \
|
2025-02-28 18:48:30 +01:00
|
|
|
src/subst/replace_substr.c \
|
2025-03-15 15:44:23 +01:00
|
|
|
src/subst/simple_filename_exp.c \
|
2025-03-18 18:55:25 +01:00
|
|
|
src/subst/simple_filename_exp_utils.c \
|
fix(get_command_path): leak when path unset and calling file present in current dir
$ touch cat
$ unset PATH
$ cat
m==75845== Memcheck, a memory error detector
==75845== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==75845== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==75845== Command: ./minishell
==75845==
==75846== Memcheck, a memory error detector
==75846== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==75846== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==75846== Command: /nix/store/6wgd8c9vq93mqxzc7jhkl86mv6qbc360-coreutils-9.5/bin/touch cat
==75846==
==75846==
==75846== FILE DESCRIPTORS: 0 open (0 std) at exit.
==75846==
==75846== HEAP SUMMARY:
==75846== in use at exit: 0 bytes in 0 blocks
==75846== total heap usage: 46 allocs, 46 frees, 8,126 bytes allocated
==75846==
==75846== All heap blocks were freed -- no leaks are possible
==75846==
==75846== For lists of detected and suppressed errors, rerun with: -s
==75846== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
minishell: cat: Permission denied
==75849==
==75849== FILE DESCRIPTORS: 3 open (3 std) at exit.
==75849==
==75849== HEAP SUMMARY:
==75849== in use at exit: 4,181 bytes in 12 blocks
==75849== total heap usage: 982 allocs, 970 frees, 122,299 bytes allocated
==75849==
==75849== 8 bytes in 1 blocks are definitely lost in loss record 1 of 9
==75849== at 0x48467D9: malloc (in /nix/store/phbnjdfmy3v4ak9xf211y2336mv5kx9s-valgrind-3.23.0/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==75849== by 0x113C22: ft_calloc (ft_calloc.c:28)
==75849== by 0x112399: get_paths_array (src/subst/simple_filename_exp.c:37)
==75849== by 0x1121EE: filepath_from_env (src/subst/simple_filename_exp.c:144)
==75849== by 0x1121C0: get_cmdpath (src/subst/simple_filename_exp.c:184)
==75849== by 0x10CD97: exec_external_cmd (src/executing/simple_cmd/simple_cmd_execute.c:67)
==75849== by 0x10CC58: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:94)
==75849== by 0x10B12C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==75849== by 0x10A4FD: execute_command (src/minishell.c:37)
==75849== by 0x10A3B2: main (src/minishell.c:90)
==75849==
==75849== 24 bytes in 1 blocks are still reachable in loss record 6 of 9
==75849== at 0x48467D9: malloc (in /nix/store/phbnjdfmy3v4ak9xf211y2336mv5kx9s-valgrind-3.23.0/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==75849== by 0x113C22: ft_calloc (ft_calloc.c:28)
==75849== by 0x10D4A9: cmd_create (src/parser/cmd/cmd.c:20)
==75849== by 0x10F6A1: simple_cmd_create (src/parser/simple_cmd/simple_cmd_parse.c:24)
==75849== by 0x10F4E4: minishell_simple_cmd_parse (src/parser/simple_cmd/simple_cmd_parse.c:38)
==75849== by 0x10E078: minishell_group_or_simple_parse (src/parser/group_cmd/group_cmd_parse.c:53)
==75849== by 0x10E4AC: minishell_pipeline_parse (src/parser/pipeline/pipeline_parse.c:26)
==75849== by 0x10D93C: minishell_cmds_parse (src/parser/cmd/cmds_parse.c:30)
==75849== by 0x1139D5: minishell_parse (src/parser/cmd_parsing.c:67)
==75849== by 0x10A38B: main (src/minishell.c:87)
==75849==
==75849== LEAK SUMMARY:
==75849== definitely lost: 8 bytes in 1 blocks
==75849== indirectly lost: 0 bytes in 0 blocks
==75849== possibly lost: 0 bytes in 0 blocks
==75849== still reachable: 24 bytes in 1 blocks
==75849== suppressed: 4,149 bytes in 10 blocks
==75849==
==75849== For lists of detected and suppressed errors, rerun with: -s
==75849== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
126
==75845==
==75845== FILE DESCRIPTORS: 3 open (3 std) at exit.
==75845==
==75845== HEAP SUMMARY:
==75845== in use at exit: 4,201 bytes in 14 blocks
==75845== total heap usage: 844 allocs, 830 frees, 72,248 bytes allocated
==75845==
==75845== 8 bytes in 1 blocks are definitely lost in loss record 1 of 8
==75845== at 0x48467D9: malloc (in /nix/store/phbnjdfmy3v4ak9xf211y2336mv5kx9s-valgrind-3.23.0/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==75845== by 0x113C22: ft_calloc (ft_calloc.c:28)
==75845== by 0x112399: get_paths_array (src/subst/simple_filename_exp.c:37)
==75845== by 0x1121EE: filepath_from_env (src/subst/simple_filename_exp.c:144)
==75845== by 0x1121C0: get_cmdpath (src/subst/simple_filename_exp.c:184)
==75845== by 0x10CD97: exec_external_cmd (src/executing/simple_cmd/simple_cmd_execute.c:67)
==75845== by 0x10CC58: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:94)
==75845== by 0x10B12C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==75845== by 0x10A4FD: execute_command (src/minishell.c:37)
==75845== by 0x10A3B2: main (src/minishell.c:90)
==75845==
==75845== LEAK SUMMARY:
==75845== definitely lost: 8 bytes in 1 blocks
==75845== indirectly lost: 0 bytes in 0 blocks
==75845== possibly lost: 0 bytes in 0 blocks
==75845== still reachable: 0 bytes in 0 blocks
==75845== suppressed: 4,193 bytes in 13 blocks
==75845==
==75845== For lists of detected and suppressed errors, rerun with: -s
==75845== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)inishell: cat: Permission denied
2025-04-24 17:46:54 +02:00
|
|
|
src/subst/simple_filename_exp_utils_utils.c \
|
2025-03-06 12:45:05 +01:00
|
|
|
src/subst/variable_subst.c \
|
|
|
|
|
src/subst/variable_subst_utils.c \
|
|
|
|
|
src/subst/wildcard_exp.c \
|
2025-03-19 09:20:51 +01:00
|
|
|
src/subst/wildcard_exp_utils.c \
|
2025-03-18 15:11:23 +01:00
|
|
|
src/subst/wildcard_exp_utils2.c \
|
|
|
|
|
src/treedrawing.c \
|
2025-04-08 12:14:38 +02:00
|
|
|
src/parser/cmd_parsing.c
|
|
|
|
|
|
2025-02-06 13:43:26 +01:00
|
|
|
|
|
|
|
|
objs = $(srcs:.c=.o)
|
2025-02-06 15:48:48 +01:00
|
|
|
export objs
|
2025-02-06 13:43:26 +01:00
|
|
|
minishell_objs = $(addsuffix .o,src/$(NAME)) $(objs)
|
|
|
|
|
all_objs = $(minishell_objs)
|
|
|
|
|
deps = $(all_objs:.o=.d)
|
|
|
|
|
|
2025-03-19 15:11:32 +01:00
|
|
|
.PHONY: all clean fclean re norm tests ctests ctestsa ctestsub ctestst alla \
|
|
|
|
|
allub allt testsa testsub testst inttests inttestsa inttestsub inttestst
|
2025-02-06 13:43:26 +01:00
|
|
|
|
|
|
|
|
all: $(NAME)
|
|
|
|
|
|
|
|
|
|
-include $(deps)
|
|
|
|
|
|
2025-02-12 14:51:05 +01:00
|
|
|
$(NAME): $(minishell_objs) $(LIBFT)
|
|
|
|
|
$(CC) $(CFLAGS) -o $@ $(minishell_objs) $(LINCLUDE) $(LDLIBS)
|
|
|
|
|
|
2025-04-02 14:15:30 +02:00
|
|
|
$(LIBFT): CFLAGS+=-DBUFFER_SIZE=1
|
2025-02-12 14:51:05 +01:00
|
|
|
$(LIBFT):
|
|
|
|
|
+$(MAKE) -C $(LIBFTDIR)
|
2025-02-06 13:43:26 +01:00
|
|
|
|
|
|
|
|
%.o: %.c
|
2025-02-12 14:51:05 +01:00
|
|
|
$(CC) -c $(CFLAGS) $(IFLAGS) -o $*.o $*.c
|
2025-04-15 10:29:30 +02:00
|
|
|
$(CC) -MM $(CFLAGS) $(IFLAGS) -MT $*.o $*.c > $*.d
|
2025-02-06 13:43:26 +01:00
|
|
|
|
|
|
|
|
clean:
|
2025-02-12 14:51:05 +01:00
|
|
|
+$(MAKE) -C $(LIBFTDIR) clean
|
2025-02-06 13:43:26 +01:00
|
|
|
find . -name '*.o' -print -delete
|
|
|
|
|
find . -name '*.d' -print -delete
|
|
|
|
|
|
|
|
|
|
fclean: clean
|
2025-02-12 14:51:05 +01:00
|
|
|
$(MAKE) -C $(LIBFTDIR) fclean
|
2025-02-06 13:43:26 +01:00
|
|
|
rm -f $(NAME)
|
2025-02-06 15:48:48 +01:00
|
|
|
+make -C tests fclean
|
2025-02-06 13:43:26 +01:00
|
|
|
|
|
|
|
|
re:
|
|
|
|
|
+make fclean
|
|
|
|
|
+make all
|
2025-02-06 13:45:29 +01:00
|
|
|
|
|
|
|
|
norm:
|
2025-02-12 16:53:48 +01:00
|
|
|
norminette src libft | grep -v OK || true
|
2025-02-06 15:13:34 +01:00
|
|
|
|
|
|
|
|
tests:
|
2025-03-19 15:11:32 +01:00
|
|
|
+make fclean
|
|
|
|
|
+make testsa
|
|
|
|
|
+make fclean
|
|
|
|
|
+make testsub
|
|
|
|
|
+make fclean
|
|
|
|
|
+make testst
|
|
|
|
|
@echo "All tests passed!"
|
|
|
|
|
|
|
|
|
|
testsa: CFLAGS += $(ASAN)
|
|
|
|
|
testsa:
|
2025-02-06 15:48:48 +01:00
|
|
|
@echo "Running tests with AddressSanitizer..."
|
2025-03-19 15:11:32 +01:00
|
|
|
+make inttests
|
|
|
|
|
+make ctests
|
2025-02-06 15:48:48 +01:00
|
|
|
|
2025-03-19 15:11:32 +01:00
|
|
|
testsub: CFLAGS += $(UBSAN)
|
|
|
|
|
testsub: all
|
2025-02-06 15:48:48 +01:00
|
|
|
@echo "Running tests with UndefinedBehaviourSanitizer..."
|
2025-03-19 15:11:32 +01:00
|
|
|
+make inttests
|
|
|
|
|
+make ctests
|
2025-02-06 15:48:48 +01:00
|
|
|
|
2025-03-19 15:11:32 +01:00
|
|
|
testst: CFLAGS += $(TSAN)
|
|
|
|
|
testst: all
|
2025-02-06 15:48:48 +01:00
|
|
|
@echo "Running tests with ThreadSanitizer..."
|
2025-03-19 15:11:32 +01:00
|
|
|
+make inttests
|
|
|
|
|
+make ctests
|
2025-02-06 15:48:48 +01:00
|
|
|
|
2025-03-19 15:11:32 +01:00
|
|
|
inttests: all
|
|
|
|
|
./test.sh
|
|
|
|
|
|
|
|
|
|
inttestsa: CFLAGS += $(ASAN)
|
|
|
|
|
inttestsa: all
|
|
|
|
|
./test.sh
|
|
|
|
|
|
|
|
|
|
inttestsub: CFLAGS += $(UBSAN)
|
|
|
|
|
inttestsub: all
|
|
|
|
|
./test.sh
|
|
|
|
|
|
|
|
|
|
inttestst: CFLAGS += $(TSAN)
|
|
|
|
|
inttestst: all
|
|
|
|
|
./test.sh
|
2025-02-12 15:10:12 +01:00
|
|
|
|
2025-03-19 15:11:32 +01:00
|
|
|
ctests: $(LIBFT) all
|
2025-02-14 13:32:21 +01:00
|
|
|
|
|
|
|
|
ctestsa: CFLAGS += $(ASAN)
|
|
|
|
|
ctestsa: ctests
|
|
|
|
|
ctestsub: CFLAGS += $(UBSAN)
|
|
|
|
|
ctestsub: ctests
|
|
|
|
|
ctestst: CFLAGS += $(TSAN)
|
|
|
|
|
ctestst: ctests
|
2025-03-18 11:54:20 +01:00
|
|
|
|
|
|
|
|
alla: CFLAGS += $(ASAN)
|
|
|
|
|
alla: all
|
|
|
|
|
allub: CFLAGS += $(UBSAN)
|
|
|
|
|
allub: all
|
|
|
|
|
allt: CFLAGS += $(TSAN)
|
|
|
|
|
allt: all
|