-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (75 loc) · 2.45 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
# -- bropdox --
#
# Makefile do projeto bropdox.
#
# Exemplo de utilização:
# make [<target>] [DFLAG=true]
#
# @param target
# Pode ser as seguintes opções:
# all - compila.
# clean - limpa os binários gerados na compilação.
# redo - limpa binários e então compila.
# print-<var> - imprime o conteúdo da variável do makefile (exemplo de uso: make print-OBJ).
#
# @param "DFLAG=true"
# Quando presente, o programa será compilado em modo debug.
#
# Se make não recebe parâmetros de target, a ação default é all
####################################################################################################
# Definições:
# -- Diretorios do projeto
INC_DIR := include
OBJ_DIR := bin
OUT_DIR := build
SRC_DIR := src
LIB_DIR := lib
DFLAG :=
# -- Flags de compilação
# Compilador e versão da linguagem
CC := g++ -std=c++17
# Caso DFLAG esteja definida, ativa compilação debug e coloca o address sanitizer junto ao executável
DEBUG := $(if $(DFLAG),-g -fsanitize=address)
CFLAGS :=\
-Wall \
-Wextra \
-Wpedantic\
-Wshadow \
-Wunreachable-code
OPT := $(if $(DFLAG),-O0,-O3)
LIB := -L$(LIB_DIR)\
-linotify-cpp \
-lboost_system \
-lboost_filesystem \
-lpthread
INC := -I$(INC_DIR)
####################################################################################################
# Arquivos:
# -- Fonte da main
# Presume que todos os fontes "main" estão na raiz do diretório SRC_DIR
MAIN := $(wildcard $(SRC_DIR)/*.cpp)
# -- Caminho(s) do(s) binário(s) final/finais
TARGET := $(patsubst %.cpp, $(OUT_DIR)/%, $(notdir $(MAIN)))
# -- Outros arquivos fonte
SRC := $(filter-out $(MAIN), $(shell find $(SRC_DIR) -name '*.cpp'))
# -- Objetos a serem criados
OBJ := $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(notdir $(SRC)))
####################################################################################################
# Regras:
# -- Executáveis
$(TARGET): $(OUT_DIR)/%: $(SRC_DIR)/%.cpp $(OBJ)
$(CC) -o $@ $^ $(INC) $(LIB) $(DEBUG) $(OPT)
# -- Objetos
$(OBJ_DIR)/%.o:
$(CC) -c -o $@ $(filter %/$*.cpp, $(SRC)) $(INC) $(CFLAGS) $(DEBUG) $(OPT)
####################################################################################################
# Alvos:
.DEFAULT_GOAL = all
all: $(TARGET)
clean:
rm -f $(OBJ_DIR)/*.o $(INC_DIR)/*~ $(TARGET) *~ *.o
redo: clean all
# Debug de variaveis da make
print-%:
@echo $* = $($*)
.PHONY: all clean redo print-%