forked from lauvergn/QuantumModelLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
375 lines (360 loc) · 14.1 KB
/
Copy pathmakefile
File metadata and controls
375 lines (360 loc) · 14.1 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
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# Disable the default rules
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
#
DEBUG := f
DDEBUG := $(subst T,t,$(DEBUG))
#=================================================================================
#=================================================================================
# Compiler?
#Possible values: ifort, ifx, gfortran (default), nagfor
FC := gfortran
#FC := ifort
#FC := nagfor
#
# Optimize? Empty: default Optimization; 0: No Optimization; 1 Optimization
OPT := 1
## OpenMP? Empty: default with OpenMP; 0: No OpenMP; 1 with OpenMP
OMP := 1
## Lapack/blas/mkl? Empty: default with Lapack; 0: without Lapack; 1 with Lapack
LAPACK := 1
## force the default integer (without kind) during the compillation.
## default 4: , INT=8 (for kind=8)
INT := 4
## change the real kind
## default real64: , possibilities, real32, real64, real128
RKIND := real64
# For some compilers (like lfortran), real128 (quadruple precision) is not implemented
# WITHRK16 = 1 (0) compilation with (without) real128
WITHRK16 :=
## branch of the external libraries
BRANCH := main
# how to clean (recursively (1) or not (0)) the external libraries (*_loc)
RECCLEAN := 1
#=================================================================================
ifeq ($(FC),)
override FC := gfortran
endif
FFC := $(FC)
ifeq ($(OPT),)
override OPT := 1
endif
ifneq ($(OPT),$(filter $(OPT),0 1))
$(info *********** OPT (optimisation): $(OPT))
$(info Possible values: 0, 1)
$(error ERROR: Incompatible option values)
endif
OOPT := $(OPT)
ifeq ($(OMP),)
override OMP := 1
endif
ifneq ($(OMP),$(filter $(OMP),0 1))
$(info *********** OMP (openmp): $(OMP))
$(info Possible values: 0, 1)
$(error ERROR: Incompatible option values)
endif
OOMP := $(OMP)
ifeq ($(LAPACK),)
override LAPACK := 1
endif
ifneq ($(LAPACK),$(filter $(LAPACK),0 1))
$(info *********** LAPACK: $(LAPACK))
$(info Possible values: 0, 1)
$(error ERROR: Incompatible option values)
endif
LLAPACK := $(LAPACK)
ifneq ($(INT),$(filter $(INT),4 8))
$(info *********** INT (change default integer): $(INT))
$(info Possible values: 4, 8)
$(error ERROR: Incompatible option values)
endif
ifneq ($(RKIND),$(filter $(RKIND),real32 real64 real128))
$(info *********** RKIND (select the real kind): $(RKIND))
$(info Possible values (case sensitive): real32 real64 real128)
$(error ERROR: Incompatible option values)
endif
ifeq ($(WITHRK16),)
override WITHRK16 := $(shell $(FFC) -o scripts/testreal128.exe scripts/testreal128.f90 &> /dev/null ; wait ; ./scripts/testreal128.exe ; rm scripts/testreal128.exe)
endif
WWITHRK16 := $(WITHRK16)
ifneq ($(WITHRK16),$(filter $(WITHRK16),0 1))
$(info *********** WITHRK16 (compilation with real128): $(WITHRK16))
$(info Possible values: 0, 1)
$(error ERROR: Incompatible option values)
endif
ifeq ($(RKIND),real128)
ifeq ($(WWITHRK16),0)
$(info "Incompatible options:")
$(info ***********RKIND: $(RKIND))
$(info ***********WITHRK16: $(WITHRK16))
$(error ERROR: Incompatible RKIND and WITHRK16 option values)
endif
endif
export RKIND WITHRK16 INT LAPACK FC OPT OMP BRANCH
export WWITHRK16 LLAPACK FFC OOPT OOMP
#
#=================================================================================
# Operating system, OS? automatic using uname:
#=================================================================================
OS:=$(shell uname)
#=================================================================================
# extension for the library (.a), objects and modules directory
#=================================================================================
ext_obj :=_$(FC)_opt$(OPT)_omp$(OMP)_lapack$(LAPACK)_int$(INT)_$(RKIND)
extold_obj :=_$(FC)_opt$(OPT)_omp$(OMP)_lapack$(LAPACK)_int$(INT)
#=================================================================================
# Directories
#=================================================================================
MAIN_path := $(shell pwd)
#
OBJ_DIR := OBJ/obj$(ext_obj)
OBJOLD_DIR := OBJ/obj$(extold_obj)
MOD_DIR := $(OBJ_DIR)
#
SRC_DIR := SRC
APP_DIR := APP
TESTS_DIR := Tests
TESTSOUT_DIR := $(TESTS_DIR)/output
LIB_NAME := QuantumModelLib
EXTMODEL_DIR := $(MAIN_path)/Ext_Model
#=================================================================================
# Cpreprocessing macros
#=================================================================================
LIB_VERSION=$(shell awk '/version/ {print $$3}' fpm.toml | head -1)
#
CPPSHELL = -D__COMPILE_DATE="\"$(shell date +"%a %e %b %Y - %H:%M:%S")\"" \
-D__COMPILE_HOST="\"$(shell hostname -s)\"" \
-D__QML_VER='$(LIB_VERSION)' \
-D__QMLPATH="'$(MAIN_path)'" \
-D__RKIND="$(RKIND)" -D__WITHRK16="$(WITHRK16)" \
-D__LAPACK="$(LAPACK)"
#=================================================================================
# To deal with external compilers.mk file
#=================================================================================
CompilersDIR = $(MAIN_path)/scripts
ifeq ($(CompilersDIR),)
include scripts/compilers.mk
else
include $(CompilersDIR)/compilers.mk
endif
#=================================================================================
# External Model : ExtModel_m.f90
#=================================================================================
# it will create the link
MEL := $(shell readlink $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90)
$(info ***********MEL: $(MEL))
MES := $(shell if ! test -e "$(MEL)" ; then echo "the ExtModel_m.f90 link does not exist or is wrong"; rm -f $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90; fi)
$(info ***********MES: $(MES))
MES := $(shell test -L $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90 || ln -s $(EXTMODEL_DIR)/ExtModel_m.f90 $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90)
MES := $(shell if test -L $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90; then echo "the ExtModel_m.f90 link exists"; else echo "ERR"; fi)
$(info ***********MES: $(MES))
ifeq ("$(MES)","ERR")
$(error ERROR: the ExtModel_m.f90 link does not exist)
endif
#=================================================================================
# External Libraries : QDUtilLib AD_dnSVM
#=================================================================================
EXTLIB_LIST := AD_dnSVM QDUtilLib
ifneq ($(EXTLIB_LIST),)
ifeq ($(ExtLibDIR),)
ExtLibDIR := $(MAIN_path)/Ext_Lib
endif
OK := $(shell if test -d $(ExtLibDIR); then echo "ok"; fi)
#$(info ***********OK: $(OK))
ifeq ($(OK),)
$(error ERROR: $(ExtLibDIR) does not exist!)
endif
export ExtLibDIR
EXTLib_DIR := $(addprefix $(ExtLibDIR)/, $(EXTLIB_LIST))
EXTMod := $(addsuffix /OBJ/obj$(ext_obj), $(EXTLib_DIR))
EXTLibOBJ := $(addsuffix /*.o, $(EXTMod))
EXTMod := $(addprefix -I,$(EXTMod))
#$(info ***********EXTLib_DIR: $(EXTLib_DIR))
EXTLib := $(shell for LLIB in $(EXTLIB_LIST) ; do echo $(ExtLibDIR)/$$LLIB"/lib"$$LLIB""$(ext_obj)".a" ; done)
endif
#=================================================================================
#=================================================================================
#=================================================================================
#=================================================================================
$(info ***********************************************************************)
$(info ***********Library name: $(LIB_NAME))
$(info ***********Library version: $(LIB_VERSION))
$(info ***********OS: $(OS))
$(info ***********COMPILER: $(FC))
$(info ***********COMPILER_VER: $(FC_VER))
$(info ***********OPTIMIZATION: $(OPT))
$(info ***********OpenMP: $(OMP))
$(info ***********INT: $(INT))
$(info ***********RKIND: $(RKIND))
$(info ***********WITHRK16: $(WWITHRK16))
$(info ***********LAPACK: $(LAPACK))
$(info ***********FFLAGS: $(FFLAGS))
$(info ***********FLIB: $(FLIB))
$(info ***********ext_obj: $(ext_obj))
$(info )
$(info ***********ExtLibDIR: $(ExtLibDIR))
$(info ***********EXTLib: $(EXTLib))
$(info ***********EXTMod: $(EXTMod))
$(info )
$(info ***********EXTMODEL_DIR: $(EXTMODEL_DIR))
$(info ***********************************************************************)
#
SRCPATH := $(shell find $(SRC_DIR)/* -maxdepth 1 -type d )
VPATH := $(APP_DIR):$(TESTS_DIR):$(SRC_DIR):$(SRCPATH)
#
include scripts/fortranlist.mk
OBJ0=$(SRCFILES:.f90=.o)
OBJ=$(addprefix $(OBJ_DIR)/, $(OBJ0))
ifeq ($(DEGUB),T)
$(info ***********SRCPATH: $(SRCPATH))
$(info ***********OBJ files: $(OBJ))
endif
#===============================================
#============= Main programs: tests + example ==
#
.PHONY: all
all: lib $(APPEXE) $(TESTEXE)
#===============================================
#================ Example(s) ===================
#===============================================
SRCAPPFILES := $(notdir $(shell ls $(APP_DIR)/*f90))
OBJAPP := $(addprefix $(OBJ_DIR)/, $(SRCAPPFILES:.f90=.o))
APPEXE := $(SRCAPPFILES:.f90=.x)
#
ifeq ($(DDEBUG),t)
$(info ***********SRCAPPFILES: $(SRCAPPFILES))
$(info ***********OBJ app files: $(OBJAPP))
$(info ***********app test exe: $(APPEXE))
$(info ***********************************************************************)
endif
#
.PHONY: app
app: $(APPEXE)
@echo "Application compilation: OK"
#
#===============================================
#================ unitary tests ================
#===============================================
SRCTESTFILES := $(notdir $(shell ls $(TESTS_DIR)/*.f90))
OBJTEST := $(addprefix $(OBJ_DIR)/, $(SRCTESTFILES:.f90=.o))
TESTEXE := $(SRCTESTFILES:.f90=.x)
NEWTESTEXE := $(filter-out TEST_model.x, $(TESTEXE))
#
ifeq ($(DDEBUG),t)
$(info ***********SRCTESTFILES: $(SRCTESTFILES))
$(info ***********OBJ test files: $(OBJTEST))
$(info ***********app test exe: $(TESTEXE))
$(info ***********app nextest exe: $(NEWTESTEXE))
$(info ***********************************************************************)
endif
#
.PHONY: ut
ut: $(TESTEXE)
@echo "model (QML) compilation: OK"
cd $(TESTS_DIR) ; ./run_test_QML $(FFC) $(OOPT) $(OOMP) $(LLAPACK) $(INT) 1
mkdir -p $(TESTSOUT_DIR)
cd $(TESTSOUT_DIR) ; rm -f *.log ; $(foreach Texe,$(NEWTESTEXE), ../../$(Texe) >> Test.log ;)
@grep "Number of error(s)" $(TESTSOUT_DIR)/Test.log
@awk -F: 'BEGIN{test=0} /Number of tests/ {test+=$$2} END {print "Number of tests: " test}' $(TESTSOUT_DIR)/Test.log
@awk -F: 'BEGIN{err=0} /Number of error/ {err=err+$$2} END {print "Number of error(s) for all tests: " err}' $(TESTSOUT_DIR)/Test.log
@echo " done Tests"
#
#===============================================
#===============================================
#============= compilation =====================
#===============================================
#
$(OBJ_DIR)/%.o: %.f90
$(FC) $(FFLAGS) -o $@ -c $<
#
%.x: $(OBJ_DIR)/%.o $(LIBAF)
$(FC) $(FFLAGS) -o $@ $< $(LIBAF) $(FLIB)
@echo $@ compilation: OK
#
# Special rule for the external model
.PHONY: ln_ExtModel
ln_ExtModel: $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90
#
$(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90:
ln -s $(MAIN_path)/Ext_Model/ExtModel_m.f90 $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90
#
#===============================================
#============= object directory ===============
#===============================================
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
rm -f $(OBJOLD_DIR)
cd OBJ && ln -s obj$(ext_obj) obj$(extold_obj)
@echo OBJ_DIR: $(OBJ_DIR)
#===============================================
#============= Main library ====================
#===============================================
LIBAshort := lib$(LIB_NAME).a
LIBA := lib$(LIB_NAME)$(ext_obj).a
LIBAOLD := lib$(LIB_NAME)$(extold_obj).a
LIBAF := lib$(LIB_NAME)Full$(ext_obj).a
LIBAFOLD := libQMLFull$(extold_obj).a
LIBAFshort := libQMLFull.a
#
.PHONY: lib
lib: $(LIBA) $(LIBAF)
$(LIBA): $(OBJ)
ar -cr $(LIBA) $(OBJ)
rm -f $(LIBAOLD)
ln -s $(LIBA) $(LIBAOLD)
rm -f $(LIBAshort)
ln -s $(LIBA) $(LIBAshort)
@echo " done Library: "$(LIBA)
$(LIBAF): $(OBJ)
ar -cr $(LIBAF) $(OBJ) $(EXTLibOBJ)
rm -f $(LIBAFOLD)
ln -s $(LIBAF) $(LIBAFOLD)
rm -f $(LIBAFshort)
ln -s $(LIBAF) $(LIBAFshort)
@echo " done Library (including external libraries): "$(LIBAF)
#===============================================
#===============================================
#============= External libraries =============
#===============================================
.PHONY: getlib
getlib: $(EXTLib)
#
$(EXTLib):
$(MAKE) -C $(ExtLibDIR) -f $(MAIN_path)/scripts/makefile-extlib LIBA=$@
#===============================================
#================ cleaning =====================
.PHONY: clean cleanall cleanlocextlib
clean:
rm -f $(TESTEXE) $(APPEXE)
rm -f *.log
rm -fr *.dSYM
rm -fr build
rm -f $(MAIN_path)/$(SRC_DIR)/QML/ExtModel_m.f90
rm -f $(OBJ_DIR)/*.o $(OBJ_DIR)/*.mod $(OBJ_DIR)/*.MOD
@echo " done cleaning for "$(LIB_NAME)
cleanall: clean
rm -f lib*.a
rm -rf OBJ
cd $(TESTS_DIR) && ./clean
if [ "$(EXTLIB_LIST)" != "" -a "$(RECCLEAN)" = "1" ]; then ./scripts/cleanExtLib cleanall "$(ExtLibDIR)" "$(EXTLIB_LIST)" 0; fi
@echo " done remove the *.a libraries and the OBJ directory for "$(LIB_NAME)
cleanlocextlib: clean
rm -f lib*.a
rm -rf OBJ
cd $(TESTS_DIR) && ./clean
if [ "$(EXTLIB_LIST)" != "" -a "$(RECCLEAN)" = "1" ] ; then ./scripts/cleanExtLib cleanlocextlib "$(ExtLibDIR)" "$(EXTLIB_LIST)" 0; fi
@echo " done remove all local library directories (..._loc) for "$(LIB_NAME)
#===============================================
#============= make dependencies ===============
#===============================================
.PHONY: dep
scripts/dependencies.mk scripts/fortranlist.mk dep:
./scripts/dependency.sh
#===============================================
#============= module dependencies =============
#===============================================
$(OBJ) $(OBJAPP) $(OBJTEST): | $(OBJ_DIR)
$(OBJAPP): $(LIBAF) | $(EXTLib)
$(OBJTEST): $(LIBAF) | $(EXTLib)
$(OBJ): | $(EXTLib)
include scripts/dependencies.mk
#===============================================