-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
72 lines (51 loc) · 1.75 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
SHELL := /bin/bash
SRC = $(shell find $(SRC_DIR) -type f -name "*.cpp")
INC = $(shell find $(INC_DIR) -type f -name "*.hpp")
TEST = $(shell find $(TEST_DIR) -type f -name "*.cpp")
OBJ = $(SRC:%.cpp=obj/%.o)
OBJ_TEST = $(TEST:%.cpp=obj/%.o)
CCPP = clang++
CPPFLAGS = -Wall -Wextra -Werror -std=c++98 -g
NAME = main.out
INC_DIR = inc
SRC_DIR = src
TEST_DIR = test
RED = \033[0;31m
GREEN = \033[0;32m
BYELLOW = \033[0;43;30m
NC = \033[0m
# Rules
all: $(NAME)
test: $(OBJ_TEST)
obj/src/%.o: src/%.cpp $(INC) Makefile
@mkdir -pv $(dir $@)
@$(CCPP) $(CPPFLAGS) -I$(INC_DIR) -c $< -o $@
obj/test/%.o: test/%.cpp $(INC) Makefile
$(eval FNAME=$(subst .o,,$@))
@mkdir -pv $(dir $@)
$(eval CPPFLAGS=$(subst -std=c++11,-std=c++98,$(CPPFLAGS)))
@$(CCPP) $(CPPFLAGS) -D_IS_TEST -I$(INC_DIR) -c $< -o $@
@$(CCPP) $(CPPFLAGS) $@ -o $(FNAME)_ft
@./$(FNAME)_ft > $(FNAME)_ft.log
$(eval CPPFLAGS=$(subst -std=c++98,-std=c++11,$(CPPFLAGS)))
@$(CCPP) $(CPPFLAGS) -I$(INC_DIR) -c $< -o $@
@$(CCPP) $(CPPFLAGS) $@ -o $(FNAME)_std
@./$(FNAME)_std > $(FNAME)_std.log
@(diff $(FNAME)_std.log $(FNAME)_ft.log > $(FNAME).diff \
&& printf "$(GREEN)$(FNAME).diff$(NC)\n" && rm $(FNAME).diff) \
|| (printf "$(RED)$(FNAME).diff$(NC)\n" && cat $(FNAME).diff)
@printf "$(BYELLOW)[ ----- Time ----- ]$(NC)\n"
@(time ./$(FNAME)_std > /dev/null) 2>&1 | grep "real" | sed 's/real/std/'
@(time ./$(FNAME)_ft > /dev/null) 2>&1 | grep "real" | sed 's/real/ft /'
$(NAME): $(OBJ)
@$(CCPP) $(CPPFLAGS) $(OBJ) -o $(NAME)
clean:
@rm -vrf obj
@rm -vrf $(OBJ_TEST)
fclean: clean
@rm -vrf $(NAME)
@rm -vrf $(subst .o,,$(OBJ_TEST))
run: all
@./$(NAME)
re: fclean all
.PHONY: clean fclean run re test