-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
95 lines (79 loc) · 2.55 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
# Makefile for LB-t lattice-Boltzmann solver (without VTK and nlohmann-json libraries)
# Tobit Flatscher - github.com/2b-t (2022)
# Compiler settings: ICC or GCC (alternatively 'make COMPILER=ICC run' in console)
COMPILER = GCC
# Define sub-directories to be included in compilation
INCLUDEDIR = ./include
SRCDIR = ./src
BUILDDIR = ./build
OBJDIR = $(BUILDDIR)/obj
BINDIR = $(BUILDDIR)/bin
SOURCES = $(SRCDIR)/simple_main.cpp $(wildcard $(SRCDIR)/**/*.cpp)
INCLUDES = $(shell find $(INCLUDEDIR) -name *.hpp)
OBJECTS = $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
PROGRAM = main.$(COMPILER)
# Compiler flags
WARNINGS = -Wall -pedantic -Wextra -Weffc++ -Woverloaded-virtual -Wfloat-equal -Wshadow -Wredundant-decls -Winline -fmax-errors=1
CXXFLAGS += -std=c++17 -O3 -flto -fwhole-program -funroll-all-loops -finline-functions -mavx2 -march=native -fno-exceptions -DNDEBUG
CXXFLAGS += -funsafe-math-optimizations -fassociative-math -freciprocal-math -obey-inline -fstrict-aliasing -fearly-inlining
CXXFLAGS += -DLBT_FORCE_NO_VTK
CXXFLAGS += -I$(INCLUDEDIR)
LDFLAGS += -O3 -flto
# Compiler settings for specific compiler
ifeq ($(COMPILER),ICC)
# Intel compiler ICC
CXX = icpc
LD = icpc
CXXFLAGS += -fopenmp
LDFLAGS += -qopenmp
COMPILER = ICC
else
# Gnu compiler GCC
CXX = g++
LD = g++
CXXFLAGS += -fopenmp
LDFLAGS += -lgomp
COMPILER = GCC
endif
## Make commands
# Default rule 'make'
default: $(BINDIR)/$(PROGRAM)
$(BINDIR)/$(PROGRAM): $(OBJECTS)
@mkdir -p $(@D)
$(LD) $(OBJECTS) $(LDFLAGS) -o $@
@echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(@D)
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "Compiled "$<" successfully!"
# Suffix rule
.cpp.o:
$(CXX) -c $(CXXFLAGS) $<
# Remove executables generated by 'make run' rule
clean:
@echo "Deleting compiled files '$(BINDIR)/$(PROGRAM)' and '$(OBJECTS)'..."
@rm -f $(BINDIR)/$(PROGRAM) $(OBJECTS)
# Remove directories and contents generated by 'make run' rule
purge:
@echo "Deleting directory build directory '$(BUILDDIR)'..."
@rm -rf $(BUILDDIR)
# Run executable
run: clean $(BINDIR)/$(PROGRAM)
@echo "Running executable '$(BINDIR)/$(PROGRAM)'..."
./$(BINDIR)/$(PROGRAM)
# Benchmark performance
benchmark: clean $(BINDIR)/$(PROGRAM)
@echo "Starting benchmark..."
./$(BINDIR)/$(PROGRAM) --b
# Generate Doxygen documentation
doc:
@echo "Generating Doxygen documentation..."
doxygen Doxyfile
# Show info about compiler
info:
@echo "Compiler version: "
$(CXX) --version
@echo "Compiler flags: "
@echo $(CXXFLAGS)
@echo "Linker flags: "
@echo $(LDFLAGS)