-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
233 lines (207 loc) · 6.83 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
# ======================================================================
# Makefile for SA_MESH
# ======================================================================
# Make targets (defined below).
.PHONY: default gfortran ifort mingw_static mpi_gcc mpi_intel symbols debug netcdf all clean veryclean
default: all
# ======================================================================
# Options.
# If the variable is not defined, an assumed value is assigned.
# Options can be overwritten by user overrides or scripts.
# DIST: Compiler family/distribution.
# - Blank/undefined to use GNU/GCC compiler (default).
# - 'intel' to use Intel compiler.
# - 'mingw' to use GNU/GCC compiler; overrides 'rm' with 'del' for MS-Windows/MS-DOS environment.
# MPI: Parallel/serial compilation.
# - Blank/undefined to compile in serial (default).
# - 'ompi' to compile using OMPI compiler.
# LSS: Land surface scheme (LSS).
# - Blank/undefined to include default versions of CLASS+SVS (default).
# ROUTE: Routing scheme.
# - Blank/undefined to include default versions of WF_ROUTE,SA_RTE+RTE (default).
# DEBUG: Debugging flags and options.
# - Blank/undefined to compile with 'o2' optimization (default).
# - 'yes' to include debug options and disable compiler optimization.
# ======================================================================
# File/object names.
include makefile.def
# ======================================================================
# Pre-configured targets: Compiler options.
ifeq ($(filter gfortran,$(MAKECMDGOALS)),gfortran)
DIST=
MPI=
else ifeq ($(filter ifort,$(MAKECMDGOALS)),ifort)
DIST=intel
MPI=
else ifeq ($(filter mingw_static,$(MAKECMDGOALS)),mingw_static)
DIST=mingw
MPI=
else ifeq ($(filter mpi_gcc,$(MAKECMDGOALS)),mpi_gcc)
DIST=
MPI=ompi
else ifeq ($(filter mpi_intel,$(MAKECMDGOALS)),mpi_intel)
DIST=intel
MPI=ompi
endif
# ======================================================================
# Pre-configured targets: Debug symbols.
ifeq ($(filter debug,$(MAKECMDGOALS)),debug)
SYMBOLS=yes
DEBUG=yes
else ifeq ($(filter symbols,$(MAKECMDGOALS)),symbols)
SYMBOLS=yes
endif
# ======================================================================
# Pre-configured targets: Double precision (where supported).
ifeq ($(filter double,$(MAKECMDGOALS)),double)
DOUBLE=yes
endif
# ======================================================================
# Pre-configured targets: netCDF library.
# This target will call 'nf-config' via the active shell.
# However, if the netCDF library is installed,
# 'nf-config' should be installed as well.
ifeq ($(filter netcdf,$(MAKECMDGOALS)),netcdf)
LIBNCO=$(shell nf-config --fflags) -DNETCDF
LIBNCL=$(shell nf-config --flibs)
endif
# ======================================================================
# Targets.
gfortran: all
ifort: all
mingw_static: all
mpi_gcc: all
mpi_intel: all
symbols: all
debug: all
double: all
netcdf: all
# ======================================================================
# Compiler check (if not the 'clean' or 'veryclean' targets).
# Minimum requirement.
# Intel 16+ (15+):
# - Intel 15 introduces full Fortran 2003 support but is untested.
# - Intel 14 will compile but may stall during run-time. This is
# presumed to be the result of partial Fortran 2003 support.
# GNU/gcc 5+:
# - GNU/gcc 4 does not implement the necessary Fortran 2003 features.
ifeq ($(filter clean veryclean, $(MAKECMDGOALS)), )
ifeq ($(DIST),intel)
ifeq ($(shell test $$(icc -dumpversion | cut -d '.' -f 1) -lt 16; echo $$?), 0)
$(error The code requires Intel compiler version 16 or higher)
endif
else
ifeq ($(shell test $$(gcc -dumpversion | cut -d '.' -f 1) -lt 5; echo $$?), 0)
$(error The code requires GNU/gcc and GNU/gfortran version 5 or higher)
endif
endif
endif
# ======================================================================
# Compiler and options.
# 'FTN90PP' and 'FTN90PPOPT' required to compile 'ftn90' files.
ifeq ($(DIST),intel)
FC=ifort
CC=icc
GFLAG=-check bounds -fpe0 #-stand f03 #-assume realloc-lhs #-check all
LFLAG=-c -g -traceback -fp-model source
CFLAG=
ifeq ($(shell test $$(icc -dumpversion | cut -d '.' -f 1) -lt 17; echo $$?), 0)
CFLAG+= -no-multibyte-chars
endif
FTN90PP=-fpp -free
FTN90PPOPT=-Tf
else
FC=gfortran
CC=gcc
GFLAG=-fbounds-check -ffpe-trap=invalid,zero,overflow -Wconversion -Wsurprising -Wintrinsic-shadow -Wtarget-lifetime #-std=f2003 #-fcheck=all -ftrapv
ifeq ($(shell test $$(gcc -dumpversion | cut -d '.' -f 1) -gt 5; echo $$?), 0)
GFLAG+= -Winteger-division
endif
LFLAG=-c -g -fbacktrace
CFLAG=
FTN90PP=-x f95 -cpp -ffree-form -ffree-line-length-none -fcray-pointer
FTN90PPOPT=
endif
# Override debugging options if 'DEBUG' not enabled.
ifndef DEBUG
GFLAG=
ifndef SYMBOLS
LFLAG=-c -O2
ifeq ($(DIST),intel)
LFLAG=-c -O2 -fp-model precise
endif
endif
CLEANUP=@$(MAKE) -s clean DIST=$(DIST)
endif
# Override compile options if 'DOUBLE' enabled.
ifdef DOUBLE
ifeq ($(DIST),intel)
LFLAG+=-r8
else
LFLAG+=-fdefault-double-8 -fdefault-real-8
endif
endif
# Output: sa_mesh.
OUT=sa_mesh
# If MPI is enabled, switch to OMPI compiler and rename output.
# Otherwise add MPI stub to 'OBJECTS'.
ifeq ($(MPI),ompi)
ifeq (,$(shell which mpifort))
FC=mpif90
else
FC=mpifort
endif
CC=mpicc
OUT=mpi_sa_mesh
else
OBJECTS:= mpi_stub.o $(OBJECTS)
endif
# Override 'rm' with 'del' and add static option for MinGW.
ifeq ($(DIST),mingw)
BIN_DEL=del
LLINK=-static
FC=gfortran
CC=gcc
OUT=sa_mesh_static
else
BIN_DEL=rm
endif
# ======================================================================
# General rules.
%.o: %.f
$(FC) $(LFLAG) $(GFLAG) $(LIBNCO) $<
%.o: %.F90
$(FC) $(FTN90PP) $(LFLAG) $(GFLAG) $(INC_DIRS) $(DFLAG) $(LIBNCO) $(FTN90PPOPT) $<
%.o: %.f90
$(FC) $(FTN90PP) $(LFLAG) $(GFLAG) $(LIBNCO) $<
%.o: %.for
$(FC) $(LFLAG) $(GFLAG) $(LIBNCO) $<
%.o: %.c
$(CC) $(LFLAG) $(CFLAG) $(INC_DIRS) $<
# ======================================================================
# Special rules.
EF_Module.o: EF_ParseUtilities.o
%.o: %.ftn90
$(FC) $(FTN90PP) $(LFLAG) $(INC_DIRS) $(DFLAG) $(FTN90PPOPT)$<
%.o: %.cdk90
$(FC) $(FTN90PP) $(LFLAG) $(INC_DIRS) $(DFLAG) $(FTN90PPOPT)$<
# ======================================================================
# Files renamed for SVS.
runsvs_mod.o: runsvs_mod_sa_mesh.ftn90
$(FC) $(FTN90PP) $(LFLAG) $(INC_DIRS) $(DFLAG) -o runsvs_mod.o $(FTN90PPOPT)$<
# ======================================================================
# Make target: all
# Deletes object and modules files unless 'DEBUG' has a value.
all: ${OBJECTS}
$(FC) $(OBJECTS) -o $(OUT) $(LLINK) $(LIBNCL)
$(CLEANUP)
# ======================================================================
# Make target: clean
# Remove object and module files.
clean:
-$(BIN_DEL) *.mod *.o
# ======================================================================
# Make target: veryclean
# Remove object and module files, and output file.
veryclean: clean
-$(BIN_DEL) $(OUT)