-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (93 loc) · 2.59 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
#******************************* VARIABLES **********************************#
NAME = libasm.a
TEST_NAME = tests_bin
# --------------- FILES --------------- #
LIST_ASM_SRC = \
ft_atoi_base.s \
ft_create_elem.s \
ft_list.s \
ft_list_push_front.s \
ft_list_remove_if.s \
ft_list_size.s \
ft_list_sort.s \
ft_read.s \
ft_strcmp.s \
ft_strcpy.s \
ft_strdup.s \
ft_strlen.s \
ft_write.s
LIST_TEST_SRC = \
ft_atoi_base.c \
ft_create_elem.c \
ft_list_push_front.c \
ft_list_remove_if.c \
ft_list_size.c \
ft_list_sort.c \
ft_read.c \
ft_strcmp.c \
ft_strcpy.c \
ft_strdup.c \
ft_strlen.c \
ft_write.c \
main.c \
utils.c
# ------------ DIRECTORIES ------------ #
DIR_BUILD = .build/
DIR_SRC = src/
DIR_INCLUDE = include/
DIR_TEST = test/
DIR_LIB = lib/
DIR_UTEST = $(DIR_LIB)utest/
# ------------- SHORTCUTS ------------- #
OBJ = $(patsubst %.s, $(DIR_BUILD)%.o, $(SRC))
DEP = $(patsubst %.s, $(DIR_BUILD)%.d, $(SRC))
SRC = $(addprefix $(DIR_SRC), $(LIST_ASM_SRC))
TEST_SRC = $(addprefix $(DIR_TEST), $(LIST_TEST_SRC))
TEST_DEP = $(patsubst %.c, $(DIR_BUILD)%.d, $(TEST_SRC))
TEST_OBJ = $(patsubst %.c, $(DIR_BUILD)%.o, $(TEST_SRC))
UTEST_INCLUDE = $(DIR_UTEST)
# ------------ COMPILATION ------------ #
AS = nasm
ASFLAGS = -f elf64 -I $(DIR_SRC)
CFLAGS = -Wall -Wextra -Werror
DEP_FLAGS = -MMD -MP
ARFLAGS = rcs
# ------------- COMMANDS ------------- #
RM = rm -rf
MKDIR = mkdir -p
#*********************************** RULES **********************************#
.PHONY: all
all: $(NAME)
.PHONY: tests
tests: $(TEST_NAME)
valgrind ./$(TEST_NAME)
$(TEST_NAME): $(TEST_OBJ) $(NAME)
$(CC) $(CFLAGS) $(TEST_OBJ) -L. -l:$(NAME) -o $(TEST_NAME)
# ---------- VARIABLES RULES ---------- #
$(NAME): $(OBJ)
$(AR) $(ARFLAGS) $(NAME) $(OBJ)
# ---------- COMPILED RULES ----------- #
-include $(DEP)
$(DIR_BUILD)%.o: %.s
mkdir -p $(shell dirname $@)
$(AS) $(ASFLAGS) -MD $(@:.o=.d) $< -o $@
-include $(TEST_DEP)
$(DIR_BUILD)%.o: %.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) $(DEP_FLAGS) -c $< -o $@ -I $(DIR_INCLUDE) -I $(UTEST_INCLUDE)
.PHONY: clean
clean:
$(RM) $(DIR_BUILD)
.PHONY: fclean
fclean: clean
$(RM) $(NAME)
$(RM) $(TEST_NAME)
.PHONY: re
re: fclean
$(MAKE) all
.PHONY: check-format
check-format:
clang-format -style=file $(TEST_SRC) -n --Werror
.PHONY: format
format:
clang-format -style=file $(TEST_SRC) -i