-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·150 lines (124 loc) · 4.61 KB
/
Makefile
File metadata and controls
executable file
·150 lines (124 loc) · 4.61 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
148
149
150
_mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
I := $(patsubst %/,%,$(dir $(_mkfile_path)))
ifneq ($(words $(MAKECMDGOALS)),1)
.DEFAULT_GOAL = all
%:
@$(MAKE) $@ --no-print-directory -rRf $(firstword $(MAKEFILE_LIST))
else
ifndef ECHO
T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory \
-nrRf $(firstword $(MAKEFILE_LIST)) \
ECHO="COUNTTHIS" | grep -c "COUNTTHIS")
N := x
C = $(words $N)$(eval N := x $N)
ECHO = python $(I)/progress.py --stepno=$C --nsteps=$T
endif
NAME = libft.a
SHARED_NAME = libft.so
CC = cc
CFLAGS = -Wall -Werror -Wextra -fpic
OBJDIR = build
INCLUDES = include
INCLUDES_FLAGS = -I$(INCLUDES) -I/usr/include
SRC = src
# Tests
TEST_SRC = tests
TEST_OBJDIR = $(OBJDIR)/tests
TEST_FLAGS = -L. -lft -lcmocka -lbsd
SRC_CHAR = char/ft_isalnum.c char/ft_isalpha.c char/ft_isascii.c \
char/ft_isdigit.c char/ft_isprint.c char/ft_toupper.c \
char/ft_tolower.c char/ft_iswhitespace.c
SRC_FD = print/ft_putchar_fd.c print/ft_putstr_fd.c print/ft_putnbr_fd.c \
print/ft_putendl_fd.c
SRC_LISTS = lists/ft_lstadd_back.c lists/ft_lstadd_front.c \
lists/ft_lstclear.c lists/ft_lstdelone.c \
lists/ft_lstlast.c lists/ft_lstmap.c lists/ft_lstnew.c \
lists/ft_lstsize.c lists/ft_lstget.c lists/ft_lstiter.c
SRC_MEM = memory/ft_memchr.c memory/ft_memcmp.c memory/ft_memcpy.c \
memory/ft_calloc.c memory/ft_memmove.c memory/ft_memset.c \
memory/ft_realloc.c memory/ft_bzero.c
SRC_NUM = numbers/ft_atoi.c numbers/ft_itoa.c numbers/ft_atol.c
SRC_STR = string/ft_free_split.c string/ft_split.c string/ft_strchr.c \
string/ft_strdup.c string/ft_striteri.c string/ft_strjoin.c \
string/ft_strlcat.c string/ft_strlcpy.c string/ft_strlen.c \
string/ft_strmapi.c string/ft_strncmp.c string/ft_strnstr.c \
string/ft_strrchr.c string/ft_strtrim.c string/ft_substr.c \
string/ft_strclean.c
SRC_PRINTF = printf/ft_printf.c printf/put_utils.c printf/utils.c
SRC_GNL = gnl/get_next_line.c gnl/get_next_line_utils.c gnl/gnl_utils.c
SRC_HASH = hash/ft_hash_add_node.c hash/ft_hash_create_node.c \
hash/ft_hash_delete.c hash/ft_hash_get_item.c \
hash/ft_hash_get_node.c hash/ft_hash_new.c hash/ft_hash_print.c \
hash/ft_hash_remove_node.c hash/hash_utils1.c
SRC_VECTOR = vector/ft_create_vector.c vector/ft_vector_private.c
SOURCES = $(addprefix $(SRC)/, $(SRC_GNL)) \
$(addprefix $(SRC)/, $(SRC_PRINTF)) \
$(addprefix $(SRC)/, $(SRC_STR)) \
$(addprefix $(SRC)/, $(SRC_CHAR)) \
$(addprefix $(SRC)/, $(SRC_LISTS)) \
$(addprefix $(SRC)/, $(SRC_MEM)) \
$(addprefix $(SRC)/, $(SRC_NUM)) \
$(addprefix $(SRC)/, $(SRC_FD)) \
$(addprefix $(SRC)/, $(SRC_HASH)) \
$(addprefix $(SRC)/, $(SRC_VECTOR)) \
OBJECTS = $(addprefix $(OBJDIR)/, $(SRC_GNL:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_PRINTF:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_STR:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_CHAR:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_LISTS:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_MEM:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_NUM:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_FD:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_HASH:.c=.o)) \
$(addprefix $(OBJDIR)/, $(SRC_VECTOR:.c=.o)) \
# Test files
TEST_FILES = fd.c memory.c strings.c # gnl.c lists.c numbers.c printf.c
TEST_OBJECTS = $(addprefix $(TEST_OBJDIR)/, $(TEST_FILES:.c=.o))
TEST_EXECUTABLES = $(addprefix $(TEST_OBJDIR)/, $(TEST_FILES:.c=.test))
all: $(NAME) $(SHARED_NAME)
$(NAME): $(OBJECTS)
@$(ECHO) "Linking Libft"
@ar rcs $(NAME) $(OBJECTS)
@$(ECHO) "Done!"
$(SHARED_NAME): $(OBJECTS)
@$(ECHO) "Creating shared library"
@$(CC) -shared -o $(SHARED_NAME) $(OBJECTS)
@$(ECHO) "Done!"
$(OBJDIR):
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: $(SRC)/%.c
@mkdir -p $(@D)
@$(ECHO) "$@"
@$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES_FLAGS)
clean:
@rm -rf $(OBJDIR)
debug: CFLAGS += -g3
debug: fclean $(NAME)
fclean: clean
@rm -f $(NAME) $(SHARED_NAME)
re: fclean all
# Compile individual test files
$(TEST_OBJDIR)/%.o: $(TEST_SRC)/%.c | $(TEST_OBJDIR)
@mkdir -p $(@D)
@echo "Compiling test: $<"
@$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES_FLAGS)
# Create test executables
$(TEST_OBJDIR)/%.test: $(TEST_OBJDIR)/%.o $(NAME)
@echo "Linking test: $@"
@$(CC) $< -o $@ $(TEST_FLAGS) $(INCLUDES_FLAGS)
# Individual test targets
test_%: $(NAME) $(TEST_OBJDIR)/%.test
@echo "Running test: $@"
@./$(TEST_OBJDIR)/$*.test
# Directory creation
$(TEST_OBJDIR):
@mkdir -p $(TEST_OBJDIR)
# Run all tests
test: $(TEST_EXECUTABLES)
@echo "Running all tests..."
@for test in $(TEST_EXECUTABLES); do \
echo "Executing $$test:"; \
./$$test; \
done
.PHONY: all clean fclean re test debug #$(addprefix test_,$(basename $(TEST_FILES)))
endif