-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
64 lines (50 loc) · 2.1 KB
/
makefile
File metadata and controls
64 lines (50 loc) · 2.1 KB
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
# Diretórios importantes.
SRC_DIR := src/
INCLUDE_DIR := include/
BUILD_DIR := build/
CXXFLAGS := -pedantic-errors -Wall -I$(SRC_DIR) -I$(INCLUDE_DIR)
LDLIBS := -lGL -lGLEW -lglut -lSDL2 -lm
# Arquivo main padrão.
MAIN := $(addprefix $(SRC_DIR), main.cpp)
# Arquivo .o relativo ao arquivo definido como main.
MAIN_OBJ := $(patsubst %.cpp, %, $(notdir $(MAIN)))
MAIN_OBJ := $(addprefix $(BUILD_DIR), $(MAIN_OBJ)).o
# Lista de arquivos .cpp
CPP_FILES := $(shell find $(SRC_DIR) -name "*.cpp")
# Lista de arquivos .hpp
HPP_FILES := $(shell find $(SRC_DIR) -name "*.hpp")
# Lista de arquivos .o
OBJ_FILES := $(patsubst $(SRC_DIR)%.cpp, $(BUILD_DIR)%.o, $(CPP_FILES))
# Gambiarra para tirar da lista os arquivos main.
# Tira da lista os arquivos .o que não tem .hpp correspondente.
OBJ_FILES := $(filter $(patsubst $(SRC_DIR)%.hpp, $(BUILD_DIR)%.o, $(HPP_FILES)), $(OBJ_FILES))
# Lista de headers sem arquivo de implementação correspondente.
HEADERSONLY := $(filter-out $(patsubst $(SRC_DIR)%.cpp, $(SRC_DIR)%.hpp, $(CPP_FILES)), $(HPP_FILES))
# Indicando para o make quais targets não estão associados com arquivos.
.PHONY: main clean debug
# Target padrão (tem que ser o primeiro definido).
ALL: $(BUILD_DIR) main
# Target para gerar executável para debugging.
debug: CXXFLAGS += -g
debug: ALL
# Target para ligação.
main: $(MAIN_OBJ) $(OBJ_FILES)
$(CXX) $(CXXFLAGS) $(OBJ_FILES) $(MAIN_OBJ) -o main $(LDLIBS)
# Target para compilação do arquivo main.
$(MAIN_OBJ): $(MAIN) $(HEADERSONLY)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Target para compilação dos outros arquivos .cpp
$(BUILD_DIR)%.o: $(SRC_DIR)%.cpp $(SRC_DIR)%.hpp $(HEADERSONLY)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Target para criar o diretório build.
$(BUILD_DIR):
ifeq ($(wildcard $(BUILD_DIR)),)
$(shell mkdir $(BUILD_DIR))
$(shell find $(SRC_DIR) -type d -exec mkdir -p "$(BUILD_DIR){}" \;)
$(shell mv $(BUILD_DIR)$(SRC_DIR)* $(BUILD_DIR) 2>/dev/null ; true) # "2>/dev/null" faz um possível erro do mv ser ignorado
$(shell rm -r $(BUILD_DIR)$(SRC_DIR))
endif
# Target para apagar objetos e executável.
clean:
rm -rf $(BUILD_DIR) *.o main
clear