forked from lawinslow/GLM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
327 lines (277 loc) · 9.39 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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
###############################################################################
# #
# Makefile for glm #
# #
# Part of GLM (General Lake Model) #
# #
# Developed by : #
# AquaticEcoDynamics (AED) Group #
# School of Earth & Environment #
# The University of Western Australia #
# #
# http://aed.see.uwa.edu.au/ #
# #
# Copyright 2013 - 2016 - The University of Western Australia #
# #
# GLM is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# GLM is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
OSTYPE=$(shell uname -s)
ifeq ($(WITH_PLOTS),)
WITH_PLOTS=true
ifeq ($(WITH_XPLOTS),)
WITH_XPLOTS=true
endif
ifeq ($(PLOTDIR),)
PLOTDIR=../libplot
endif
endif
ifeq ($(UTILDIR),)
UTILDIR=../libutil
endif
srcdir=src
incdir=src
objdir=obj
moddir=mod
TARGETS=glm
DEFINES=
FINCLUDES=-I$(UTILDIR)/include
CINCLUDES=-I$(UTILDIR)/include
LIBS=-L$(UTILDIR)/lib -lutil
GLM_DEPS=$(UTILDIR)/lib/libutil.a
ifeq ($(WITH_PLOTS),true)
DEFINES+=-DPLOTS
ifeq ($(WITH_XPLOTS),true)
DEFINES+=-DXPLOTS
endif
GLM_DEPS+=$(PLOTDIR)/lib/libplot.a
CINCLUDES+=-I$(PLOTDIR)/include
endif
ifeq ($(OSTYPE),Darwin)
ifeq ($(HOMEBREW),true)
FINCLUDES+=-I/usr/local/include
CINCLUDES+=-I/usr/local/include
LIBS+=-L/usr/local/lib
else
FINCLUDES+=-I/opt/local/include
CINCLUDES+=-I/opt/local/include
LIBS+=-L/opt/local/lib
endif
#EXTRALINKFLAGS=-Wl,-no_compact_unwind
EXTRALINKFLAGS=-Wl,-no_compact_unwind,-headerpad_max_install_names
else
EXTRALINKFLAGS=-Wl,--export-dynamic
endif
ifeq ($(FORTRAN_COMPILER),IFORT11)
F90=ifort
endif
ifeq ($(FORTRAN_COMPILER),IFORT12)
F90=ifort
endif
ifeq ($(FORTRAN_COMPILER),)
FORTRAN_COMPILER=GFORTRAN
endif
ifeq ($(COMPILATION_MODE),)
COMPILATION_MODE=production
endif
ifeq ($(FABM),true)
ifeq ($(FABMDIR),)
FABMDIR=../fabm-git
endif
DEFINES+=-DFABM
ifeq ($(FABM_OLD_BUILD),true)
ifeq ($(COMPILATION_MODE),production)
FABMLIB=fabm_prod
WITH_CHECKS=false
endif
ifeq ($(COMPILATION_MODE),debug)
FABMLIB=fabm_debug
WITH_CHECKS=true
endif
FINCLUDES+=-I$(FABMDIR)/include -I$(FABMDIR)/src/drivers/glm -I$(FABMDIR)/modules/glm/$(FORTRAN_COMPILER)
FABMLIBS=-L$(FABMDIR)/lib/glm/$(FORTRAN_COMPILER) -l$(FABMLIB)
else
ifeq ($(COMPILATION_MODE),production)
FABMLIB=fabm
WITH_CHECKS=false
endif
ifeq ($(COMPILATION_MODE),debug)
FABMLIB=fabm_debug
WITH_CHECKS=true
endif
FINCLUDES+=-I$(FABMDIR)/include -I$(FABMDIR)/src/drivers/glm -I$(FABMDIR)/build/modules
FABMLIBS=-L$(FABMDIR)/build -l$(FABMLIB)
endif
ifeq ($(USE_DL),true)
FABMTARGETS=libglm_wq_fabm.so
endif
endif
ifeq ($(AED2),true)
DEFINES+=-DAED2
ifeq ($(AED2DIR),)
AED2DIR=../libaed2
endif
FINCLUDES+=-I$(AED2DIR)/include -I$(AED2DIR)/mod
AED2LIBS=-L$(AED2DIR)/lib -laed2
ifeq ($(USE_DL),true)
AED2TARGETS=libglm_wq_aed2.so
endif
endif
ifneq ($(USE_DL),true)
LIBS+=$(AED2LIBS) $(FABMLIBS)
endif
# Select specific compiler bits
ifeq ($(F90),ifort)
FINCLUDES+=-I/opt/intel/include
DEBUG_FFLAGS=-g -traceback
OPT_FFLAGS=-O3
FFLAGS=-warn all -module ${moddir} -i-static -mp1 -stand f03 $(DEFINES) $(FINCLUDES)
ifeq ($(WITH_CHECKS),true)
FFLAGS+=-check
endif
FFLAGS+=-real-size 64
LIBS+=-L/opt/intel/lib
LIBS+=-lifcore -lsvml
LIBS+=-limf -lintlc
else
F90=gfortran
FINCLUDES+=-I/usr/include
DEBUG_FFLAGS=-g -fbacktrace
OPT_FFLAGS=-O3
FFLAGS=-Wall -J ${moddir} -Wno-c-binding-type -ffree-line-length-none -std=f2008 $(DEFINES) $(FINCLUDES) -fall-intrinsics
ifeq ($(WITH_CHECKS),true)
FFLAGS+=-fcheck=all
endif
FFLAGS+=-fdefault-real-8 -fdefault-double-8
ifeq ($(OSTYPE),Darwin)
LIBS+=-L/usr/local/gfortran/lib
endif
LIBS+=-lgfortran
endif
ifeq ($(DEBUG),true)
DEBUG_CFLAGS=-g -fbounds-check
OPT_CFLAGS=
OPT_FFLAGS=
else
DEBUG_FFLAGS=
DEBUG_CFLAGS=
# OPT_CFLAGS=-O4 -Ofast -frounding-math
OPT_CFLAGS=-O3
# OPT_CFLAGS=
# OPT_FFLAGS=
endif
LIBS+=-lnetcdf
# If variable NETCDFLIB is not empty, use it to
# set path to the library
ifneq ($(NETCDFLIB),)
LIBS+=-L$(NETCDFLIB)
endif
ifeq ($(PLOTDIR),)
PLOTDIR=../../libplot
endif
ifeq ($(WITH_PLOTS),true)
LIBS+=-L$(PLOTDIR)/lib -lplot -lgd -lpng -ljpeg -lm
ifeq ($(WITH_XPLOTS),true)
ifeq ($(OSTYPE),Darwin)
LIBS+=-framework Cocoa
else
LIBS+=-lX11
endif
endif
endif
#LIBS+=-lefence
CFLAGS=-Wall -I$(UTILDIR) -I$(PLOTDIR) $(CINCLUDES) $(DEFINES) $(DEBUG_CFLAGS) $(OPT_CFLAGS)
FFLAGS+=$(DEBUG_FFLAGS) $(OPT_FFLAGS)
OBJS=${objdir}/glm_globals.o \
${objdir}/glm_util.o \
${objdir}/glm_csv.o \
${objdir}/glm_mobl.o \
${objdir}/glm_mixu.o \
${objdir}/glm_wqual.o \
${objdir}/glm_layers.o \
${objdir}/glm_surface.o \
${objdir}/glm_input.o \
${objdir}/glm_plot.o \
${objdir}/glm_output.o \
${objdir}/glm_ncdf.o \
${objdir}/glm_lnum.o \
${objdir}/glm_init.o \
${objdir}/glm_flow.o \
${objdir}/glm_mixer.o \
${objdir}/glm_deep.o \
${objdir}/glm_bubbler.o \
${objdir}/glm_stress.o \
${objdir}/glm_bird.o \
${objdir}/glm_model.o \
${objdir}/glm_types.o \
${objdir}/glm_const.o \
${objdir}/glm_main.o
ifeq ($(USE_DL),true)
LIBS+=-ldl
CFLAGS+=-DUSE_DL_LOADER=1
FFLAGS+=-DUSE_DL_LOADER=1
TARGETS+=$(AED2TARGETS) $(FABMTARGETS)
else
OBJS+=${objdir}/glm_zones.o
ifeq ($(AED2),true)
OBJS+=${objdir}/glm_aed2.o
endif
ifeq ($(FABM),true)
OBJS+=${objdir}/glm_fabm.o ${objdir}/ode_solvers.o
endif
endif
all: $(TARGETS)
lib:
@mkdir lib
${objdir}:
@mkdir ${objdir}
${moddir}:
@mkdir ${moddir}
glm: ${objdir} ${moddir} $(OBJS) $(GLM_DEPS)
$(CC) -o glm $(EXTRALINKFLAGS) $(OBJS) $(LIBS)
clean: ${objdir} ${moddir}
@touch ${objdir}/1.o ${moddir}/1.mod 1.t 1__genmod.f90 glm 1.so glm_test_bird
@/bin/rm ${moddir}/*.mod ${objdir}/*.o *.t *__genmod.f90 *.so glm_test_bird
@echo Made clean
distclean: clean
@/bin/rm -rf ${objdir} ${moddir} glm
#${objdir}/%.o: ${srcdir}%.F90 ${incdir}/glm.h ${moddir} ${objdir}
# $(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/%.o: ${srcdir}/%.c ${incdir}/glm.h
$(CC) -fPIC $(CFLAGS) $(EXTRA_FLAGS) -D_C_VERSION_ -c $< -o $@
%.so:
$(LD) -shared $(LDFLAGS) \
-o $@ $^ -L/opt/intel/lib/intel64/ $(LIBS)
# -E -Bdynamic -undefined suppress -o $@ $^ -L/opt/intel/lib/intel64/ $(LIBS)
# Build rules
libglm_wq_aed2.so: glm_aed2.o glm_plugin.o
$(LD) -shared $(LDFLAGS) \
-o $@ $^ -L/opt/intel/lib/intel64/ $(LIBS) $(AED2LIBS)
libglm_wq_fabm.so: glm_fabm.o ode_solvers.o glm_plugin.o
$(LD) -shared $(LDFLAGS) \
-o $@ $^ -L/opt/intel/lib/intel64/ $(LIBS) $(FABMLIBS)
# special needs dependancies
${objdir}/glm_aed2.o: ${srcdir}/glm_aed2.F90 ${objdir}/glm_types.o
$(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/glm_zones.o: ${srcdir}/glm_zones.F90 ${objdir}/glm_types.o
$(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/glm_fabm.o: ${srcdir}/glm_fabm.F90 ${objdir}/glm_types.o ${objdir}/ode_solvers.o
$(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/glm_types.o: ${srcdir}/glm_types.F90 ${incdir}/glm.h
$(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/ode_solvers.o: ${srcdir}/ode_solvers.F90
$(F90) -fPIC $(FFLAGS) $(EXTRA_FFLAGS) -D_FORTRAN_SOURCE_ -c $< -o $@
${objdir}/glm_globals.o: ${srcdir}/glm_globals.c ${incdir}/glm_globals.h ${incdir}/glm.h
${objdir}/glm_bubbler.o: ${srcdir}/glm_bubbler.c ${incdir}/glm_globals.h ${incdir}/glm.h
${objdir}/glm_plugin.o: ${srcdir}/glm_plugin.c ${incdir}/glm_plugin.h ${incdir}/glm.h