Rules.make 6.98 KB
Newer Older
gotm's avatar
gotm committed
1 2 3 4 5 6
#
# This file contains rules which are shared between multiple Makefiles.
# This file is quite complicated - all compilation options are set in this
# file and included in all other Makefiles.
# Here you set the fortran compiler and the compilation mode (debug,prof,prod)
# If you want to include info for a new compiler - please know what you are 
7
# doing - then add a new file to the directory ../compilers.
gotm's avatar
gotm committed
8 9

SHELL   = /bin/sh
10 11
CPP	= /lib/cpp

12 13 14
# Top of this version of GETM and GOTM. Defaults can be overwritten using 
# environment variables.
ifndef GETMDIR
15
GETMDIR  = $(HOME)/GETM/getm-git
16
endif
17 18 19
ifeq ($(wildcard $(GETMDIR)/src/getm/main.F90),)
$(error the directory GETMDIR=$(GETMDIR) is not a valid GETM directory)
endif
20 21

ifndef GOTMDIR
22
GOTMDIR = $(HOME)/GOTM/gotm-git
23
endif
24 25 26 27
ifeq ($(wildcard $(GOTMDIR)/src/gotm/gotm.F90),)
$(error the directory GOTMDIR=$(GOTMDIR) is not a valid GOTM directory)
endif

28

29 30 31 32 33 34
# Information about which Fortran compiler to use is 
# obtained from $(FORTRAN_COMPILER) - environment variable.
# The file ../compilers/compiler.$(FORTRAN_COMPILER) must exist

DEFINES=-D$(FORTRAN_COMPILER)
include $(GETMDIR)/compilers/compiler.$(FORTRAN_COMPILER)
gotm's avatar
gotm committed
35 36 37 38 39 40 41 42 43

# The compilation mode is obtained from $COMPILATION_MODE
# default production - else debug or profiling
ifndef COMPILATION_MODE
compilation=production
else
compilation=$(COMPILATION_MODE)
endif

44
# 2D compilation only
45 46 47 48 49
ifeq ($(GETM_NO_3D),true)
DEFINES += -DNO_3D
export GETM_NO_BAROCLINIC=true
endif

50
# 3D barotropic
51 52
ifeq ($(GETM_NO_BAROCLINIC),true)
DEFINES += -DNO_BAROCLINIC
Knut's avatar
Knut committed
53
export FABM=false
54 55
endif

56
# Suspended matter
kbk's avatar
kbk committed
57 58
ifeq ($(GETM_SPM),true)
DEFINES += -DSPM
59 60
endif

61 62 63 64 65
# Structure friction
ifeq ($(GETM_STRUCTURE_FRICTION),true)
DEFINES += -DSTRUCTURE_FRICTION
endif

bjb's avatar
bjb committed
66 67 68 69 70
# Remove timers
ifeq ($(GETM_NO_TIMERS),true)
DEFINES += -DNO_TIMERS
endif

gotm's avatar
gotm committed
71 72
# Here you can put defines for the [c|f]pp - some will also be set depending
# on compilation mode - if STATIC is defined be careful.
Karsten Bolding's avatar
Karsten Bolding committed
73 74

# It is not necessary to set INPUT_DIR
75 76 77
ifdef INPUT_DIR
DEFINES += -DINPUT_DIR="'$(INPUT_DIR)/'"
endif
gotm's avatar
gotm committed
78 79 80 81 82 83
#DEFINES += -DSPHERICAL
#DEFINES += -DCURVILINEAR
#DEFINES += -DNO_BOTTFRIC
#DEFINES += -DNO_ADVECT
#DEFINES += -DNO_SLR
#DEFINES += -DNEW_CORI
kbk's avatar
kbk committed
84
#DEFINES += -DCONSTANT_VISCOSITY
gotm's avatar
gotm committed
85 86 87 88 89 90 91
#DEFINES += -DPARABOLIC_VISCOSITY
#DEFINES += -DNEW_METHOD_KBK
#DEFINES += -DMIN_VEL_DEPTH
#DEFINES += -DPRESS_GRAD_Z
#DEFINES += -DITERATE_VERT_ADV
#DEFINES += -DSUBSTR_INI_PRESS
#DEFINES += -DSONG_WRIGHT
92
#DEFINES += -D_MOMENTUM_TERMS_
gotm's avatar
gotm committed
93

94
# Further directory related settings.
gotm's avatar
gotm committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
ifndef BINDIR
BINDIR	= $(GETMDIR)/bin
endif

ifndef LIBDIR
LIBDIR  = $(GETMDIR)/lib/$(FORTRAN_COMPILER)
endif

ifndef MODDIR
MODDIR	= $(GETMDIR)/modules/$(FORTRAN_COMPILER)
endif

