-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmakefile
More file actions
276 lines (238 loc) · 7.6 KB
/
Copy pathmakefile
File metadata and controls
276 lines (238 loc) · 7.6 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
SHELL = /bin/bash
#Default compiling options
USE_OPENMP = y
USE_MPI = n
ARCH = n
PROFILE = n
DEBUG = n
# Directories
FIDASIM_DIR := $(shell pwd)
SRC_DIR = $(FIDASIM_DIR)/src
DEPS_DIR = $(FIDASIM_DIR)/deps
TABLES_DIR = $(FIDASIM_DIR)/tables
LIB_DIR = $(FIDASIM_DIR)/lib
DOCS_DIR = $(FIDASIM_DIR)/docs
PYTHON_EXEC = $(shell which python3)
PYTHON_EXEC = $(shell which python3 python 2> /dev/null | head -1)
ifeq ($(PYTHON_EXEC),)
$(error Python3 executable was not found)
endif
#Operating Systems
OS := $(shell uname)
#Compilers
SUPPORTED_FC = gfortran pgf90 ifort flang
SUPPORTED_CC = gcc pgcc clang
SUPPORTED_CXX = g++ pgc++ clang
HAS_FC := $(strip $(foreach SC, $(SUPPORTED_FC), $(findstring $(SC), $(FC))))
ifeq ($(HAS_FC),)
$(error Fortran compiler $(FC) is not supported. Set FC to gfortran)
endif
HAS_CC := $(strip $(foreach SC, $(SUPPORTED_CC), $(findstring $(SC), $(CC))))
ifeq ($(HAS_CC),)
$(error C compiler $(CC) is not supported. Set CC to gcc)
endif
HAS_CXX := $(strip $(foreach SC, $(SUPPORTED_CXX), $(findstring $(SC), $(CXX))))
ifeq ($(HAS_CXX),)
$(error C++ compiler $(CXX) is not supported. Set CXX to g++)
endif
#Check for Python3
PYTHON3_CHECK := $(shell command -v python3 2>/dev/null)
ifeq ($(PYTHON3_CHECK),)
$(error Python3 not found. Please install Python3 to continue.)
endif
PYTHON_EXEC = $(shell which python3)
# Compiler Flags
# User defined Flags
VERSION := $(shell [ -e $(FIDASIM_DIR)/VERSION ] && cat $(FIDASIM_DIR)/VERSION)
ifneq ($(VERSION),)
U_FLAGS := -D_VERSION=\"$(VERSION)\"
endif
BUILD := $(shell command -v git >/dev/null 2>&1 && \
[ -d $(FIDASIM_DIR)/.git ] && \
git describe --tags --always --dirty)
ifneq ($(BUILD),)
U_FLAGS := -D_VERSION=\"$(BUILD)\"
endif
# HDF5 variables
HDF5_LIB = $(DEPS_DIR)/hdf5/lib
HDF5_INCLUDE = $(DEPS_DIR)/hdf5/include
ifeq ($(OS),Linux)
HDF5_FLAGS = -L$(HDF5_LIB) -Wl,-Bstatic -lhdf5_fortran -lhdf5hl_fortran -lhdf5_hl -lhdf5 -Wl,-Bdynamic -lz -ldl
endif
ifneq ($(findstring MINGW, $(OS)),)
HDF5_FLAGS = -L$(HDF5_LIB) -lhdf5_fortran -lhdf5hl_fortran -lhdf5_hl -lhdf5 -lm -lz -lws2_32
U_FLAGS=-static
EXEEXT=.exe
CFLAGS=-DH5_HAVE_WIN32_API
export CFLAGS
export EXEEXT
endif
ifeq ($(OS),Darwin)
HDF5_FLAGS = -L/usr/lib -L$(HDF5_LIB) -lhdf5_fortran -lhdf5hl_fortran -lhdf5_hl -lhdf5 -lz -ldl -Wl,-rpath,$(HDF5_LIB)
endif
ifneq ($(findstring gfortran, $(FC)),)
L_FLAGS = -lm
COMMON_CFLAGS = -Ofast -g -fbacktrace -cpp -Wfatal-errors
DEBUG_CFLAGS = -O0 -g -cpp -fbacktrace -fcheck=all -Wall -ffpe-trap=invalid,zero,overflow -D_DEBUG
OPENMP_FLAGS = -fopenmp -D_OMP
MPI_FLAGS = -D_MPI
PROF_FLAGS = -pg -D_PROF
ifneq ($(ARCH),n)
COMMON_CFLAGS := $(COMMON_CFLAGS) -march=$(ARCH)
endif
endif
ifneq ($(findstring pgf90, $(FC)),)
L_FLAGS = -lm -llapack -lblas
COMMON_CFLAGS = -O3 -Mpreprocess -D_DEF_INTR -D_USE_BLAS
DEBUG_CFLAGS = -O0 -g -Mpreprocess -traceback -D_DEF_INTR -D_USE_BLAS -D_DEBUG
OPENMP_FLAGS = -mp -D_OMP
MPI_FLAGS = -D_MPI
PROF_FLAGS = -pg -D_PROF
ifneq ($(ARCH),n)
COMMON_CFLAGS := $(COMMON_CFLAGS) -tp=$(ARCH)
endif
endif
ifneq ($(findstring ifort, $(FC)),)
L_FLAGS = -lm -mkl
COMMON_CFLAGS = -Ofast -g -traceback -fpp -D_USE_BLAS
DEBUG_CFLAGS = -O0 -g -fpp -traceback -check all -D_USE_BLAS -D_DEBUG
OPENMP_FLAGS = -qopenmp -D_OMP
MPI_FLAGS = -D_MPI
PROF_FLAGS = -p -D_PROF
ifneq ($(ARCH),n)
COMMON_CFLAGS := $(COMMON_CFLAGS) -x$(ARCH)
endif
endif
ifneq ($(findstring flang, $(FC)),)
L_FLAGS = -lm
COMMON_CFLAGS = -O3 -mfma -fvectorize -mfma -mavx2 -m3dnow -floop-unswitch-aggressive -Mpreprocess
DEBUG_CFLAGS = -O0 -g -cpp -fbacktrace -fcheck=all -Wall -ffpe-trap=invalid,zero,overflow -D_DEBUG
OPENMP_FLAGS = -fopenmp -D_OMP
MPI_FLAGS = -D_MPI
PROF_FLAGS = -pg -D_PROF
ifneq ($(ARCH),n)
COMMON_CFLAGS := $(COMMON_CFLAGS) -march=$(ARCH)
endif
endif
MPI_FC = $(FC)
C_FLAGS = $(COMMON_CFLAGS) $(U_FLAGS)
ifeq ($(DEBUG),y)
USE_OPENMP = n
USE_MPI = n
PROFILE = n
MPI_FC = $(FC)
C_FLAGS = $(DEBUG_CFLAGS) $(UFLAGS)
endif
ifeq ($(PROFILE),y)
USE_OPENMP = n
USE_MPI = n
MPI_FC = $(FC)
C_FLAGS = $(COMMON_CFLAGS) $(U_FLAGS) $(PROF_FLAGS)
endif
ifeq ($(USE_MPI),y)
USE_OPENMP = n
MPI_FC = mpif90
C_FLAGS = $(COMMON_CFLAGS) $(U_FLAGS) $(MPI_FLAGS)
endif
ifeq ($(USE_OPENMP),y)
MPI_FC = $(FC)
C_FLAGS = $(COMMON_CFLAGS) $(U_FLAGS) $(OPENMP_FLAGS)
endif
L_FLAGS := $(L_FLAGS) $(HDF5_FLAGS) -L$(SRC_DIR)
I_FLAGS := -I$(HDF5_INCLUDE) -I$(SRC_DIR)
# atomic table variables
NTHREADS = 1000
# FORD documentation variables
FORD_FLAGS = -d $(SRC_DIR) -d $(TABLES_DIR) -d $(LIB_DIR)/idl -d $(LIB_DIR)/python/fidasim -p $(DOCS_DIR)/user-guide -o $(DOCS_DIR)/html
CHECK_LINKS = y
export FIDASIM_DIR
export SRC_DIR
export DEPS_DIR
export TABLES_DIR
export MPI_FC
export USE_MPI
export C_FLAGS
export L_FLAGS
export I_FLAGS
export NTHREADS
fidasim: deps src tables python
.PHONY: deps
deps:
@cd $(DEPS_DIR); make
.PHONY: src
src:
@cd $(SRC_DIR); make
.PHONY: tables
tables: src
@cd $(TABLES_DIR); make
.PHONY: docs
docs:
ford $(FORD_FLAGS) $(DOCS_DIR)/fidasim.md
@ if [[ $(CHECK_LINKS) == [yY]* ]]; then \
echo "Checking for broken links..."; \
linkchecker --ignore-url=/master $(DOCS_DIR)/html/index.html ; \
fi
.PHONY: python
python:
@echo "Linking python executable: $(PYTHON_EXEC) --> $(DEPS_DIR)/python"
@ln -sf $(PYTHON_EXEC) $(DEPS_DIR)/python
clean_all: clean clean_deps clean_docs
clean: clean_src clean_tables
-rm -f *.mod *.o fidasim
@echo ""
@echo "=== CLEANING COMPLETE ==="
@echo "Cleaned: source files, tables, and fidasim executable"
@echo ""
@echo "NOTE: Dependencies (HDF5) and docs were NOT cleaned."
@echo "If switching compilers or want a complete clean, run: make clean_all"
@echo ""
clean_src:
@cd $(SRC_DIR); make clean
clean_deps:
@cd $(DEPS_DIR); make clean
clean_tables:
@cd $(TABLES_DIR); make clean
clean_docs:
-rm -rf $(DOCS_DIR)/html
help:
@echo ""
@echo "Makefile Targets:"
@echo " fidasim"
@echo " Builds fidasim executable (Default Target)"
@echo " docs"
@echo " Builds FIDASIM documentation website in $(DOCS_DIR)/html"
@echo " clean"
@echo " Deletes object and module files in the src and tables directories and deletes the fidasim executable"
@echo " clean_all"
@echo " Cleans src, tables, deps, and docs directories"
@echo " clean_src"
@echo " Cleans src directory"
@echo " clean_tables"
@echo " Cleans the tables directory"
@echo " clean_deps"
@echo " Cleans deps directory including HDF5 build"
@echo " clean_docs"
@echo " Deletes FIDASIM documentation website directory"
@echo ""
@echo "Compiling Options:"
@echo " USE_MPI = (y|n)"
@echo " Turns on MPI parallelization and turns off OpenMP"
@echo " Default: n"
@echo " USE_OPENMP = (y|n)"
@echo " Turns on OpenMP"
@echo " Default: y"
@echo " ARCH = (<TARGET>|n)"
@echo " Compile code optimized for <TARGET> e.g. ARCH=haswell/CORE-AVX2/native"
@echo " Options differ depending on compiler"
@echo " Generated code may not run on different architectures"
@echo " Default: n"
@echo " DEBUG = (y|n)"
@echo " Turns off all optimizations and OpenMP"
@echo " Turns on bounds checking and floating point exceptions"
@echo " Default: n"
@echo " PROFILE = (y|n)"
@echo " Turns on gprof profiling and turns off OpenMP"
@echo " Default: n"
@echo " CHECK_LINKS = (y|n)"
@echo " Checks whether documentation website hyperlinks are active using linkchecker"
@echo " Default: y"