-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathbuild_rules.mk
More file actions
296 lines (275 loc) · 10.6 KB
/
build_rules.mk
File metadata and controls
296 lines (275 loc) · 10.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# $Id$
#
# Darwin.gfortranclang.default
#
############################################################
# Default compiler setting.
#
ESMF_F90DEFAULT = gfortran
ESMF_F90LINKERDEFAULT = $(ESMF_CXXLINKER)
ESMF_CXXDEFAULT = clang++
ESMF_CDEFAULT = clang
ESMF_CLINKERDEFAULT = clang++
ESMF_CPPDEFAULT = clang -E -P -x c
ESMF_CXXCOMPILEOPTS += -x c++ -mmacosx-version-min=10.7 -stdlib=libc++
############################################################
# Default MPI setting.
#
ifeq ($(ESMF_COMM),default)
export ESMF_COMM := mpiuni
endif
############################################################
# MPI dependent settings.
#
ifeq ($(ESMF_COMM),mpiuni)
# MPI stub library -----------------------------------------
ESMF_CPPFLAGS += -DESMF_MPIUNI -I$(ESMF_DIR)/src/Infrastructure/stubs/mpiuni
ESMF_MPIRUNDEFAULT = $(ESMF_DIR)/src/Infrastructure/stubs/mpiuni/mpirun
else
ifeq ($(ESMF_COMM),mpich1)
# Mpich1 ---------------------------------------------------
ESMF_F90COMPILECPPFLAGS+= -DESMF_MPICH1
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_MPICH1
ESMF_F90DEFAULT = mpif90
ESMF_CXXDEFAULT = mpiCC
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpiCC
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_MPI3
else
ifeq ($(ESMF_COMM),mpich2)
# Mpich2 ---------------------------------------------------
ESMF_F90DEFAULT = mpif90
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_MPI3
else
ifeq ($(ESMF_COMM),mpich)
# Mpich3 and up --------------------------------------------
ESMF_F90DEFAULT = mpif90
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_CXXLINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.mpich3f90)
ESMF_F90LINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.mpich3f90)
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
else
ifeq ($(ESMF_COMM),mvapich2)
# Mvapich2 -------------------------------------------------
ESMF_F90DEFAULT = mpif90
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
else
ifeq ($(ESMF_COMM),lam)
# LAM (assumed to be built with gfortran) ------------------
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_SIGUSR2
ESMF_F90DEFAULT = mpif77
ESMF_CXXDEFAULT = mpic++
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpic++
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
ESMF_F90COMPILECPPFLAGS+= -DESMF_NO_MPI3
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_MPI3
else
ifeq ($(ESMF_COMM),openmpi)
# OpenMPI --------------------------------------------------
ifeq ($(shell $(ESMF_DIR)/scripts/available mpifort),mpifort)
ESMF_F90DEFAULT = mpifort
else
ESMF_F90DEFAULT = mpif90
endif
ESMF_CXXCOMPILECPPFLAGS+= -DESMF_NO_SIGUSR2
ESMF_F90LINKLIBS += $(shell $(ESMF_DIR)/scripts/libs.openmpif90_forcxx $(ESMF_F90DEFAULT))
ESMF_CXXDEFAULT = mpicxx
ESMF_CDEFAULT = mpicc
ESMF_CLINKERDEFAULT = mpicxx
ESMF_MPIRUNDEFAULT = mpirun $(ESMF_MPILAUNCHOPTIONS)
ESMF_MPIMPMDRUNDEFAULT = mpiexec $(ESMF_MPILAUNCHOPTIONS)
else
ifeq ($(ESMF_COMM),user)
# User specified flags -------------------------------------
else
$(error Invalid ESMF_COMM setting: $(ESMF_COMM))
endif
endif
endif
endif
endif
endif
endif
endif
############################################################
# Print compiler version string
#
ESMF_F90COMPILER_VERSION = ${ESMF_F90COMPILER} -v --version
ESMF_CXXCOMPILER_VERSION = ${ESMF_CXXCOMPILER} -v --version
ESMF_CCOMPILER_VERSION = ${ESMF_CCOMPILER} -v --version
############################################################
# Special debug flags
#
ESMF_F90OPTFLAG_G += -Wall -Wextra -Wconversion -Wno-unused -Wno-unused-dummy-argument -fimplicit-none -fcheck=all,no-pointer -ffpe-trap=zero,overflow
ESMF_CXXOPTFLAG_G += -Wall -Wextra -Wno-unused
############################################################
# Fortran symbol convention
#
ifeq ($(ESMF_FORTRANSYMBOLS),default)
ESMF_F90COMPILEOPTS +=
ESMF_F90LINKOPTS +=
ESMF_CPPFLAGS += -DESMF_LOWERCASE_SINGLEUNDERSCORE
else
ifeq ($(ESMF_FORTRANSYMBOLS),lowercase_singleunderscore)
ESMF_F90COMPILEOPTS += -fno-second-underscore
ESMF_F90LINKOPTS += -fno-second-underscore
ESMF_CPPFLAGS += -DESMF_LOWERCASE_SINGLEUNDERSCORE
else
ifeq ($(ESMF_FORTRANSYMBOLS),lowercase_doubleunderscore)
ESMF_F90COMPILEOPTS += -fsecond-underscore
ESMF_F90LINKOPTS += -fsecond-underscore
ESMF_CPPFLAGS += -DESMF_LOWERCASE_DOUBLEUNDERSCORE
else
$(error "ESMF_FORTRANSYMBOLS = $(ESMF_FORTRANSYMBOLS)" not supported by ESMF and/or this platform)
endif
endif
endif
############################################################
# Construct the ABISTRING
#
ifeq ($(ESMF_MACHINE),x86_64)
ifeq ($(ESMF_ABI),32)
ESMF_ABISTRING := $(ESMF_MACHINE)_32
endif
ifeq ($(ESMF_ABI),64)
ESMF_ABISTRING := x86_64_small
endif
endif
############################################################
# Set memory model compiler flags according to ABISTRING
#
ifeq ($(ESMF_ABISTRING),x86_64_32)
ESMF_CXXCOMPILEOPTS += -m32
ESMF_CXXLINKOPTS += -m32
ESMF_CCOMPILEOPTS += -m32
ESMF_CLINKOPTS += -m32
ESMF_F90COMPILEOPTS += -m32
ESMF_F90LINKOPTS += -m32
endif
ifeq ($(ESMF_ABISTRING),x86_64_small)
ESMF_CXXCOMPILEOPTS += -m64 -mcmodel=small
ESMF_CXXLINKOPTS += -m64 -mcmodel=small
ESMF_CCOMPILEOPTS += -m64 -mcmodel=small
ESMF_CLINKOPTS += -m64 -mcmodel=small
ESMF_F90COMPILEOPTS += -m64 -mcmodel=small
ESMF_F90LINKOPTS += -m64 -mcmodel=small
endif
ifeq ($(ESMF_ABISTRING),x86_64_medium)
ESMF_CXXCOMPILEOPTS += -m64 -mcmodel=medium
ESMF_CXXLINKOPTS += -m64 -mcmodel=medium
ESMF_CCOMPILEOPTS += -m64 -mcmodel=medium
ESMF_CLINKOPTS += -m64 -mcmodel=medium
ESMF_F90COMPILEOPTS += -m64 -mcmodel=medium
ESMF_F90LINKOPTS += -m64 -mcmodel=medium
endif
############################################################
# Conditionally add pthread compiler and linker flags
#
ifeq ($(ESMF_PTHREADS),ON)
ESMF_F90COMPILEOPTS += -pthread -frecursive
ESMF_CXXCOMPILEOPTS += -pthread
ESMF_CCOMPILEOPTS += -pthread
ESMF_F90LINKOPTS += -pthread
ESMF_CXXLINKOPTS += -pthread
ESMF_CLINKOPTS += -pthread
endif
############################################################
# OpenMP compiler and linker flags
#
ESMF_OPENMP=OFF
ESMF_OPENMP_F90COMPILEOPTS += -fopenmp
# As of 2022-12-05, Apple's clang doesn't support -fopenmp directly; instead, it requires
# -Xpreprocessor -fopenmp. In addition, you will need to install libomp and explicitly add
# the appropriate include and link directories and libraries to pull it in (this is not
# done here yet).
ESMF_OPENMP_CXXCOMPILEOPTS += -Xpreprocessor -fopenmp
ESMF_OPENMP_F90LINKOPTS += -fopenmp
ESMF_OPENMP_CXXLINKOPTS += -Xpreprocessor -fopenmp
############################################################
# Need this until the file convention is fixed (then remove these two lines)
#
ESMF_F90COMPILEFREENOCPP = -ffree-form
ESMF_F90COMPILEFIXCPP = -cpp -ffixed-form
############################################################
# Set unlimited line length limit for free format files
#
ESMF_F90COMPILEOPTS += -ffree-line-length-none
############################################################
# Trying to produce a backtrace can lead programs to hang without any useful information
# rather than aborting cleanly, so disable backtraces.
#
ESMF_F90COMPILEOPTS += -fno-backtrace
############################################################
# Set rpath syntax
#
ESMF_F90RPATHPREFIX = -Wl,-rpath,
ESMF_CXXRPATHPREFIX = -Wl,-rpath,
ESMF_CRPATHPREFIX = -Wl,-rpath,
############################################################
# Determine where gfortran's libraries are located
#
# Note that the result of -print-file-name will be the full path to the file if it is found
# within the compiler installation, and simply the file name verbatim if it is NOT found.
ESMF_LIBGFORTRAN := $(shell $(ESMF_F90COMPILER) -print-file-name=libgfortran.dylib)
ifeq ($(ESMF_LIBGFORTRAN),libgfortran.dylib)
ESMF_LIBGFORTRAN := $(shell $(ESMF_F90COMPILER) -print-file-name=libgfortran.a)
endif
ESMF_CXXLINKPATHS += -L$(dir $(ESMF_LIBGFORTRAN))
ESMF_CXXLINKRPATHS += $(ESMF_CXXRPATHPREFIX)$(dir $(ESMF_LIBGFORTRAN))
# With clang, we use a C++ linker for Fortran programs, so use the same link paths as for CXX:
ESMF_F90LINKPATHS += -L$(dir $(ESMF_LIBGFORTRAN))
ESMF_F90LINKRPATHS += $(ESMF_CXXRPATHPREFIX)$(dir $(ESMF_LIBGFORTRAN))
############################################################
# Link against the c++ library
#
# Although we use the C++ linker for Fortran programs under ESMF, users might not, so still
# add on the C++ specific information
#
# Note that the result of -print-file-name will be the full path to the file if it is found
# within the compiler installation, and simply the file name verbatim if it is NOT found.
ESMF_LIBSTDCXX := $(shell $(ESMF_CXXCOMPILER) -print-file-name=libc++.dylib)
ifeq ($(ESMF_LIBSTDCXX),libc++.dylib)
ESMF_LIBSTDCXX := $(shell $(ESMF_CXXCOMPILER) -print-file-name=libc++.a)
endif
ESMF_F90LINKPATHS += -L$(dir $(ESMF_LIBSTDCXX))
ESMF_F90LINKLIBS += -lm -lc++
############################################################
# Link against libesmf.a using the C++ linker front-end
#
ESMF_CXXLINKLIBS += -lgfortran
# With clang, we use a C++ linker for Fortran programs, so use the same link libs as for CXX:
ESMF_F90LINKLIBS += -lgfortran
############################################################
# Shared library options
ESMF_SL_LIBOPTS += -dynamiclib
# No need for "$(ESMF_F90LINKPATHS) $(ESMF_F90LINKLIBS)" in the following because they are identical to the CXX versions:
ESMF_SL_LIBLIBS += $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKLIBS)
############################################################
# Static builds on Darwin do not support trace lib due to missing linker option
ifeq ($(ESMF_SHARED_LIB_BUILD),OFF)
ESMF_TRACE_LIB_BUILD = OFF
endif
############################################################
# Shared object options
#
ESMF_SO_F90COMPILEOPTS = -fPIC
ESMF_SO_F90LINKOPTS = -shared
ESMF_SO_CXXCOMPILEOPTS = -fPIC
ESMF_SO_CXXLINKOPTS = -shared