Ticket #807: Linux-ftn-gnu.mk

File Linux-ftn-gnu.mk, 9.8 KB (added by m.hadfield, 5 years ago)
Line 
1# svn $Id$
2#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3# Copyright (c) 2002-2019 The ROMS/TOMS Group :::
4# Licensed under a MIT/X style license :::
5# See License_ROMS.txt :::
6#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
7#
8# Include file for CRAY ftn compiler with PrgEnv-gnu
9# -------------------------------------------------------------------------
10#
11# ARPACK_LIBDIR ARPACK libary directory
12# FC Name of the fortran compiler to use
13# FFLAGS Flags to the fortran compiler
14# CPP Name of the C-preprocessor
15# CPPFLAGS Flags to the C-preprocessor
16# HDF5_INCDIR HDF5 include directory
17# HDF5_LIBDIR HDF5 library directory
18# HDF5_LIBS HDF5 library switches
19# NF_CONFIG NetCDF Fortran configuration script
20# NETCDF_INCDIR NetCDF include directory
21# NETCDF_LIBDIR NetCDF library directory
22# NETCDF_LIBS NetCDF library switches
23# LD Program to load the objects into an executable
24# LDFLAGS Flags to the loader
25# RANLIB Name of ranlib command
26# MDEPFLAGS Flags for sfmakedepend (-s if you keep .f files)
27#
28# First the defaults
29#
30 FC := ftn
31 FFLAGS := -frepack-arrays
32 FIXEDFLAGS := -ffixed-form
33 FREEFLAGS := -ffree-form -ffree-line-length-none
34 CPP := /usr/bin/cpp
35 CPPFLAGS := -P -traditional -w
36 INCDIR := /usr/include /usr/local/bin
37 SLIBS := -L/usr/local/lib -L/usr/lib
38 ULIBS :=
39 LIBS :=
40 MOD_SUFFIX := mod
41 LD := $(FC)
42 LDFLAGS :=
43 AR := ar
44 ARFLAGS := -r
45 MKDIR := mkdir -p
46 CP := cp -p -v
47 RM := rm -f
48 RANLIB := ranlib
49 PERL := perl
50 TEST := test
51
52#--------------------------------------------------------------------------
53# Compiling flags for ROMS Applications.
54#--------------------------------------------------------------------------
55
56ifdef USE_ROMS
57 ifdef USE_DEBUG
58 FFLAGS += -g
59 FFLAGS += -fbounds-check
60 FFLAGS += -fbacktrace
61 FFLAGS += -fcheck=all
62# FFLAGS += -fsanitize=address -fsanitize=undefined
63 FFLAGS += -finit-real=nan -ffpe-trap=invalid,zero,overflow
64 else
65 FFLAGS += -O3
66 FFLAGS += -ffast-math
67 endif
68 MDEPFLAGS := --cpp --fext=f90 --file=- --objdir=$(SCRATCH_DIR)
69endif
70
71#--------------------------------------------------------------------------
72# Compiling flags for CICE Applications.
73#--------------------------------------------------------------------------
74
75ifdef CICE_APPLICATION
76 CPPDEFS := -DLINUS $(MY_CPP_FLAGS)
77 ifdef USE_DEBUG
78 FFLAGS += -g
79 FFLAGS += -fbounds-check
80 else
81 FFLAGS := -O3 -w
82 endif
83endif
84
85#--------------------------------------------------------------------------
86# Coupled models. Notice Linux needs the libraries repeated for
87# dependencies for some of the coupled components.
88#--------------------------------------------------------------------------
89
90ifdef USE_COAMPS
91 LIBS += $(COAMPS_LIB_DIR)/coamps_driver.a
92 LIBS += $(COAMPS_LIB_DIR)/libaa.a
93 LIBS += $(COAMPS_LIB_DIR)/libam.a
94 LIBS += $(COAMPS_LIB_DIR)/libashare.a
95 LIBS += $(COAMPS_LIB_DIR)/libcoamps.a
96 LIBS += $(COAMPS_LIB_DIR)/libfnoc.a
97 LIBS += $(COAMPS_LIB_DIR)/libaa.a
98 LIBS += $(COAMPS_LIB_DIR)/libam.a
99 LIBS += $(COAMPS_LIB_DIR)/libashare.a
100 LIBS += $(COAMPS_LIB_DIR)/libcoamps.a
101 LIBS += $(COAMPS_LIB_DIR)/libfnoc.a
102 LIBS += $(COAMPS_LIB_DIR)/libfishpak.a
103 LIBS += $(COAMPS_LIB_DIR)/libtracer.a
104endif
105
106ifdef USE_WRF
107 LIBS += $(WRF_LIB_DIR)/module_wrf_top.o
108 LIBS += $(WRF_LIB_DIR)/libwrflib.a
109 LIBS += $(WRF_LIB_DIR)/libfftpack.a
110 LIBS += $(WRF_LIB_DIR)/libio_grib1.a
111 LIBS += $(WRF_LIB_DIR)/libio_grib_share.a
112 LIBS += $(WRF_LIB_DIR)/libwrfio_int.a
113 LIBS += $(WRF_LIB_DIR)/libesmf_time.a
114 LIBS += $(WRF_LIB_DIR)/librsl_lite.a
115 LIBS += $(WRF_LIB_DIR)/module_internal_header_util.o
116 LIBS += $(WRF_LIB_DIR)/pack_utils.o
117 LIBS += $(WRF_LIB_DIR)/libwrfio_nf.a
118endif
119
120ifdef CICE_APPLICATION
121 SLIBS := $(LIBS) $(SLIBS)
122endif
123
124#--------------------------------------------------------------------------
125# Library locations, can be overridden by environment variables.
126#--------------------------------------------------------------------------
127
128 LDFLAGS := $(FFLAGS)
129
130ifdef USE_NETCDF4
131 NF_CONFIG ?= nf-config
132 NETCDF_INCDIR ?= $(shell $(NF_CONFIG) --prefix)/include
133 LIBS += $(shell $(NF_CONFIG) --flibs)
134 INCDIR += $(NETCDF_INCDIR) $(INCDIR)
135else
136 NETCDF_INCDIR ?= /opt/cray/pe/netcdf/default/gnu/7.1/include
137 NETCDF_LIBDIR ?= /opt/cray/pe/netcdf/default/gnu/7.1/lib
138 NETCDF_LIBS ?= -lnetcdf
139 LIBS += -L$(NETCDF_LIBDIR) $(NETCDF_LIBS)
140 INCDIR += $(NETCDF_INCDIR) $(INCDIR)
141endif
142
143ifdef USE_HDF5
144 HDF5_INCDIR ?= /opt/cray/hdf5/default/gnu/7.1/include
145 HDF5_LIBDIR ?= /opt/cray/hdf5/default/gnu/7.1/lib
146 HDF5_LIBS ?= -lhdf5_fortran -lhdf5hl_fortran -lhdf5 -lz
147 LIBS += -L$(HDF5_LIBDIR) $(HDF5_LIBS)
148 INCDIR += $(HDF5_INCDIR)
149endif
150
151ifdef USE_ARPACK
152 ifdef USE_MPI
153 PARPACK_LIBDIR ?= /usr/local/lib
154 LIBS += -L$(PARPACK_LIBDIR) -lparpack
155 endif
156 ARPACK_LIBDIR ?= /usr/local/lib
157 LIBS += -L$(ARPACK_LIBDIR) -larpack
158endif
159
160ifdef USE_MPI
161 CPPFLAGS += -DMPI
162endif
163
164ifdef USE_OpenMP
165 CPPFLAGS += -D_OPENMP
166 FFLAGS += -fopenmp
167endif
168
169ifdef USE_MCT
170 MCT_INCDIR ?= /usr/local/mct/include
171 MCT_LIBDIR ?= /usr/local/mct/lib
172 FFLAGS += -I$(MCT_INCDIR)
173 LIBS += -L$(MCT_LIBDIR) -lmct -lmpeu
174 INCDIR += $(MCT_INCDIR) $(INCDIR)
175endif
176
177ifdef USE_ESMF
178 ESMF_OS ?= $(OS)
179 ESMF_SUBDIR := $(ESMF_OS).$(ESMF_COMPILER).$(ESMF_ABI).$(ESMF_COMM).$(ESMF_SITE)
180 ESMF_MK_DIR ?= $(ESMF_DIR)/lib/lib$(ESMF_BOPT)/$(ESMF_SUBDIR)
181 include $(ESMF_MK_DIR)/esmf.mk
182 FFLAGS += $(ESMF_F90COMPILEPATHS)
183 LIBS += $(ESMF_F90LINKPATHS) $(ESMF_F90ESMFLINKLIBS)
184endif
185
186# Use full path of compiler.
187
188 FC := $(shell which ${FC})
189 LD := $(FC)
190
191#--------------------------------------------------------------------------
192# ROMS specific rules.
193#--------------------------------------------------------------------------
194
195# Turn off bounds checking for function def_var, as "dimension(*)"
196# declarations confuse Gnu Fortran 95 bounds-checking code.
197
198ifdef USE_ROMS
199 $(SCRATCH_DIR)/def_var.o: FFLAGS += -fno-bounds-check
200endif
201
202# Allow integer overflow in ran_state.F. This is not allowed
203# during -O3 optimization. This option should be applied only for
204# Gfortran versions >= 4.2.
205
206ifdef USE_ROMS
207 FC_TEST := $(findstring $(shell ${FC} --version | head -1 | \
208 awk '{ sub("Fortran 95", "Fortran"); print }' | \
209 cut -d " " -f 4 | \
210 cut -d "." -f 1-2), \
211 4.0 4.1)
212
213 ifeq "${FC_TEST}" ""
214 $(SCRATCH_DIR)/ran_state.o: FFLAGS += -fno-strict-overflow
215 endif
216endif
217
218# Set free form format in some ROMS source files to allow long string for
219# local directory and compilation flags inside the code.
220
221ifdef USE_ROMS
222 $(SCRATCH_DIR)/mod_ncparam.o: FFLAGS += $(FREEFLAGS)
223 $(SCRATCH_DIR)/mod_strings.o: FFLAGS += $(FREEFLAGS)
224 $(SCRATCH_DIR)/analytical.o: FFLAGS += $(FREEFLAGS)
225 $(SCRATCH_DIR)/biology.o: FFLAGS += $(FREEFLAGS)
226
227 ifdef USE_ADJOINT
228 $(SCRATCH_DIR)/ad_biology.o: FFLAGS += $(FREEFLAGS)
229 endif
230 ifdef USE_REPRESENTER
231 $(SCRATCH_DIR)/rp_biology.o: FFLAGS += $(FREEFLAGS)
232 endif
233 ifdef USE_TANGENT
234 $(SCRATCH_DIR)/tl_biology.o: FFLAGS += $(FREEFLAGS)
235 endif
236endif
237
238#--------------------------------------------------------------------------
239# Model coupling specific rules.
240#--------------------------------------------------------------------------
241
242# Add COAMPS library directory to include path of ESMF coupling files.
243
244ifdef USE_COAMPS
245 $(SCRATCH_DIR)/esmf_atm.o: FFLAGS += -I$(COAMPS_LIB_DIR)
246 $(SCRATCH_DIR)/esmf_esm.o: FFLAGS += -I$(COAMPS_LIB_DIR)
247endif
248
249# Add WRF library directory to include path of ESMF coupling files.
250
251ifdef USE_WRF
252 ifeq "$(strip $(WRF_LIB_DIR))" "$(WRF_SRC_DIR)"
253 $(SCRATCH_DIR)/esmf_atm.o: FFLAGS += $(addprefix -I$(WRF_LIB_DIR)/,$(WRF_MOD_DIRS))
254 else
255 $(SCRATCH_DIR)/esmf_atm.o: FFLAGS += -I$(WRF_LIB_DIR)
256 endif
257endif
258
259# Supress free format in SWAN source files since there are comments
260# beyond column 72.
261
262ifdef USE_SWAN
263 $(SCRATCH_DIR)/ocpcre.o: FFLAGS += $(FIXEDFLAGS)
264 $(SCRATCH_DIR)/ocpids.o: FFLAGS += $(FIXEDFLAGS)
265 $(SCRATCH_DIR)/ocpmix.o: FFLAGS += $(FIXEDFLAGS)
266 $(SCRATCH_DIR)/swancom1.o: FFLAGS += $(FIXEDFLAGS)
267 $(SCRATCH_DIR)/swancom2.o: FFLAGS += $(FIXEDFLAGS)
268 $(SCRATCH_DIR)/swancom3.o: FFLAGS += $(FIXEDFLAGS)
269 $(SCRATCH_DIR)/swancom4.o: FFLAGS += $(FIXEDFLAGS)
270 $(SCRATCH_DIR)/swancom5.o: FFLAGS += $(FIXEDFLAGS)
271 $(SCRATCH_DIR)/swanmain.o: FFLAGS += $(FIXEDFLAGS)
272 $(SCRATCH_DIR)/swanout1.o: FFLAGS += $(FIXEDFLAGS)
273 $(SCRATCH_DIR)/swanout2.o: FFLAGS += $(FIXEDFLAGS)
274 $(SCRATCH_DIR)/swanparll.o: FFLAGS += $(FIXEDFLAGS)
275 $(SCRATCH_DIR)/swanpre1.o: FFLAGS += $(FIXEDFLAGS)
276 $(SCRATCH_DIR)/swanpre2.o: FFLAGS += $(FIXEDFLAGS)
277 $(SCRATCH_DIR)/swanser.o: FFLAGS += $(FIXEDFLAGS)
278 $(SCRATCH_DIR)/swmod1.o: FFLAGS += $(FIXEDFLAGS)
279 $(SCRATCH_DIR)/swmod2.o: FFLAGS += $(FIXEDFLAGS)
280 $(SCRATCH_DIR)/m_constants.o: FFLAGS += $(FREEFLAGS)
281 $(SCRATCH_DIR)/m_fileio.o: FFLAGS += $(FREEFLAGS)
282 $(SCRATCH_DIR)/mod_xnl4v5.o: FFLAGS += $(FREEFLAGS)
283 $(SCRATCH_DIR)/serv_xnl4v5.o: FFLAGS += $(FREEFLAGS)
284endif