Ticket #762: Linux-gfortran.mk

File Linux-gfortran.mk, 5.8 KB (added by m.hadfield, 6 years ago)

Makefile for Linux-gfortran with netCDF-related fixes

Line 
1# svn $Id$
2#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
3# Copyright (c) 2002-2018 The ROMS/TOMS Group :::
4# Licensed under a MIT/X style license :::
5# See License_ROMS.txt :::
6#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
7#
8# Include file for GNU Fortran compiler on Linux
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# NF_CONFIG NetCDF Fortran configuration script
17# NETCDF_INCDIR NetCDF include directory
18# NETCDF_LIBDIR NetCDF library directory
19# NETCDF_LIBS NetCDF library switches
20# LD Program to load the objects into an executable
21# LDFLAGS Flags to the loader
22# RANLIB Name of ranlib command
23# MDEPFLAGS Flags for sfmakedepend (-s if you keep .f files)
24#
25# First the defaults
26#
27 FC := gfortran
28 FFLAGS := -frepack-arrays
29 CPP := /usr/bin/cpp
30 CPPFLAGS := -P -traditional
31 LDFLAGS :=
32 AR := ar
33 ARFLAGS := -r
34 MKDIR := mkdir -p
35 RM := rm -f
36 RANLIB := ranlib
37 PERL := perl
38 TEST := test
39
40 MDEPFLAGS := --cpp --fext=f90 --file=- --objdir=$(SCRATCH_DIR)
41
42#
43# Library locations, can be overridden by environment variables.
44#
45
46ifdef USE_NETCDF4
47 NF_CONFIG ?= nf-config
48 NETCDF_INCDIR ?= $(shell $(NF_CONFIG) --includedir)
49 LIBS := $(shell $(NF_CONFIG) --flibs)
50else
51 NETCDF_INCDIR ?= /usr/local/include
52 NETCDF_LIBDIR ?= /usr/local/lib
53 NETCDF_LIBS ?= -lnetcdf
54 LIBS := -L$(NETCDF_LIBDIR) $(NETCDF_LIBS)
55endif
56
57ifdef USE_ARPACK
58 ifdef USE_MPI
59 PARPACK_LIBDIR ?= /opt/gfortransoft/PARPACK
60 LIBS += -L$(PARPACK_LIBDIR) -lparpack
61 endif
62 ARPACK_LIBDIR ?= /opt/gfortransoft/PARPACK
63 LIBS += -L$(ARPACK_LIBDIR) -larpack
64endif
65
66ifdef USE_MPI
67 CPPFLAGS += -DMPI
68 ifdef USE_MPIF90
69 FC := mpif90
70 else
71 # MPI without mpif90 is not supported on this platform
72 endif
73endif
74
75ifdef USE_OpenMP
76 CPPFLAGS += -D_OPENMP
77 FFLAGS += -fopenmp
78endif
79
80ifdef USE_DEBUG
81 FFLAGS += -g -fbounds-check -fbacktrace -finit-real=nan -ffpe-trap=invalid,zero,overflow
82else
83 FFLAGS += -O3 -ffast-math
84endif
85
86ifdef USE_MCT
87 MCT_INCDIR ?= /usr/local/mct/include
88 MCT_LIBDIR ?= /usr/local/mct/lib
89 FFLAGS += -I$(MCT_INCDIR)
90 LIBS += -L$(MCT_LIBDIR) -lmct -lmpeu
91endif
92
93ifdef USE_ESMF
94 ESMF_OS ?= $(OS)
95 ESMF_SUBDIR := $(ESMF_OS).$(ESMF_COMPILER).$(ESMF_ABI).$(ESMF_COMM).$(ESMF_SITE)
96 ESMF_MK_DIR ?= $(ESMF_DIR)/lib/lib$(ESMF_BOPT)/$(ESMF_SUBDIR)
97 include $(ESMF_MK_DIR)/esmf.mk
98 FFLAGS += $(ESMF_F90COMPILEPATHS)
99 LIBS += $(ESMF_F90LINKPATHS) $(ESMF_F90ESMFLINKLIBS)
100endif
101
102#
103# Use full path of compiler.
104#
105 FC := $(shell which ${FC})
106 LD := $(FC)
107
108#
109# Turn off bounds checking for function def_var, as "dimension(*)"
110# declarations confuse Gnu Fortran 95 bounds-checking code.
111#
112
113$(SCRATCH_DIR)/def_var.o: FFLAGS += -fno-bounds-check
114
115#
116# Allow integer overflow in ran_state.F. This is not allowed
117# during -O3 optimization. This option should be applied only for
118# Gfortran versions >= 4.2.
119#
120
121FC_TEST := $(findstring $(shell ${FC} --version | head -1 | \
122 awk '{ sub("Fortran 95", "Fortran"); print }' | \
123 cut -d " " -f 4 | \
124 cut -d "." -f 1-2), \
125 4.0 4.1)
126
127ifeq "${FC_TEST}" ""
128$(SCRATCH_DIR)/ran_state.o: FFLAGS += -fno-strict-overflow
129endif
130
131#
132# Set free form format in source files to allow long string for
133# local directory and compilation flags inside the code.
134#
135
136$(SCRATCH_DIR)/mod_ncparam.o: FFLAGS += -ffree-form -ffree-line-length-none
137$(SCRATCH_DIR)/mod_strings.o: FFLAGS += -ffree-form -ffree-line-length-none
138$(SCRATCH_DIR)/analytical.o: FFLAGS += -ffree-form -ffree-line-length-none
139$(SCRATCH_DIR)/biology.o: FFLAGS += -ffree-form -ffree-line-length-none
140ifdef USE_ADJOINT
141$(SCRATCH_DIR)/ad_biology.o: FFLAGS += -ffree-form -ffree-line-length-none
142endif
143ifdef USE_REPRESENTER
144$(SCRATCH_DIR)/rp_biology.o: FFLAGS += -ffree-form -ffree-line-length-none
145endif
146ifdef USE_TANGENT
147$(SCRATCH_DIR)/tl_biology.o: FFLAGS += -ffree-form -ffree-line-length-none
148endif
149
150#
151# Supress free format in SWAN source files since there are comments
152# beyond column 72.
153#
154
155ifdef USE_SWAN
156
157$(SCRATCH_DIR)/ocpcre.o: FFLAGS += -ffixed-form
158$(SCRATCH_DIR)/ocpids.o: FFLAGS += -ffixed-form
159$(SCRATCH_DIR)/ocpmix.o: FFLAGS += -ffixed-form
160$(SCRATCH_DIR)/swancom1.o: FFLAGS += -ffixed-form
161$(SCRATCH_DIR)/swancom2.o: FFLAGS += -ffixed-form
162$(SCRATCH_DIR)/swancom3.o: FFLAGS += -ffixed-form
163$(SCRATCH_DIR)/swancom4.o: FFLAGS += -ffixed-form
164$(SCRATCH_DIR)/swancom5.o: FFLAGS += -ffixed-form
165$(SCRATCH_DIR)/swanmain.o: FFLAGS += -ffixed-form
166$(SCRATCH_DIR)/swanout1.o: FFLAGS += -ffixed-form
167$(SCRATCH_DIR)/swanout2.o: FFLAGS += -ffixed-form
168$(SCRATCH_DIR)/swanparll.o: FFLAGS += -ffixed-form
169$(SCRATCH_DIR)/swanpre1.o: FFLAGS += -ffixed-form
170$(SCRATCH_DIR)/swanpre2.o: FFLAGS += -ffixed-form
171$(SCRATCH_DIR)/swanser.o: FFLAGS += -ffixed-form
172$(SCRATCH_DIR)/swmod1.o: FFLAGS += -ffixed-form
173$(SCRATCH_DIR)/swmod2.o: FFLAGS += -ffixed-form
174$(SCRATCH_DIR)/m_constants.o: FFLAGS += -ffree-form -ffree-line-length-none
175$(SCRATCH_DIR)/m_fileio.o: FFLAGS += -ffree-form -ffree-line-length-none
176$(SCRATCH_DIR)/mod_xnl4v5.o: FFLAGS += -ffree-form -ffree-line-length-none
177$(SCRATCH_DIR)/serv_xnl4v5.o: FFLAGS += -ffree-form -ffree-line-length-none
178
179endif