-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (63 loc) · 1.54 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
# Source files directory
S = srcs/
# Object files directory
O = objs/
# Include files directory
I = incs/ incs/iterators incs/RBTree incs/utils
# Dependency files directory
D = deps/
# Name of your program
NAME = ft_containers
# list of your source files
SRCS = main.cpp set_tests.cpp map_tests.cpp vector_tests.cpp stack_tests.cpp
# Compiler stuff
CC = clang++
CFLAGS += -Wall -Wextra -g -std=c++98 # -g is for gdb
LDFLAGS =
# Usage of cpputest, write YES to use
CPPUTEST = YES
# The rest is automatic
ifeq ($(CPPUTEST), YES)
CPPUTEST_HOME = $(HOME)/.brew/Cellar/cpputest/4.0
CPPUTEST_HOME = ./cpputest
CFLAGS += -I$(CPPUTEST_HOME)/include/
CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
LDFLAGS = -L$(CPPUTEST_HOME)/lib/ -lCppUTest -lCppUTestExt
endif
CFLAGS += $(addprefix -I,$I)
SRCS := $(addprefix $S,$(SRCS))
OBJS := $(SRCS:$S%=$O%.o)
DEPS := $(SRCS:$S%=$D%.d)
DFLAGS = -MT $(@:$O%.o=$S%) -MMD -MP -MF $(@:$O%.o=$D%.d)
RM = /bin/rm -rf
.PHONY: all
all: $(NAME)
$(NAME): $(OBJS)
@echo "Linking $(NAME)"
@$(CC) $^ -o $@ $(LDFLAGS)
# Object directory generation
$O:
@mkdir $O
# Dependency directory generation
$D:
@mkdir $D
# Object files generation
$(OBJS): $O%.o:$S% | $O $D
@mkdir -p $(@D)
@mkdir -p $(@D:$O%=$D%)
@echo "Compiling $@"
@$(CC) $(CFLAGS) $(DFLAGS) -c $(@:$O%.o=$S%) -o $@
.PHONY: clean
clean:
@echo "Cleaning up..."
@$(RM) $D $O
.PHONY: fclean
fclean: clean
@echo "Everything!"
@$(RM) $(NAME)
.PHONY: re
re: fclean
@$(MAKE) all
.PHONY: run
run: $(NAME)
./$(NAME)