-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
187 lines (140 loc) · 5.83 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
NAME = minishell
GTEST = libs/googletest
FT_DIR = libft
READLINE_DIR = libs/readline
GTEST_DIR = libs/googletest
LIB_FT = $(FT_DIR)/libft.a
LIB_READLINE = $(READLINE_DIR)/libreadline.a
LIB_GTEST = $(GTEST_DIR)/build/lib/libgtest.a $(GTEST)/build/lib/libgtest_main.a
TEST_CFLAGS = -std=c++11 -Ilibft -I$(GTEST)/googletest/include -g
TEST_LDFLAGS = -pthread -ltermcap
CFLAGS = -MD -Wall -Wextra -Werror -I$(FT_DIR) -Ilibs -g
# readline requires that it's linked with termcap
# LDFLAGS = -Llibft -fsanitize=address -ltermcap
LDFLAGS = -ltermcap
CC = gcc
SHELL = /bin/sh
TEST_DIR = tests
OBJ_DIR := obj
SRC_DIR := src
MODULES := parser executer tokenizer utils map prompt command ast built_in env error print wildcard new
SRC_DIRS := $(addprefix src/,$(MODULES))
OBJ_DIRS := $(addprefix obj/,$(MODULES))
# SRCS := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.c))
SRCS := src/ast/builder.c src/ast/builder_utils.c src/ast/free_tree.c \
src/ast/node_utils.c src/ast/print_tree.c src/ast/walk_logic.c \
src/ast/walk_utils.c src/ast/walkers.c src/built_in/built_in.c \
src/built_in/ft_cd.c src/built_in/ft_echo.c src/built_in/ft_env.c \
src/built_in/ft_exit.c src/built_in/ft_export.c src/built_in/ft_path.c \
src/built_in/ft_pwd.c src/built_in/ft_unset.c src/command/execute.c \
src/command/execute_builtin.c src/command/redirections.c src/command/file_open.c src/command/heredoc.c src/command/free_command.c \
src/env/cached_path.c src/env/env_singleton.c src/env/extract_env.c \
src/env/get_env.c src/env/get_env_length.c src/env/init_env.c src/env/path.c \
src/env/pwd.c src/env/set_env.c src/env/unset_env.c src/error/error.c \
src/error/singleton.c src/error/trace.c src/error/unexpected.c \
src/map/copy_map.c src/map/create_map.c src/map/destroy_map.c src/map/hashing.c \
src/map/map_get.c src/map/map_insert.c src/map/map_remove.c src/map/map_select.c \
src/new/is_next_pipeline.c src/new/jumpers.c src/new/new.c \
src/new/parse_and_run.c src/parser/append_to_pvec.c src/parser/expand.c \
src/parser/expand_tokens.c src/parser/is_command_token.c \
src/parser/is_redir_token.c src/parser/is_wildcard_argument.c \
src/parser/length.c src/parser/parser.c src/parser/skip_spaces.c \
src/parser/strlencpy.c src/print/print.c src/print/token_colors.c \
src/prompt/git_status.c src/prompt/git_status_format.c src/prompt/prompt.c \
src/prompt/replace_prefix.c src/tokenizer/free_tokens.c \
src/tokenizer/metacharacter.c src/tokenizer/token.c \
src/tokenizer/tokenize_control.c src/tokenizer/tokenize_paren.c \
src/tokenizer/tokenize_pipe.c src/tokenizer/tokenize_quote.c \
src/tokenizer/tokenize_redir.c src/tokenizer/tokenize_space.c \
src/tokenizer/tokenize_var.c src/tokenizer/tokenize_wildcard.c \
src/tokenizer/tokenize_word.c src/tokenizer/tokenizer.c src/utils/close.c src/utils/sort.c \
src/utils/node_type_tostr.c src/utils/print_token.c src/utils/utils.c \
src/utils/utils_print.c src/wildcard/check_end.c src/wildcard/check_match.c \
src/wildcard/check_start.c src/wildcard/compare_char.c \
src/wildcard/vector_append_all.c src/wildcard/wildcard.c src/wildcard/free_array.c
OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
INCLUDES := $(addprefix -I,$(SRC_DIRS))
ENTRY_SRCS = $(SRC_DIR)/main.c
ENTRY_OBJS = $(patsubst $(SRC_DIR)/%.c, obj/%.o, $(ENTRY_SRCS))
TEST_SRCS = $(wildcard $(TEST_DIR)/*.cpp)
TEST_OBJS = $(patsubst $(TEST_DIR)/%.cpp, $(TEST_DIR)/obj/%.o, $(TEST_SRCS))
TEST_BIN = $(TEST_DIR)/test
INPUTS_DIR = tests/inputs
vpath %.c $(SRC_DIRS)
all: $(NAME)
# Here is the actual compile rule. This is only for stuff in src/*/*.c
checkdirs: $(OBJ_DIRS)
@echo obj: $(OBJ_DIR) $(OBJ_DIRS)
@echo src: $(SRC_DIR) $(SRC_DIRS)
@echo "All srcs: " $(SRCS)
@echo "All objs: " $(OBJS)
@echo "All includes: " $(INCLUDES)
define make-goal
$1/%.o: %.c | $(OBJ_DIRS)
$(CC) $(CFLAGS) $(INCLUDES) -c $$< -o $$@
endef
$(foreach bdir,$(OBJ_DIRS),$(eval $(call make-goal,$(bdir))))
submodules:
git submodule init
git submodule sync
git submodule update
build:
rm -rf build ;\
mkdir -p build ;\
cp -r src build/src ;\
cp -r Makefile build/ ;\
cp -r .gitignore build/ ;\
cp -r .gitmodules build/ ;\
cd build ;\
git init ;\
git submodule add [email protected]:ytkimirti/libft libft ;\
git submodule add https://github.com/sailfishos-mirror/readline libs/readline ;\
git add . ;\
git commit -m "Initial"
$(NAME): $(OBJS) $(ENTRY_OBJS) $(LIB_FT) $(LIB_READLINE)
$(CC) $(OBJS) $(ENTRY_OBJS) $(LIB_FT) $(LIB_READLINE) $(LDFLAGS) -o $@
$(LIB_FT):
make -C $(FT_DIR)
$(LIB_GTEST):
mkdir -p $(GTEST_DIR)/build
cd $(GTEST_DIR)/build; \
cmake ..; \
make
$(LIB_READLINE):
cd $(READLINE_DIR); \
./configure --with-curses; \
make; \
rm -f history.pc
maketest: $(TEST_BIN)
test: $(TEST_BIN)
./$(TEST_BIN)
testerr: $(TEST_BIN)
./$(TEST_BIN) --gtest_brief=1
$(TEST_BIN): $(TEST_OBJS) $(OBJS) $(LIB_GTEST) $(LIB_READLINE)
@echo "==== LINKING TEST FILES ===="
g++ $(TEST_CFLAGS) $(OBJS) $(TEST_OBJS) $(LIB_GTEST) $(LIB_FT) $(LIB_READLINE) $(TEST_LDFLAGS) -o $@
$(TEST_DIR)/obj/%.o: $(TEST_DIR)/%.cpp | $(TEST_DIR)/obj
g++ $(TEST_CFLAGS) $(INCLUDES) -c $< -o $@
# Rules for making directiories
$(OBJ_DIRS) $(OBJ_DIR) $(TEST_DIR)/bin $(TEST_DIR)/obj:
mkdir -p $@
# Only for $(ENTRY_SRCS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
run: all
./$(NAME) < $(INPUTS_DIR)/basic1.txt
# re_nolog: CFLAGS += -DLOG=false
difftester/print_args: difftester/print_args.c
$(CC) $< -o $@
re: fclean all
clean:
rm -rf $(TEST_DIR)/obj
rm -rf $(OBJ_DIR)
rm -f difftester/print_args
fclean: clean
rm -f $(NAME)
rm -rf $(TEST_DIR)/bin
norm:
@norminette src | grep Error || ( (command -v &>/dev/null && cowsay "All clear" ) || echo "(ノ◕ヮ◕)ノ*:・゚✧ All clear")
# -include $(foreach odir,$(OBJ_DIRS),$(wildcard $(odir)/*.d))
.PHONY: all re clean fclean checkdirs run test testerr maketest norm submodules build