-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (103 loc) · 3.58 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
##
## EPITECH PROJECT, 2022
## Makefile for NanoTekSpice
## File description:
## Makefile
##
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS := $(MAKEFLAGS)
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
else
.RECIPEPREFIX = >
endif
NAME := nanotekspice
MKDIR := mkdir -p
RM := rm -f
RMDIR := rm -fr
TOUCH := touch -a
SRC_DIR := ./src
INC_DIR := -I ./inc -I ./inc/Components -I ./inc/Gates -I ./inc/ComplexComponents
OBJ_DIR := ./build
SOURCES_SUB_DIRS := $(shell find $(SRC_DIR) -type d)
OBJECTS_SUB_DIRS := $(SOURCES_SUB_DIRS:$(SRC_DIR)%=$(OBJ_DIR)%)
ifeq ($(MAKECMDGOALS), tests_run)
SOURCES := $(shell find $(SRC_DIR) -type f -not -wholename "*/main.cpp" -name "*.cpp")
else
SOURCES := $(shell find $(SRC_DIR) -type f -name "*.cpp")
endif
OBJECTS := $(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
DEPS := $(SOURCES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.d)
TEST_SRC_DIR := ./tests
TEST_OBJ_DIR := ./tests_build
TEST_SOURCES_SUB_DIRS := $(shell find $(TEST_SRC_DIR) -type d)
TEST_OBJECTS_SUB_DIRS := $(TEST_SOURCES_SUB_DIRS:$(TEST_SRC_DIR)%=$(TEST_OBJ_DIR)%)
TEST_SOURCES := $(shell find $(TEST_SRC_DIR) -type f -name "*.cpp")
TEST_OBJECTS := $(TEST_SOURCES:$(TEST_SRC_DIR)/%.cpp=$(TEST_OBJ_DIR)/%.o)
ifeq ($(MAKECMDGOALS), tests_run)
CXX := g++
CXX_WARNINGS := -Wall -Wextra -Wpedantic -Wno-unused-variable
CXXFLAGS := -fprofile-arcs -ftest-coverage
LDFLAGS := -lgcov -lcriterion
else
CXX := clang++
CXX_WARNINGS := -Wall -Wextra -Wpedantic
CXXFLAGS := -std=c++20
LDFLAGS :=
endif
CXX_DEPS = -MT $(OBJ_DIR)/$*.o -MP -MMD -MF $(OBJ_DIR)/$*.d
CXX_DEBUG := -g3 -ggdb3
CXX_OPTIMIZE := -O2 -march=native
CXXFLAGS := $(CXXFLAGS) $(CXX_DEBUG) $(CXX_OPTIMIZE) $(CXX_WARNINGS) $(INC_DIR)
LDFLAGS := $(LDFLAGS)
WHITE = \e[0m
RED = \e[38;5;203m
DARK_RED = \e[38;5;160m
ORANGE = \e[1;33m
GREEN = \e[1;32m
DARK_BLUE = \e[38;5;26m
CYAN = \e[38;5;51m
BOLD = \e[1m
all: intro $(NAME)
intro:
> @ printf "$(DARK_RED)$(BOLD)+-------------------------------+\n$(WHITE)"
> @ printf "$(DARK_RED)$(BOLD)| NanoTekSpice V0.1 |\n$(WHITE)"
> @ printf "$(DARK_RED)$(BOLD)+-------------------------------+\n$(WHITE)"
$(NAME): $(OBJECTS)
> @ $(CXX) $^ $(LDFLAGS) -o $@
> @ printf "$(ORANGE)$@ linking success\n$(WHITE)"
tests_run: $(OBJECTS) $(TEST_OBJECTS)
> @$(CXX) $(OBJECTS) $(TEST_OBJECTS) $(LDFLAGS) -o test
> @ printf "$(ORANGE)Gonna launch criterion tests\n$(WHITE)"
> ./test
tests_recap:
> @ printf "$(ORANGE)$(BOLD)Tests recap:$(WHITE)\n"
> gcovr --exclude tests --exclude inc
# > gcovr --exclude tests --exclude inc --branches
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJECTS_SUB_DIRS)
> @$(CXX) $(CXXFLAGS) $(CXX_DEPS) -c $< -o $@
> @ printf "$(DARK_BLUE)Compiling [$(CYAN)$@$(WHITE)$(DARK_BLUE)]$(WHITE)\n"
$(TEST_OBJ_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(TEST_OBJECTS_SUB_DIRS)
> @$(CXX) $(CXXFLAGS) $(CXX_DEPS) -c $< -o $@
> @ printf "$(DARK_BLUE)Compiling [$(CYAN)$@$(WHITE)$(DARK_BLUE)]$(WHITE)\n"
$(OBJECTS_SUB_DIRS):
> @$(MKDIR) $(OBJECTS_SUB_DIRS)
$(TEST_OBJECTS_SUB_DIRS):
> @$(MKDIR) $(TEST_OBJECTS_SUB_DIRS)
clean:
> @$(RMDIR) $(OBJ_DIR)
> @$(RMDIR) $(TEST_OBJ_DIR)
> @ printf "$(RED)Removing object files.$(WHITE)\n"
fclean: clean
> @$(RM) $(NAME)
> @$(RM) test
> @ printf "$(RED)Removing binary file.$(WHITE)\n"
re: fclean all
-include $(DEPS)
.PHONY: all tests_run clean fclean re