-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
92 lines (58 loc) · 1.74 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
ROOT = .
SRC_DIR = sources
CC = gcc
NAME = example
REAL = $(ROOT)/build
LIB = liballocator.a
SRC = $(SRC_DIR)/mmap_allocator.c \
$(SRC_DIR)/mmap_utils.c \
$(SRC_DIR)/mmap_calloc.c \
$(SRC_DIR)/mmap_init.c \
$(SRC_DIR)/mmap_free.c
SRC_BIN = $(SRC_DIR)/example.c
WARN = -W -Wall -Wextra
CFLAGS = -I $(ROOT)/includes $(WARN) -g
LDFLAGS =
LIB ?= 1
TEST ?= 0
DEB ?= 0
G = -g
V ?= @
OBJS = $(patsubst $(SRC_DIR)/%.c, $(REAL)/%.o, $(SRC))
#COLOR
GREEN = \e[1;32m
WHITE = \e[1;3\e[0m
ORANGE = \e[1;3\e[1;33m
RED = \e[1;3\e[1;35m
BLUE = \e[1;3\e[1;34m
debug: CFLAGS += $(G)
all: $(LIB)
$(LIB): $(OBJS)
$(V)printf "$(GREEN)Compile sources.$(WHITE)\n"
$(V)ar rc -o $(LIB) $(OBJS)
$(V)printf "$(GREEN)Linking obj and Libraries.$(WHITE)\n"
$(NAME): $(LIB)
$(V)$(CC) -o $(REAL)/example.o -c $(SRC_DIR)/example.c $(CFLAGS)
$(V)$(CC) -o $@ $(OBJS) $(REAL)/example.o $(CFLAGS) -L . -l allocator
$(V)printf "$(GREEN)Dup $(NAME) into root directory.$(WHITE)\n"
debug: fclean echo_d $(NAME)
$(REAL)/%.o: $(SRC_DIR)/%.c
$(V)mkdir -p $(dir $@)
$(V)printf "$(BLUE)Compiling [$(GREEN)$(notdir $<)$(BLUE) -> $(RED)$(notdir $@)$(BLUE)]\n$(WHITE)"
$(V)$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS)
clean:
$(V)rm -rf $(OBJS)
$(V)rm -rf $(REAL)/example.o
$(V)printf "$(ORANGE)Removing object files.$(WHITE)\n"
fclean: clean
$(V)rm -f $(LIB)
$(V)rm -f $(REAL)/$(NAME)
$(V)rm -f $(ROOT)/$(NAME)
$(V)printf "$(ORANGE)Removing binary file.$(WHITE)\n"
re: fclean
$(V)make --no-print-directory all
echo_build:
$(V)printf "$(GREEN)Begin of the build !\n$(ORANGE)Warnings : \n$(WHITE)"
echo_d:
$(V)printf "$(RED)DEBUG MODE initialized.$(WHITE)\n";
.PHONY: clean fclean debug all re echo_debug buildrepo