INCDIRS		= -I$(GETMDIR)/include -I$(MODDIR)
LINKDIRS	= -L$(LIBDIR)
EXTRA_LIBS	=

111 112 113 114 115
# Turbulence directory
ifdef GOTM_PREFIX

GOTMLIBDIR	= $(GOTM_PREFIX)/lib
LINKDIRS	+= -L$(GOTMLIBDIR)
Knut's avatar
Knut committed
116 117 118 119
ifeq ($(GETM_FLEXIBLE_OUTPUT),true)
DEFINES += -D_FLEXIBLE_OUTPUT_
EXTRA_LIBS	+= -loutput_manager
endif
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
ifeq ($(FABM),true)
EXTRA_LIBS	+= -lgotm_fabm
endif
EXTRA_LIBS	+= -lturbulence -lutil
INCDIRS		+= -I$(GOTM_PREFIX)/include

else

GOTMLIBDIR	= $(GOTMDIR)/lib/$(FORTRAN_COMPILER)
LINKDIRS	+= -L$(GOTMLIBDIR)
ifeq ($(FABM),true)
EXTRA_LIBS	+= -lgotm_fabm$(buildtype)
endif
EXTRA_LIBS	+= -lturbulence$(buildtype) -lutil$(buildtype)
INCDIRS		+= -I$(GOTMDIR)/modules/$(FORTRAN_COMPILER)

endif


Karsten Bolding's avatar
Karsten Bolding committed
139 140
# FABM-geochemical component
ifeq ($(FABM),true)
141

Karsten Bolding's avatar
Karsten Bolding committed
142
DEFINES += -D_FABM_
143 144
FEATURES += fabm

Knut's avatar
Knut committed
145
export GETM_BIO=false
146

147 148
ifdef FABM_PREFIX

149 150 151 152 153 154
ifeq ($(wildcard $(FABM_PREFIX)/lib/libfabm.*), )
$(error the directory FABM_PREFIX=$(FABM_PREFIX) is not a valid FABM directory)
endif

INCDIRS         += -I$(FABM_PREFIX)/include
LINKDIRS        += -L$(FABM_PREFIX)/lib
155
EXTRA_LIBS	+= -lfabm
156 157 158

else

Karsten Bolding's avatar
Karsten Bolding committed
159
ifndef FABMDIR
160
FABMDIR = $(HOME)/FABM/fabm-git
Karsten Bolding's avatar
Karsten Bolding committed
161
endif
162

163 164 165
ifeq ($(wildcard $(FABMDIR)/src/fabm.F90),)
$(error the directory FABMDIR=$(FABMDIR) is not a valid FABM directory)
endif
Karsten Bolding's avatar
Karsten Bolding committed
166 167
INCDIRS    += -I$(FABMDIR)/include -I$(FABMDIR)/modules/gotm/$(FORTRAN_COMPILER) -I$(FABMDIR)/src/drivers/gotm
LINKDIRS   += -L$(FABMDIR)/lib/gotm/$(FORTRAN_COMPILER)
168
EXTRA_LIBS	+= -lfabm$(buildtype)
169 170 171

endif

Karsten Bolding's avatar
Karsten Bolding committed
172 173 174
endif

# Old GOTM-BIO component - deprecated
175
ifeq ($(GETM_BIO),true)
Karsten Bolding's avatar
Karsten Bolding committed
176
DEFINES    += -DGETM_BIO
177 178 179
EXTRA_LIBS += -lbio$(buildtype)
endif

gotm's avatar
gotm committed
180
# Where does the NetCDF include file and library reside.
Knut's avatar
Knut committed
181
NETCDF_VERSION?=NETCDF4
Karsten Bolding's avatar
Karsten Bolding committed
182 183 184
ifeq ($(NETCDF_VERSION),NETCDF4)

DEFINES		+= -DNETCDF4
Knut's avatar
Knut committed
185
# this does not work for shared libs
186
INCDIRS		+= -I$(shell nf-config --includedir)
Knut's avatar
Knut committed
187 188
# this includes optimisation flags from the netcdf compilation
#INCDIRS		+= $(shell nf-config --fflags)
189
NETCDFLIB	=  $(shell nf-config --flibs)
Karsten Bolding's avatar
Karsten Bolding committed
190 191 192 193

else  # NetCDF3 is default

DEFINES		+= -DNETCDF3
gotm's avatar
gotm committed
194 195 196
ifdef NETCDFINC
INCDIRS		+= -I$(NETCDFINC)
endif
197 198 199 200 201

ifdef NETCDFLIBDIR
LINKDIRS	+= -L$(NETCDFLIBDIR)
endif

gotm's avatar
gotm committed
202 203 204 205 206
ifdef NETCDFLIBNAME
NETCDFLIB	= $(NETCDFLIBNAME)
else
NETCDFLIB	= -lnetcdf
endif
207

