forked from mjohn218/NERDSS
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (121 loc) · 4.16 KB
/
Makefile
File metadata and controls
147 lines (121 loc) · 4.16 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# Update 2020-01-29:
# o Uses required argument of serial, omp, or mpi.
# o Use VPATH for finding cpp file in different directories -- this simplifies rules
# o Abort if gsl-config isn't available
# o Fixed (INTEL) compiler search 0=found | 1=notfound ; make conditional simple (ifeq 0|1)
# o Also use conditional for GCC
# o For objects, use basename to get base file name
# o Clean up directory prefix (shorten variable names and group)
# o Simplified obj and bin rule logic and readability.
# o put rules in canonical order
# o Now has PROF for profiling. (This is by default overrided with empty PROF.)
# o Now uses INCS. CXXFLAGS is used for C++ specific options.
# o Make executables with suffixes ( nerdss_serial | nerdss_mpi | nerdss_omp).
# -- a bit cleaner Kent milfeld@tacc.utexas.edu
#
# TODO: use function to create VPATH
# TODO: Fix MPI after learning purpose
# TODO: Make rules for *.hpp's
#
# Set terminal width to 220 to avoid viewing wrapped lines in output. A width of 200 avoids most wrapping.
#
# Update 2025-08-25:
# o dded new PHONY: "debug" and "profile".
# o Use `make serial debug` to debug with gdb
# o use `make serial profile` to profile
#
BDIR = bin
ODIR = obj
SDIR = src
EDIR = EXEs
PROF =
.PHONY: any debug profile clean
# ---------------- REQUIREMENTS: gsl and directories
hasGSL = $(shell type gsl-config >/dev/null 2>&1; echo $$?)
ifeq ($(hasGSL),1)
$(error " GSL must be installed, and gsl-config must be in path.")
else
$(shell mkdir -p bin)
$(shell mkdir -p obj)
endif
# ---------------- EXECUTABLE SETUP
INCLUDE_FOLDERS = boundary_conditions classes error math parser reactions system_setup trajectory_functions io
ifneq (,$(filter serial,$(MAKECMDGOALS)))
_EXEC = nerdss
endif
ifneq (,$(filter mpi,$(MAKECMDGOALS)))
_EXEC = nerdss_mpi
DEFS = -Dmpi_
INCLUDE_FOLDERS += debug io_mpi mpi
endif
ifneq (,$(filter clean,$(MAKECMDGOALS)))
MAKECMDGOALS = dummy
endif
ifneq (,$(filter debug,$(MAKECMDGOALS)))
ENABLE_DEBUG = true
endif
ifneq (,$(filter profile,$(MAKECMDGOALS)))
ENABLE_PROFILING = true
endif
SRCS = $(foreach dir,$(INCLUDE_FOLDERS),$(wildcard $(SDIR)/$(dir)/*.cpp))
EXEC = $(patsubst %,$(BDIR)/%,$(_EXEC))
OS := $(shell uname)
INTEL = $(shell type icpc >/dev/null 2>&1; echo $$?)
GCC = $(shell type g++ >/dev/null 2>&1; echo $$?)
INCS = $(shell gsl-config --cflags) -Iinclude
CXXFLAGS = -std=c++0x
LIBS = $(shell gsl-config --libs)
# ---------------- COMPILER SETUP
override PROF =
ifeq ($(GCC),0)
CC = g++
ifeq (mpi,$(MAKECMDGOALS))
CC = mpicxx
endif
CFLAGS = -O3 # use -O2 if profiling is confused by optimization
endif
ifeq ($(INTEL),0)
CC = icpc
ifeq (mpi,$(MAKECMDGOALS))
CC = mpicxx
endif
CFLAGS = -O3 # use -O2 if profiling is confused by optimization
endif
# ---------------- Feature toggles
# Set debug flags if ENABLE_DEBUG is true
ifdef ENABLE_DEBUG
CFLAGS = -g -O0 -fsanitize=address -fno-omit-frame-pointer
CXXFLAGS += -DDEBUG
endif
# Set profiling flags if ENABLE_PROFILING is true
ifdef ENABLE_PROFILING
PROF += -pg
CFLAGS += -DENABLE_PROFILING
LIBS += $(shell pkg-config --libs libprofiler)
endif
# ---------------- OBJECT FILES
OBJS = $(patsubst $(SDIR)/%.cpp,$(ODIR)/%.o,$(SRCS))
# ---------------- RULES
syntax:
@echo "------------------------------------"
@printf '\033[31m%s\033[0m\n' " USAGE: make serial|mpi [debug] [profile]"
@echo "------------------------------------"
exit 0
$(MAKECMDGOALS): $(EXEC)
@echo "Finished making (re-)building $(MAKECMDGOALS) version, $(EXEC)."
$(EXEC): $(OBJS)
@echo "Compiling $(EDIR)/$(@F).cpp"
$(CC) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) -o $@ $(EDIR)/$(@F).cpp $(OBJS) $(LIBS) $(PLANG)
@echo "------------"
$(ODIR)/%.o: $(SDIR)/%.cpp
@echo "Compiling $< to $@"
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(CXXFLAGS) $(INCS) $(PROF) -c $< -o $@ $(PLANG) $(DEFS)
@echo "------------"
clean:
rm -rf $(ODIR) bin
# Reference: https://www.gnu.org/software/make/manual/html_node/Quick-Reference.html
# https://www.gnu.org/software/make/
# https://www.cmcrossroads.com/article/basics-vpath-and-vpath
# https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html