forked from GiovanniMarchetto/advanced_programming_exam_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
129 lines (100 loc) · 3.92 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
# Compile and link options
# Name for final executable file
TARGET_EXEC = final_program.x
# Compile options
CXX = c++
CXX_FLAGS = -Wall -Wextra -g -std=c++17 -DNDEBUG
# Define target directory
BUILD_DIR = bin
# Define source directories where to find source files
SRC_DIRS = ./src ./test ./include
# Parameters for plotting benchmark results
BENCHMARK_OUTPUT_DIR = benchmark_results
PLOT_RESOLUTION_DPI = 300
PLOT_FORMAT = png
PYTHON_SCRIPT_BENCHMARK_RESULTS = test/plot_benchmark_results.py ${BENCHMARK_OUTPUT_DIR} ${PLOT_RESOLUTION_DPI} ${PLOT_FORMAT}
# Documentation options
# Folder with everything about documentation
DOC_DIR = Documentation
# Init file with parameters for documentation
DOC_INIT_FILE = $(DOC_DIR)/doxy.in
# Output folder with generated documentation
DOC_OUT_DIR = $(DOC_DIR)/out
# Desired name for the output PDF file containing the documentation
DOC_OUT_FILE_NAME = BST_documentation.pdf
###############################################################################
## END of configurable parameters ##
## --------------------- DO NOT MODIFY UNDER THIS LINE --------------------- ##
###############################################################################
# Find all C++ files we want to compile
SRCS = $(shell find $(SRC_DIRS) -maxdepth 1 -path "*.cpp")
# String substitution for every C++ file
OBJS = $(SRCS:%.cpp=$(BUILD_DIR)/%.o)
# String substitution for every object file
EXECS = $(OBJS:.o=.x)
# Every folder containing source files will need to be passed to GCC so that it can find header files
# Now include all required files, without searching in excluded dirs
INC_DIRS = $(shell find $(SRC_DIRS) -type d)
# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
INC_FLAGS = $(addprefix -I,$(INC_DIRS))
# Final build step
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CXX) $(OBJS) -o $@ $(CXX_FLAGS)
# Build step for C++ source
$(BUILD_DIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(INC_FLAGS) $(CXX_FLAGS) -c $< -o $@
.PHONY: all
all: clean build run
.PHONY: all_with_valgrind
all_with_valgrind: clean build valgrind
.PHONY: all_with_charts
all_with_charts: clean build run benchmark_plot
.PHONY: clean
clean:
rm -rf $(BENCHMARK_OUTPUT_DIR)
rm -rf $(BUILD_DIR)
.PHONY: build
build:
make
.PHONY: run
run:
$(BUILD_DIR)/$(TARGET_EXEC)
.PHONY: valgrind
valgrind:
valgrind $(BUILD_DIR)/$(TARGET_EXEC)
.PHONY: benchmark_plot
benchmark_plot:
python ${PYTHON_SCRIPT_BENCHMARK_RESULTS}
.PHONY: build_with_documentation
build_with_documentation: clean build documentation
.PHONY: documentation
documentation:
# Remove old doxygen folder if it exists
rm -rf $(DOC_DIR)
# Create new doxygen folder if it does not exist
mkdir $(DOC_DIR)
# Generate init file for Doxygen
doxygen -g $(DOC_INIT_FILE)
# Append configuration options to doxygen init file (see Doxygen manual)
@echo 'PROJECT_NAME = "Binary Search Tree"' >> $(DOC_INIT_FILE)
@echo 'OUTPUT_DIRECTORY = "$(DOC_OUT_DIR)"' >> $(DOC_INIT_FILE)
@echo 'INPUT = "."' >> $(DOC_INIT_FILE)
@echo 'RECURSIVE = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_ALL = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_PRIVATE = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_PACKAGE = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_STATIC = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_LOCAL_CLASSES = YES' >> $(DOC_INIT_FILE)
@echo 'EXTRACT_LOCAL_METHODS = YES' >> $(DOC_INIT_FILE)
# Create folder where to save the generated documentation
mkdir $(DOC_OUT_DIR)
# Generate documentation
doxygen $(DOC_INIT_FILE)
# Invoke doxygen makefile to create the PDF file with the documentation
make --directory=$(DOC_OUT_DIR)/latex
# Rename the file containing the documentation
mv $(DOC_OUT_DIR)/latex/refman.pdf $(DOC_OUT_DIR)/latex/$(DOC_OUT_FILE_NAME)
# Copy the pdf file with the documentation in the proper directories
cp -i $(DOC_OUT_DIR)/latex/$(DOC_OUT_FILE_NAME) $(DOC_OUT_DIR)
cp -i $(DOC_OUT_DIR)/latex/$(DOC_OUT_FILE_NAME) $(DOC_DIR)