-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
115 lines (79 loc) · 2.77 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
##
## EPITECH PROJECT, 2018
## CPE_corewar_2017
## File description:
## Corewar Folder Makefile
##
## VARIABLES
NAME = mysh
UNITS = units
SRC_DIR = src/
TEST_DIR = tests/
SRC_FILES = main.c \
minishell.c \
utils/struct_utils.c \
utils/parsing_utils.c \
utils/get_next_line.c \
builtin/exit_command.c \
builtin/cd_command.c \
builtin/setenv_command.c \
builtin/unsetenv_command.c \
builtin/printenv_command.c \
builtin/echo_command.c \
managers/env_manager.c \
managers/prompt_manager.c \
managers/redirect_manager.c \
managers/check_binaries.c \
managers/command_manager.c \
actions/environment_actions.c \
handlers/signal_handler.c
SRC = $(addprefix $(SRC_DIR), $(SRC_FILES))
TESTS_FILES = $(filter-out main.c, $(SRC_FILES))
TESTS_FILES += ""
INCLUDE = include/
LIBRARY_DIR = lib/
CC = gcc
CFLAGS = -Wall -Wextra -I $(INCLUDE) -g3
LFLAGS = -L $(LIBRARY_DIR) -lmy
UNITS_LFLAGS = $(LFLAGS) -lgcov -lcriterion
## BUILD VARIABLES
BUILD_DIR = build/
BUILD_TESTS_DIR = tests/build/
BUILD_OBJ = $(addprefix $(BUILD_DIR), $(SRC_FILES:.c=.o))
BUILD_TESTS_OBJ = $(addprefix $(BUILD_TESTS_DIR), $(TESTS_FILES:.c=.o))
BUILD_SD = $(shell find $(SRC_DIR) -mindepth 1 -type d -printf '%p\n' | sed -e 's/^src\///')
## RULES
all: library $(BUILD_DIR) $(NAME)
library:
make -C $(LIBRARY_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(foreach SUB_DIR, $(BUILD_SD), $(shell mkdir -p $(BUILD_DIR)$(SUB_DIR)))
$(BUILD_DIR)%.o: $(SRC_DIR)%.c
$(CC) $(CFLAGS) -c -o $@ $<
$(NAME): $(BUILD_OBJ)
$(CC) $(CFLAGS) -o $(NAME) $(BUILD_OBJ) $(LFLAGS)
tests_run: fclean library $(UNITS)
find $(BUILD_TESTS_DIR) -name '*.gc*' -exec mv -t ./ {} +
./$(UNITS)
$(UNITS): $(BUILD_TESTS_DIR) $(BUILD_TESTS_OBJ)
$(CC) $(CFLAGS) -o $(UNITS) $(BUILD_TESTS_OBJ) --coverage $(UNITS_LFLAGS)
$(BUILD_TESTS_DIR):
mkdir -p $(BUILD_TESTS_DIR)$(TEST_DIR)
$(foreach SUB_DIR, $(BUILD_SD), $(shell mkdir -p $(BUILD_TESTS_DIR)$(SUB_DIR)))
$(BUILD_TESTS_DIR)%.o: $(SRC_DIR)%.c
$(CC) $(CFLAGS) --coverage -c -o $@ $<
$(BUILD_TESTS_DIR)%.o: $(TEST_DIR)%.c
$(CC) $(CFLAGS) --coverage -c -o $@ $<
clean:
rm -rf $(BUILD_DIR)
rm -rf $(BUILD_TESTS_DIR)
find -name '*.gc*' -delete -or -name 'vgcore.*' -delete -o -name '*.o' -delete
make clean -C $(LIBRARY_DIR)
fclean: clean
rm -rf $(NAME)
rm -rf $(UNITS)
make fclean -C $(LIBRARY_DIR)
re: fclean all
# Just in case those files exist in the root dir
.PHONY : all library clean fclean re tests_run