-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
343 lines (266 loc) · 9.79 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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# ******************** MAKEFILE ****************
#----------------------------------------------------------------------------
# USER DEFINABLE OPTIONS
#----------------------------------------------------------------------------
# Executable name
EXENAME = scarpia
# Print relevant output to log file
LOGFILE = yes
LOGNAME = scarpia.log
# Compiler ( gfortran, ifort )
FC = ifort
# Debugging options ( yes or no )
DEBUG = no
# Optimization level
OPTLEVEL = 3
# OpenMP libraries
OPENMP = no
# linking LAPACK and BLAS
LAPACK = yes
# Compile with standard real 8 (see details about the flags for each compiler...)
REAL8 = yes
#----------------------------------------------------------------------------
# LAPACK AND BLAS FINE DETAILS
#----------------------------------------------------------------------------
# Intel compiler version ( used only if FC=ifort and LAPACK=yes )
# 2016-SEQ, 2016-MULTI - 2016 version, sequential / multithreaded
# 2013-SEQ, 2013-MULTI - 2013 version, sequential / multithreaded
# 11-SEQ, 11-MULTI - 11.x version, sequential / multithreaded
# 11-IA32 - 11.x ia32 arch version, sequential
# 10-SEQ, 10-MULTI - 10.x version, sequential / multithreaded
INTELVERS = 2016-SEQ
# gfortran lapack libraries
# GNU - system default libraries
# ATLAS - atlas libraries
GLAPACK = GNU
#----------------------------------------------------------------------------
# STRIP ALL SPACES
#----------------------------------------------------------------------------
# Strip leading and trailing spaces from all variables.
FC := $(strip ${FC})
DEBUG := $(strip ${DEBUG})
OPTLEVEL := $(strip ${OPTLEVEL})
LAPACK := $(strip ${LAPACK})
INTELVERS := $(strip ${INTELVERS})
GLAPACK := $(strip ${GLAPACK})
LOGFILE := $(strip ${LOGFILE})
LOGNAME := $(strip ${LOGNAME})
OPENMP := $(strip ${OPENMP})
#----------------------------------------------------------------------------
# Compiler specific statements.
#----------------------------------------------------------------------------
ifeq (${FC},gfortran)
# Optimization flag
O0FLAGS = -O0
O1FLAGS = -O1
O2FLAGS = -O2
O3FLAGS = -O3
# Debug flag
DEBUGFLG = -g -fbounds-check -ffpe-trap=invalid,zero,overflow
# LAPACK AND BLAS flags
ifeq (${GLAPACK},GNU)
# GNU Lapack and Blas flags
LAPACKFLG = -llapack -lblas
endif
ifeq (${GLAPACK},ATLAS)
# ATLAS Lapack and Blas flags
LAPACKFLG = -L/usr/lib64/atlas/ -llapack -lf77blas -lcblas -latlas
endif
# OPENMP flags
OPENMPFLG = -fopenmp
# Data type
DATAFLG =
ifeq (${REAL8},yes)
DATAFLG = -fdefault-real-8
endif
# Flag to specify the position of mod files
MODULEFLG = -fintrinsic-modules-path
# Other miscellaneous compiling options
MISCFLG = -ffree-line-length-none
endif
ifeq (${FC},ifort)
# Optimization flags
O0FLAGS = -O0
O1FLAGS = -O1
O2FLAGS = -O2
O3FLAGS = -O3
# Debug flags
DEBUGFLG = -g -traceback -fpe-all=0 -debug all -check all
# MKL flags
ifeq (${INTELVERS},2016-SEQ)
LAPACKFLG = -lpthread -lm
LAPACKCOMPILE = -mkl=sequential
endif
ifeq (${INTELVERS},2016-MULTI)
LAPACKFLG = -lpthread -lm
LAPACKCOMPILE = -qopenmp -mkl=parallel
endif
ifeq (${INTELVERS},2013-SEQ)
LAPACKFLG = -lpthread -lm
LAPACKCOMPILE = -mkl=sequential
endif
ifeq (${INTELVERS},2013-MULTI)
LAPACKFLG = -lpthread -lm
LAPACKCOMPILE = -openmp -mkl=parallel
endif
ifeq (${INTELVERS},11-SEQ)
LAPACKFLG = -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread -lm
LAPACKCOMPILE = -I$(MKLROOT)/include
endif
ifeq (${INTELVERS},11-IA32)
LAPACKFLG = -L${MKLROOT}/lib/ia32 -lmkl_intel -lmkl_core -lmkl_sequential -lpthread -lm
LAPACKCOMPILE = -I${MKLROOT}/include
endif
ifeq (${INTELVERS},11-MULTI)
LAPACKFLG = -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -lm
LAPACKCOMPILE = -openmp -I$(MKLROOT)/include
endif
ifeq (${INTELVERS},10-SEQ)
LAPACKFLG = -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread -lm
LAPACKCOMPILE = -I$(MKLROOT)/include
endif
ifeq (${INTELVERS},10-MULTI)
LAPACKFLG = -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -lm
LAPACKCOMPILE = -openmp -I$(MKLROOT)/include
endif
# OPENMP flags
OPENMPFLG = -qopenmp
# Data type
DATAFLG =
ifeq (${REAL8},yes)
DATAFLG = -r8 -i4
endif
# Flag to specify the position of mod files
MODULEFLG = -I
# Other miscellaneous compiling options
MISCFLG =
endif
#----------------------------------------------------------------------------
# Setup preprocessing options
#----------------------------------------------------------------------------
PPDEFINE =
# Define macro for writing current version (git tag) in the code
PPDEFINE += -DVERSIONTAG=\"$(shell git describe --tags)\"
# Write output to logfile
ifeq (${LOGFILE}, yes)
PPDEFINE += -DLOG_FILE=\"${LOGNAME}\"
endif
# Preprocess with lapack calls
ifeq (${LAPACK}, yes)
PPDEFINE += -DWITH_LAPACK
endif
# Preprocess with OPENMP
ifeq (${OPENMP}, yes)
PPDEFINE += -DWITH_OPENMP
endif
#----------------------------------------------------------------------------
# Setup linking and compilation flags
#----------------------------------------------------------------------------
# initialize flags
COMPILEFLG =
LINKFLG =
LIBFLG =
INCLUDEFLG =
# if debugging set the appropriate flags
ifeq (${DEBUG}, yes)
COMPILEFLG += ${DEBUGFLG}
endif
# Set flags for defining standard variable kinds
COMPILEFLG += ${DATAFLG}
# If lapack, add the linking options
ifeq (${LAPACK}, yes)
LIBFLG += ${LAPACKFLG}
LINKFLG += ${LAPACKCOMPILE}
endif
# If OPENMP, add the linking options
ifeq (${OPENMP}, yes)
LIBFLG += ${OPENMPFLG}
COMPILEFLG += ${OPENMPFLG}
endif
COMPILEFLG += ${MISCFLG}
#----------------------------------------------------------------------------
# Determine the optimization level to be used.
#----------------------------------------------------------------------------
# if debugging override input optimization level
ifeq (${DEBUG}, yes)
OPTLEVEL = 0
endif
# Define optimization level
OPTFLAGS = ${O0FLAGS}
ifeq (${OPTLEVEL},1)
OPTFLAGS = ${O1FLAGS}
endif
ifeq (${OPTLEVEL},2)
OPTFLAGS = ${O2FLAGS}
endif
ifeq (${OPTLEVEL},3)
OPTFLAGS = ${O3FLAGS}
endif
COMPILEFLG += ${OPTFLAGS}
#----------------------------------------------------------------------------
# List of directories
#----------------------------------------------------------------------------
SRCDIR = Source
OBJDIR = Objects
TESTDIR = Tests/Source
EXEDIR = Executables
#----------------------------------------------------------------------------
# List of object files
#----------------------------------------------------------------------------
# Define list of object from the list of all f90 files in the directory
OBJSWITHMAIN =$(patsubst Source/%,Objects/%,$(patsubst %.f90,%.o,$(wildcard ${SRCDIR}/*.f90)))
OBJS =$(patsubst %/Main.o,,${OBJSWITHMAIN})
#----------------------------------------------------------------------------
# Construct the compile, link, preprocess variables.
#----------------------------------------------------------------------------
# Compile command: ${COMPILE} <source>
COMPILE = ${FC} ${COMPILEFLG} ${MODULEFLG} ${OBJDIR} -c
# Link command: ${LINK} <exe name> <objects> <libflags>
LINK = ${FC} ${LINKFLG} ${MODULEFLG} ${OBJDIR} -o
# Preprocess commands, add to compilation
PREPROCESS = -cpp ${PPDEFINE}
# Build static library : ${AR} <libraryname>.a <objects>
AR = ar cr
#----------------------------------------------------------------------------
# START OF MAKE RULES
#----------------------------------------------------------------------------
# Link objects to the produce the executable file
${EXENAME} : ${SRCDIR}/Main.f90 ${OBJS}
${COMPILE} ${PREPROCESS} ${SRCDIR}/Main.f90
${LINK} ${EXEDIR}/$@ Main.o $(OBJS) ${LIBFLG}
rm Main.o
# Make target to build all the object files and assemble them
all : ${OBJS}
# Make a target object file by preprocessing and compiling the fortran code
${OBJDIR}/%.o : ${SRCDIR}/%.f90
${COMPILE} ${PREPROCESS} ${SRCDIR}/$*.f90
cp -p $*.o $(shell echo $* | tr A-Z a-z).mod ${OBJDIR}
rm $*.o $(shell echo $* | tr A-Z a-z).mod
# Make target to build required directories
directories :
mkdir -p ${OBJDIR} ${EXEDIR}
# Make documentation with doxygen
doc :
doxygen Documentation/Doxyfile
# Remove compiled objects and related stuff
clean :
rm -fr ${OBJDIR}/*
# Clean documentation
clean-doc :
rm -fr Documentation/html
rm -fr Documentation/latex
# --------------------------------------------------------------------------------------------
# ---------------------------------- START WITH DEPENDENCIES NOW -----------------------------
# --------------------------------------------------------------------------------------------
# Very basic files, which everything depends on
COMMONDEP = ${OBJDIR}/MyError.o ${OBJDIR}/MyLinearAlgebra.o ${SRCDIR}/preprocessoptions.cpp Makefile
# Runge-Kutta 4(5) integrator
${OBJDIR}/Optimize.o : ${SRCDIR}/Optimize.f90 ${OBJDIR}/MyLinearAlgebra.o ${OBJDIR}/FiniteDifference.o ${COMMONDEP}
# Input and shared data
${OBJDIR}/FiniteDifference.o : ${SRCDIR}/FiniteDifference.f90 ${COMMONDEP}
# Error and warning procedures
${OBJDIR}/MyLinearAlgebra.o : ${SRCDIR}/MyLinearAlgebra.f90 ${OBJDIR}/MyError.o Makefile
# potential energy surface
${OBJDIR}/PES.o : ${SRCDIR}/PES.f90 Makefile
# Error and warning procedures
${OBJDIR}/MyError.o : ${SRCDIR}/MyError.f90 Makefile