208
endif
209

210
EXTRA_LIBS	+= $(NETCDFLIB)
211 212
# NetCDF/HDF configuration done

213 214
# Compile for parallel execution
ifeq ($(GETM_PARALLEL),true)
215
DEFINES += -DGETM_PARALLEL
216

kb's avatar
kb committed
217
# OPENMPI - set FC to mpif90
218 219
ifeq ($(MPI),OPENMPI)
FC=mpif90
kb's avatar
kb committed
220 221 222 223 224 225 226
endif

# MPICH2 - set FC to mpif90
ifeq ($(MPI),MPICH2)
FC=mpif90
endif

Knut's avatar
Knut committed
227 228 229 230 231 232 233 234 235 236 237 238
ifeq ($(MPI),INTELMPI)
ifeq ($(FORTRAN_COMPILER),IFORT)
FC=mpiifort
else
ifeq ($(FORTRAN_COMPILER),GFORTRAN)
FC=mpif90
else
FC=mpifc
endif
endif
endif

kb's avatar
kb committed
239 240 241 242 243
# SGI - MPI - works for Peter Holtermann on ALTIX 3700.
ifeq ($(MPI),SGIMPI)
EXTRA_LIBS      += -lmpi
endif

kb's avatar
kb committed
244
# obsolete - use either OPenMPI or MPICH2
245
# Where does the MPI library reside.
kb's avatar
kb committed
246
ifeq ($(MPI),MPICH)
gotm's avatar
gotm committed
247 248 249 250 251 252
ifdef MPIINC
INCDIRS		+= -I$(MPIINC)
endif
ifdef MPIMOD
INCDIRS		+= -I$(MPIMOD)
endif
frv-bjb's avatar
frv-bjb committed
253 254 255
ifdef MPILIBFILE
MPILIB		= $(MPILIBFILE)
else
gotm's avatar
gotm committed
256 257 258
ifdef MPILIBNAME
MPILIB		= $(MPILIBNAME)
else
kb's avatar
kb committed
259
MPILIB		= -lmpich -lpthread
frv-bjb's avatar
frv-bjb committed
260
endif
gotm's avatar
gotm committed
261
ifdef MPILIBDIR
262
LINKFLAGS		+= -L$(MPILIBDIR)
gotm's avatar
gotm committed
263 264 265 266
LINKDIRS	+= -L$(MPILIBDIR)
endif
endif
EXTRA_LIBS	+= $(MPILIB)
267
endif
kb's avatar
kb committed
268

269
endif
270

gotm's avatar
gotm committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
DOCDIR		= $(GETMDIR)/doc

# Sets options for debug compilation
ifeq ($(compilation),debug)
buildtype = _debug
DEFINES += -DDEBUG $(STATIC)
FLAGS   = $(DEBUG_FLAGS) 
endif

# Sets options for profiling compilation
ifeq ($(compilation),profiling)
buildtype = _prof
DEFINES += -DPROFILING $(STATIC)
FLAGS   = $(PROF_FLAGS) 
endif

# Sets options for production compilation
ifeq ($(compilation),production)
buildtype = _prod
DEFINES += -DPRODUCTION $(STATIC)
FLAGS   = $(PROD_FLAGS) 
endif

Knut's avatar
Knut committed
294 295 296
# OpenMP computation (mostly with compiler directives anyway):
ifeq ($(GETM_OMP),true)
DEFINES += -DGETM_OMP
bjb's avatar
bjb committed
297 298 299
FLAGS   += $(OMP_FLAGS)
endif

gotm's avatar
gotm committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
# For making the source code documentation.
PROTEX	= protex -b -n -s

# It should not be necessary to change anything below this line - kbk
#
# False targets.
#
.PHONY: dummy

.SUFFIXES:
.SUFFIXES: .F90

CPPFLAGS	= $(DEFINES) $(INCDIRS)
FFLAGS  	= $(DEFINES) $(FLAGS) $(MODULES) $(INCDIRS) $(EXTRAS)
F90FLAGS  	= $(FFLAGS)
315
LINKFLAGS		= $(LDFLAGS) $(FFLAGS) $(LINKDIRS)
gotm's avatar
gotm committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

#
# Special variables which should not be exported
#
unexport SUBDIRS

#
# Common rules
#

ifeq  ($(can_do_F90),true)
%.o: %.F90
	$(FC) $(F90FLAGS) $(EXTRA_FFLAGS) -c $<
else
%.f90: %.F90
331 332
	$(F90_to_f90)
#	$(CPP) $(CPPFLAGS) $< -o $@
gotm's avatar
gotm committed
333 334 335 336

%.o: %.f90
	$(FC) $(F90FLAGS) $(EXTRA_FFLAGS) -c $< -o $@
endif