-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
372 lines (354 loc) · 13.3 KB
/
Copy pathmakefile
File metadata and controls
372 lines (354 loc) · 13.3 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
# Disable the default rules
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
#
DEBUG := t
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 (main, dev)
BRANCH := main
# how to clean (recursively (1) or not (0)) the external libraries (*_loc)
RECCLEAN := 1
#
extf = f90
## c compiler for the cDriver
#CompC = gcc
CompC := gcc-14
#=================================================================================
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 := Tnum-Tana
EXTMODEL_DIR := $(MAIN_path)/Ext_Model
LIBAshort := lib$(LIB_NAME).a
LIBA := lib$(LIB_NAME)$(ext_obj).a
LIBAOLD := lib$(LIB_NAME)$(extold_obj).a
LIBAF := libTnum-TanaFull$(ext_obj).a
LIBAFshort := libTnum-TanaFull.a
#=================================================================================
# 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__TNUM_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 Libraries : QDUtilLib AD_dnSVM ConstPhys QuantumModelLib nDindex EVRT_dnSVM FOR_EVRT
#=================================================================================
EXTLIB_LIST := FOR_EVRT QuantumModelLib EVRT_dnSVM AD_dnSVM ConstPhys nDindex 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))
$(info ***********EXTLib_DIR: $(EXTLib_DIR))
EXTMod := $(addsuffix /OBJ/obj$(ext_obj), $(EXTLib_DIR))
$(info ***********EXTOBJDIR: $(EXTMod))
EXTLibOBJ := $(addsuffix /*.o, $(EXTMod))
$(info ***********EXTLibOBJ: $(EXTLibOBJ))
EXTMod := $(addprefix -I,$(EXTMod))
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 ***********************************************************************)
#
SRCPATH := $(shell find $(SRC_DIR)/* -maxdepth 1 -type d )
VPATH := $(APP_DIR):$(SRCPATH)
$(info ***********VPATH: $(VPATH))
#
include scripts/fortranlist.mk
OBJ := $(SRCFILES:.f90=.o)
OBJ := $(addprefix $(OBJ_DIR)/, $(OBJ))
ifeq ($(DDEBUG),t)
$(info ***********SRCPATH: $(SRCPATH))
$(info ***********OBJ files: $(OBJ))
endif
# special files
EXT_SRC := calc_f2_f1Q.f90 Sub_X_TO_Q_ana.f90 Calc_Tab_dnQflex.f90 sub_system.f90 \
Module_ForTnumTana_Driver.f90 TnumTana_Lib.f90
EXT_OBJ := $(EXT_SRC:.f90=.o)
EXT_OBJ := $(addprefix $(OBJ_DIR)/,$(EXT_OBJ))
ifeq ($(DDEBUG),t)
$(info ***********EXT_SRC: $(EXT_SRC))
$(info ***********EXT_OBJ files: $(EXT_OBJ))
endif
#===============================================
#============= Main programs: tests + example ==
#
.PHONY: all Tnum_MCTDH Tnum_MidasCpp Midas midas Tnum Tana
all: lib app
Tnum_MCTDH: Tnum90_MCTDH.exe
Tnum_MidasCpp Midas midas: Tnum90_MidasCpp.exe
Tnum Tana: Tnum90.exe
#===============================================
#================ Example(s) ===================
#===============================================
APPSRC := $(notdir $(shell ls $(APP_DIR)/*.f90))
APPOBJ := $(addprefix $(OBJ_DIR)/, $(APPSRC:.f90=.o))
APPEXE := $(APPSRC:.f90=.exe)
APPSRC := $(notdir $(shell ls $(APP_DIR)/*.c))
APPOBJ += $(addprefix $(OBJ_DIR)/, $(APPSRC:.c=.o))
APPEXE += $(APPSRC:.c=.exe)
#
ifeq ($(DDEBUG),t)
$(info ***********app SCR: $(APPSRC))
$(info ***********app OBJ: $(APPOBJ))
$(info ***********app exe: $(APPEXE))
$(info ***********************************************************************)
endif
#
.PHONY: app
app: $(APPEXE)
@echo "Application compilation: OK"
#
#===============================================
#================ unitary tests ================
#===============================================
#
.PHONY: ut
ut: Tnum90.exe Tnum90_MidasCpp.exe
@echo "---------------------------------------"
@echo "Unitary tests for the Tnum"
@cd TESTS ; ./run_tests_WithoutComp
@echo "---------------------------------------"
@echo " done Tests"
#
#===============================================
#===============================================
#============= compilation =====================
#===============================================
#
$(OBJ_DIR)/%.o: %.f90
$(FC) $(FFLAGS) -o $@ -c $<
#
%.exe: $(OBJ_DIR)/%.o $(LIBAF)
$(FC) $(FFLAGS) -o $@ $< $(LIBAF) $(FLIB)
@echo $@ compilation: OK
#
$(OBJ_DIR)/%.o: %.c
@echo " compile: " $<
$(CompC) $(CFLAGS) -o $@ -c $<
#
#===============================================
#============= make sub_system =================
#============= with the .f or .f90 extention ==
#===============================================
SRC/sub_pot/sub_system.$(extf): SRC_NotUsed/sub_pot/sub_system_save.$(extf)
cp SRC_NotUsed/sub_pot/sub_system_save.$(extf) SRC/sub_pot/sub_system.$(extf)
#===============================================
#============= 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 ====================
#===============================================
.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) $(EXT_OBJ)
ar -cr $(LIBAF) $(OBJ) $(EXT_OBJ) $(EXTLibOBJ)
rm -f $(LIBAFshort)
ln -s $(LIBAF) $(LIBAFshort)
@echo " done Library: "$(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
cd APP_OutputFiles && ./clean
rm -f res*
rm -f *.xyz
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) $(APPOBJ) $(OBJTEST): | $(OBJ_DIR)
$(APPOBJ): $(LIBA) | $(EXTLib)
$(OBJTEST): $(LIBA) | $(EXTLib)
$(OBJ): | $(EXTLib)
include scripts/dependencies.mk
#===============================================