-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (77 loc) · 2.24 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
CXX ?= g++
# path #
SRC_PATH = src
BUILD_PATH = build
BIN_PATH = $(BUILD_PATH)/bin
OUTPUT_PATH = output/results
# executable #
BIN_NAME = prvr.out
# extensions #
SRC_EXT = cpp
# Find all source files in the source directory, sorted by most recently modified
SOURCES = $(shell find $(SRC_PATH) -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
# Set the object file names, with the source directory stripped from the path, and the build path prepended in its place
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)
# flags #
# for debuggin only: CXXFLAGS = -Wall -O0 -g3 -std=c++11
CXXFLAGS = -Wall -O0 -std=c++11
INCLUDES = -I include/ -I /usr/local/include
# LIBS = -lpthread -lconfig++
# LIBS = -DDEBUG
LDFLAGS = $(LIBS)
.PHONY: default_target
default_target: release
.PHONY: release
release: export CXXFLAGS := $(CXXFLAGS)
release: dirs
@$(MAKE) all
.PHONY: dirs
dirs:
@echo "Criando pastas"
@mkdir -p $(OUTPUT_PATH)
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)
.PHONY: clean
clean:
@echo "Deletando atalho $(BIN_NAME)"
@$(RM) $(BIN_NAME)
@echo "Deletando pastas e arquivos"
@$(RM) -r $(BUILD_PATH)
@$(RM) -r $(BIN_PATH)
# checks the executable and symlinks to the output
.PHONY: all
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Criando atalho: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
# Creation of the executable
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linkando: $@"
@$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
# Add dependency files, if they exist
-include $(DEPS)
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compilando: $< -> $@"
@$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@
remake:
@$(MAKE) clean
@$(MAKE)
teste:
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
run-clear: remake
@clear
@./$(BIN_NAME) ${ARGS}
run:
@$(MAKE)
@./$(BIN_NAME) ${ARGS}
val: remake
@clear
valgrind --leak-check=yes --track-origins=yes ./$(BIN_NAME)
val-full: remake
@clear
valgrind --leak-check=yes --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(BIN_NAME)