-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.old
More file actions
147 lines (115 loc) · 4.98 KB
/
Makefile.old
File metadata and controls
147 lines (115 loc) · 4.98 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
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
NAME = minishell
# flags
CFLAGS = -Wall -Werror -Wextra
CFLAGS += -g3
# CFLAGS += -DMINIHISTFILEPATH="\"/.minishell_test_history\""
# NDEBUG is a macro that disables the debug prints - uncomment to disable them
# comment out to enable them need to recompile with make re
# can use also like ./minishell 2>> error_log.txt to print stderror to a
# file and have
# all debug messages together
# CFLAGS += -DNDEBUG
CC = cc
INCLUDES = -I./lib/libft -I./include
# directories
OBJ_DIR = obj/
SRC_DIR = src/
TMP_DIR = /tmp/splash/
LIBFTDIR = lib/libft
# Group related files by module for better organization
CORE_SRCS := init.c fd.c main.c loop.c signals.c freedata.c
HISTORY_SRCS := history/history.c history/history2.c
SCANNER_SRCS := scanner/scanner.c scanner/scanner_utils.c scanner/scanner_utils2.c \
scanner/scanner_utils3.c scanner/scanner_utils4.c scanner/scanner_error.c \
scanner/dollar_tokens.c scanner/token_functions.c scanner/token_functions2.c \
scanner/token_functions3.c scanner/reserved_builtins.c scanner/reserved_builtins2.c \
scanner/token_operators.c scanner/history_tokens.c scanner/token_blocks.c \
scanner/token_blocks2.c scanner/redirection_tokens.c scanner/redirection_tokens2.c
ENVIRONMENT_SRCS := environment/environment.c environment/environment2.c \
environment/environment3.c environment/environment4.c
PARSER_SRCS := parser/parser.c parser/parser2.c parser/parser3.c parser/parser4.c \
parser/parser_utils.c parser/parser_utils2.c parser/parser_utils3.c \
parser/parser_utils4.c
ANALYSER_SRCS := analyser/analyser.c analyser/expansion_utils.c analyser/expansion_utils2.c \
analyser/expansion_quotes.c analyser/expansion_dollar.c analyser/expansion_tilde.c \
analyser/expansion_tilde2.c
UTILS_SRCS := utils/utils.c utils/utils2.c
GLOBBING_SRCS := globbing/globbing.c globbing/globbing1.c
ERROR_SRCS := error/error_perror.c error/error_stderr.c
DARRAY_SRCS := darray/darray.c darray/darray2.c darray/darray3.c
BUILTINS_SRCS := builtins/builtins.c builtins/builtin_cd.c builtins/builtin_echo.c \
builtins/builtin_env.c builtins/builtin_exit.c builtins/builtin_export.c \
builtins/builtin_pwd.c builtins/builtin_unset.c
EXECUTER_SRCS := executer/executer.c executer/executer2.c executer/executer3.c \
executer/executer4.c executer/executer5.c executer/executer6.c
HEREDOC_SRCS := heredoc/heredoc.c heredoc/heredoc2.c heredoc/heredoc3.c \
heredoc/heredoc4.c heredoc/heredoc5.c
# Combine all source files
SRCS := $(CORE_SRCS) $(HISTORY_SRCS) $(SCANNER_SRCS) $(ENVIRONMENT_SRCS) \
$(PARSER_SRCS) $(ANALYSER_SRCS) $(UTILS_SRCS) $(GLOBBING_SRCS) \
$(ERROR_SRCS) $(DARRAY_SRCS) $(BUILTINS_SRCS) $(EXECUTER_SRCS) \
$(HEREDOC_SRCS)
# Add source directory prefix
SRCS := $(addprefix $(SRC_DIR), $(SRCS))
OBJS = $(patsubst $(SRC_DIR)%.c,$(OBJ_DIR)%.o,$(SRCS))
HDRS = $(addprefix include/, init.h fd.h splash.h scanner.h environment.h \
parser.h analyser.h executer.h splash_error.h darray.h builtins.h globbing.h debug.h heredoc.h)
# linker flags and libraries
LIBFT = $(LIBFTDIR)/libft.a
LDLIBS = -lm -lreadline -lcurses
# OS specific flags
UNAME = $(shell uname -s)
ifeq ($(UNAME), Linux)
LDLIBS += -lbsd
else ifeq ($(UNAME), Darwin)
INCLUDES += -I$(shell brew --prefix readline)/include
LDLIBS += -L$(shell brew --prefix readline)/lib
endif
# target
all: $(LIBFT) $(NAME) tests tests_integration bonus
@mkdir -p $(TMP_DIR)
@chmod 700 $(TMP_DIR)
# Static pattern rule for compilation - adding the .o files in the obj folder
# with includes for the libft that will allow the "libft.h" notation
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Target $(LIBFT) depends on the libft library.
$(LIBFT):
@if [ ! -d $(LIBFTDIR) ]; then \
echo "⚠️ Libft directory not found. Make sure submodules are initialized."; \
echo " Run: git submodule update --init --recursive"; \
exit 1; \
fi
$(MAKE) -C $(LIBFTDIR) all
# Target $(NAME) depends on object files $(OBJS) and libft library.
$(NAME): LDLIBS += $(LIBFT)
$(NAME): $(OBJS) $(HDRS)
$(CC) $(CFLAGS) $(INCLUDES) $(OBJS) $(LIBS) $(LDLIBS) -o $(NAME)
clean:
rm -rf $(OBJ_DIR)
$(MAKE) -C $(LIBFTDIR) clean
$(MAKE) -C tests clean
fclean: clean
rm -f $(NAME)
$(MAKE) -C $(LIBFTDIR) fclean
$(MAKE) -C tests fclean
$(MAKE) -C tests_integration fclean
re: fclean all copy_bonus
tests:
$(MAKE) -C tests
tests_integration:
$(MAKE) -C tests_integration
monkey:
sh monkey_tests/monkey.sh
bonus: minishell
@cp minishell minishell_bonus
.PHONY: all clean fclean re tests tests_integration copy_bonus
# This regex has been created by the maintainer of a http server
# to avoid using c functions like strcpy() etc...
# just for fun ill include it here
# see more: http://www.and.org/and-httpd/
check:
@echo Files with potentially dangerous functions.
@egrep '[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)\
|stpn?cpy|a?sn?printf|byte_)' $(SRCS) || true