This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
303 lines (273 loc) · 10.8 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
#=============================================================================
#
# A Makefile with compiler and operative-system options.
# The objects and libraries are defined in Makefile.code.
#
#-----------------------------------------------------------------------------
# KYL 2009-03-16: Created a new, more generic system
#
#=============================================================================
# Set some general variables
#=============================================================================
ifeq ($(shell uname -o),Msys)
OS = MINGW32
else
OS := $(shell uname -s)
endif
bit64 := $(shell uname -a | grep x86_64 | wc -c)
ifeq ($(bit64),0)
PROC = i686
else
PROC = x86_64
endif
modes = debug profile normal optim r16 debug_irg openmp openmpprofile
targets = help clean
compilers = dummy
default = gfortran
ifeq ($(OS),OSF1)
default = OSF1
endif
#=============================================================================
# Define architecture spesific flags
#=============================================================================
# Note: march1 is march settings for gfortran
march1=-march=i686 -msse2
ifneq ($(OS),MINGW32)
ifneq ($(shell cat /proc/cpuinfo|grep Opteron),)
march1=-march=opteron -msse3
else ifeq ($(PROC),x86_64)
march1=-march=native -msse3
endif
endif
#=============================================================================
# Define some special targets
#=============================================================================
.PHONY: clean help
help:
@echo "Usage: make <target>"
@echo "<target> is one of the following:"
@echo
@echo -e " $(foreach target,$(targets), $(target)\n)"
@echo " The default compiler is $(default)."
@echo "OS = $(OS), PROC = $(PROC)"
@echo "Compilers: $(compilers)"
clean:
$(MAKE) -f Makefile.code clean
all: all_debug all_optim all_openmp profile_ifort_Linux
all_debug:
$(MAKE) $(filter debug_%, $(targets_filtered))
all_optim:
$(MAKE) $(filter optim_%, $(targets_filtered))
all_openmp:
$(MAKE) $(filter openmp_%, $(targets_filtered))
unittests_all: unittests_all_debug unittests_all_optim unittests_all_openmp
unittests_all_debug:
$(MAKE) $(filter unittests_debug_%, $(targets_filtered))
unittests_all_optim:
$(MAKE) $(filter unittests_optim_%, $(targets_filtered))
unittests_all_openmp:
$(MAKE) $(filter unittests_openmp_%, $(targets_filtered))
#=============================================================================
# Setup the compiler list and define the compiler flags
#=============================================================================
# - Based on the operating system reported by uname, a list of
# compilers will be made available through the variables
# default, compilers and modes. 'default' is the default
# compiler (the one used when only typing e.g. 'make debug'),
# compilers is a list of target compilers and modes is a list
# of compile modes.
# - For each target specified by a combination of the compilers
# and modes, there is also defined a variable that contains
# the compiler flags: <mode>_<compiler>_flags. This must be
# defined if the target is to be created. For OSF1 (and similar
# OSes that might be added in the future), the flags are in
# variables named: <mode>_<OS>_flags.
#
ifeq ($(OS),Linux)
compilers += gfortran
# Define gfortran flags
gf_common := -cpp -fPIC -fdefault-real-8 -fdefault-double-8
debug_gfortran_flags = "$(gf_common) \
-g -fbounds-check -fbacktrace \
-ffpe-trap=invalid,zero,overflow \
-mieee-fp -Wno-unused-dummy-argument -Wall" \
NOWARN_FFLAGS="-Wno-all"
profile_gfortran_flags = "$(gf_common) -g -pg"
normal_gfortran_flags = "$(gf_common)"
optim_gfortran_flags = "$(gf_common) -O3 $(march1) -funroll-loops"
openmp_gfortran_flags = "$(gf_common) \
-O3 $(march1) -funroll-loops -fopenmp -frecursive"
openmpprofile_gfortran_flags = "$(gf_common) -fopenmp -frecursive -gomp"
#openmp_gfortran_flags = "-fdefault-real-8 -fdefault-double-8 -fopenmp -frecursive"
# Define ifort flags
ifneq ($(shell command -v ifort 2> /dev/null),)
# Make script freeze when runnign "ifort --version" without contact to licence server
ifneq ($(shell timeout 0.2 ifort --version 2> /dev/null),)
compilers += ifort
omp_ifort = "-openmp"
ifort_is_bleeding := $(shell expr `ifort --version 2>/dev/null \
| grep -o "[0-9]\.[0-9]\.[0-9]" | tail -1` \
\>= 18.0.0 2>/dev/null)
ifeq ($(ifort_is_bleeding),1)
omp_ifort = "-qopenmp"
endif
endif
endif
debug_ifort_flags = "-fpp -r8 -fpe0 -g -fp-model precise -warn all \
-check all,noarg_temp_created,nopointers \
-traceback -ftz -auto -fPIC -no-wrap-margin" \
NOWARN_FFLAGS="-warn none"
profile_ifort_flags = "-fpp -r8 -fpe0 -g -pg -auto -fPIC -no-wrap-margin"
normal_ifort_flags = "-fpp -r8 -fpe0 -warn all -auto -fPIC -no-wrap-margin"
optim_ifort_flags = "-fpp -r8 -O3 -ax -fp-model precise -fpe0 -w -ftz -auto -check uninit -fPIC -no-wrap-margin"
r16_ifort_flags = "-fpp -r16 -fpe0 -warn all -auto -fPIC -no-wrap-margin"
openmp_ifort_flags = "-fpp $(omp_ifort) -r8 -O3 -ax -fp-model precise -fpe0 -w -ftz -auto -fPIC -no-wrap-margin"
# Set some processor specific flags (e.g. 64bit flags)
# Notes:
# * For optim_ifort: -axN ? (is also compatible with generic processor)
ifeq ($(PROC),i686)
optim_ifort_flags = "-r8 -O3 -xN -fpe0 -fPIC -w -fpp"
endif
#
# MinGW/Msys
#***************************************************************************
else ifeq ($(OS),MINGW32)
# Set list of compilers, default compiler and names of compiler binaries
#---------------------------------------------------------------------------
# Note: -lg2c ?
# use -lg2c if linking in TPlib compiled with g77 (Doesn't work on Windows?)
#
compilers += gfortran
#
# Define gfortran flags
#---------------------------------------------------------------------------
debug_gfortran_flags = "$(gf_common) -fbounds-check -Wall -g \
-ffpe-trap=invalid,zero,overflow -mieee-fp"
# -L$(mingw_path)"
normal_gfortran_flags = "$(gf_common)"
optim_gfortran_flags = "$(gf_common) -O3 -funroll-loops -malign-double"
#
# Set some processor specific flags (e.g. 64bit flags)
#---------------------------------------------------------------------------
ifeq ($(PROC),x86_64)
optim_gfortran_flags = "$(gf_common) -O3 -funroll-loops"
endif
endif
# g++ options
debug_cpp = "-fPIC -Wall -g -mieee-fp -fsignaling-nans -D_GLIBCXX_USE_CXX11_ABI=0"
optim_cpp = "-fPIC -O3 -funroll-loops -D_GLIBCXX_USE_CXX11_ABI=0"
openmp_cpp = "-fPIC -O3 -DUSEOMP -fopenmp -funroll-loops -D_GLIBCXX_USE_CXX11_ABI=0"
profile_cpp = "-fPIC -g -pg -D_GLIBCXX_USE_CXX11_ABI=0"
normal_cpp = "-D_GLIBCXX_USE_CXX11_ABI=0"
openmpprofile_cpp = "-fPIC -O3 -DUSEOMP -fopenmp -D_GLIBCXX_USE_CXX11_ABI=0"
CC=g++
#=============================================================================
# Define the canned sequences that creates targets
#=============================================================================
#
# 'create_phony_targets' is a canned sequence that creates the dummy targets.
# If the corresponding flags are not defined, the targets will not be created.
# when a target is created, it is automatically added to the list of targets.
#
define create_phony_targets
ifeq ($(2),dummy)
ifdef $(1)_$(default)_flags
targets += $(1)
$(1): $(1)_$(default)
endif
else
ifdef $(1)_$(2)_flags
targets += $(1)_$(2)
$(1)_$(2): $(1)_$(2)_$(OS)
endif
endif
endef
#
# 'create_target' is a canned sequence that is used to define targets based on
# three arguments: 'os', 'mode' and 'compiler' respectively. There are three
# different uses based on the content of 'compiler':
#
# "dummy" : Create target <mode>_<os>
# <comp> : Create target <mode>_<compiler>_<os>
#
# where <comp> is the name of any compiler, e.g. gfortran. The intent of
# "dummy" is to create targets for OSF1, and the intent of "dummy2" is to
# create targets for special modes (e.g. r16_ifort_Linux). The targets are only
# created if there exist corresponding flags:
#
# <mode>_<comp>_flags : when compiler is not "dummy"
# <mode>_<os>_flags : else
#
# One example is in order. The following will create the targets
# optim_ifort_Linux, debug_OSF1 and r16_ifort_Linux, respectively:
#
# $(eval $(call create_target,Linux,optim,ifort))
# $(eval $(call create_target,OSF1 ,debug,dummy))
# $(eval $(call create_target,Linux,r16_ifort,dummy2))
#
define create_target
ifeq ($(3),dummy)
ifdef $(2)_$(1)_flags
targets += $(2)_$(1)
$(2)_$(1):
+$(MAKE) FC=$(fc) FFLAGS=$($(2)_$(1)_flags) CFLAGS=$($(2)_cpp) TARGET=$$@ \
LEXT=$(1) -f Makefile.code -e thermopack
endif
else
ifdef $(2)_$(3)_flags
targets += $(2)_$(3)_$(1)
$(2)_$(3)_$(1):
+$(MAKE) FC=$(3) MODE=$(2) FFLAGS=$($(2)_$(3)_flags) CFLAGS=$($(2)_cpp) TARGET=$$@ \
LEXT=$(3)_$(1) -f Makefile.code -e thermopack
endif
endif
endef
define create_test_target
ifeq ($(3),dummy)
ifdef $(2)_$(1)_flags
targets += unittests_$(2)_$(1)
unittests_$(2)_$(1):
+$(MAKE) FC=$(fc) FFLAGS=$($(2)_$(1)_flags) \
TARGET=$(2)_$(1) LEXT=$(1) -f Makefile.code -e run_unittests
endif
else
ifdef $(2)_$(3)_flags
targets += unittests_$(2)_$(3)_$(1)
unittests_$(2)_$(3)_$(1):
+$(MAKE) FC=$(3) MODE=$(2) FFLAGS=$($(2)_$(3)_flags) \
TARGET=$(2)_$(3)_$(1) LEXT=$(3)_$(1) -f Makefile.code -e run_unittests
endif
endif
endef
define create_phony_test_targets
ifeq ($(2),dummy)
ifdef $(1)_$(default)_flags
targets += unittests_$(1)
unittests_$(1): unittests_$(1)_$(default)
endif
else
ifdef $(1)_$(2)_flags
targets += unittests_$(1)_$(2)
unittests_$(1)_$(2): unittests_$(1)_$(2)_$(OS)
endif
endif
endef
#=============================================================================
# Define the targets
#=============================================================================
#
# First we create the dummy targets that points to the real targets
$(foreach mode,$(modes),$(foreach comp,$(compilers),\
$(eval $(call create_phony_targets,$(mode),$(comp)))))
#
# Then we create the real targets
$(foreach mode,$(modes),$(foreach comp,$(compilers),\
$(eval $(call create_target,$(OS),$(mode),$(comp)))))
# Similar for test targets
$(foreach mode,$(modes),$(foreach comp,$(compilers),\
$(eval $(call create_phony_test_targets,$(mode),$(comp)))))
#
$(foreach mode,$(modes),$(foreach comp,$(compilers),\
$(eval $(call create_test_target,$(OS),$(mode),$(comp)))))
# Create list of filtered targets for the "all" family of targets
targets_filtered := $(filter-out %_pgf90, $(filter-out %_Linux, $(targets)))