~reducedmodelling/fluidity/ROM_RES_DEIM

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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#    Copyright (C) 2006 Imperial College London and others.
#    
#    Please see the AUTHORS file in the main source directory for a full list
#    of copyright holders.
#
#    Prof. C Pain
#    Applied Modelling and Computation Group
#    Department of Earth Science and Engineering
#    Imperial College London
#
#    amcgsoftware@imperial.ac.uk
#    
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation,
#    version 2.1 of the License.
#
#    This library 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
#    Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with this library; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
#    USA
SHELL = @SHELL@

PACKAGE_NAME = @PACKAGE_NAME@

# Ignore package version from autoconf. Instead, for packages
# FLUIDITY_VERSION is passed into ./configure and used here. If it is not
# set we obtain version information from bzr. Again, this is not done in
# configure to ensure the info is up-to-date after a "bzr up" without reconfiguring
ifeq ("@FLUIDITY_VERSION@","")
PACKAGE_VERSION = `bzr version-info --custom --template='{branch_nick}.{revno}'`
else
PACKAGE_VERSION = "@FLUIDITY_VERSION@"
endif

FLUIDITY = $(PACKAGE_NAME)

PROGRAM	 = ./bin/$(FLUIDITY)
FLDECOMP = ./bin/fldecomp

LIB_FLUIDITY = ./lib/lib$(FLUIDITY).a
SLIB_FLUIDITY = lib$(FLUIDITY).so

# Follow: www.gnu.org/prep/standards/html_node/Directory-Variables.html
PACKAGE_NAME = @PACKAGE_NAME@
prefix  = @prefix@
exec_prefix  = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
datadir = @datadir@
docdir = @docdir@/
htmldir = @htmldir@/
pdfdir = @pdfdir@/

FC      = @FC@
FCFLAGS = @FCFLAGS@

MPIF90  = @MPIF90@
MPICC   = @MPICC@
MPICXX  = @MPICXX@

CC	= @CC@
CFLAGS	= @CPPFLAGS@ @CFLAGS@

CXX	= @CXX@
CXXFLAGS= @CPPFLAGS@ @CXXFLAGS@ -I./include

LINKER  = @LINKER@ @LDFLAGS@

FLLINKER = @FLLINKER@ @LDFLAGS@ $(FCFLAGS)

LIBS    = -L./lib -l$(FLUIDITY) @BLAS_LIBS@ @LIB_FEMDEM@ ./lib/libadaptivity.a \
           ./lib/libvtkfortran.a ./lib/libspatialindex.a ./lib/libspud.a ./lib/libjudy.a \
           @LIBS@

OBJS = $(shell find . -mindepth 2 -maxdepth 2 -name '*.c' -o -name '*.cpp' -o -name '*.[fF]' -o -name '*.F90' | grep -v ^./lib | xargs)
MAKE = @MAKE@ -s

AR = @AR@

ARFLAGS	= -cr

EVAL = tools/silenteval.sh

ifeq (@MBA2D@,yes)
LIBMBA2D = lib/libmba2d.a
endif
ifeq (@MBA3D@,yes)
LIBMBA3D = lib/libmba3d.a
endif
ifeq (@ALGENCAN@,yes)
LIBALGENCAN = lib/libalgencan.a
endif

# Thread count for make test.
THREADS=1

EXCLUDE_TAGS =
ifneq (@ZOLTAN@,yes)
	EXCLUDE_TAGS := $(EXCLUDE_TAGS) -e zoltan
else
	EXCLUDE_TAGS := $(EXCLUDE_TAGS) -e nozoltan
endif
ifneq (@HAVE_ADJOINT@,yes)
	EXCLUDE_TAGS := $(EXCLUDE_TAGS) -e adjoint
endif
ifneq (@ALGENCAN@,yes)
	EXCLUDE_TAGS := $(EXCLUDE_TAGS) -e algencan
endif
ifneq (@MBA2D@,yes)
	EXCLUDE_TAGS := $(EXCLUDE_TAGS) -e 2dadapt
endif

.SUFFIXES: .f90 .F90 .c .cpp .o .a

.cpp.o:
	@echo "        CXX $<"
	$(CXX) $(CXXFLAGS) -c $<

default: bin/$(FLUIDITY)

sub_system: $(LIBMBA2D) $(LIBMBA3D) $(LIBALGENCAN)  @LIB_FEMDEM@ \
	lib/libadaptivity.a lib/libvtkfortran.a lib/libspatialindex.a \
	lib/libspud.a lib/libjudy.a include/version.h

lib/libjudy.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd libjudy; echo '    MAKE libjudy'; $(MAKE) > make.log ; $(MAKE) install >> make.log ; cd ..

lib/libmba2d.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd libmba2d; echo '    MAKE libmba2d'; $(MAKE) ; cd ..

lib/libmba3d.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd libmba3d; echo '    MAKE libmba3d'; $(MAKE) ; cd ..

lib/libalgencan.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd libalgencan; echo '    MAKE libalgencan'; $(MAKE) ; cd ..

lib/libadaptivity.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@BUILD_LIBADAPT@

lib/libvtkfortran.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd libvtkfortran; echo '    MAKE libvtkfortran'; $(MAKE) 2>make.log 2>&1 ; cp libvtkfortran.a ../lib/; cp *.mod ../include/; cd ..

lib/libspatialindex.a:
	@echo '    MKDIR lib'; mkdir -p lib
	@cd @SPATIALINDEXDIR@ ; echo '    MAKE libspatialindex'; $(MAKE); $(MAKE) install >> make.log 2>&1

lib/libspud.a:
	@echo '    MKDIR lib'; mkdir -p lib
ifeq (@SPUD_ONLY@,yes)
	@cd libspud;  echo '    MAKE libspud'; $(MAKE) ; $(MAKE) install-libspud
else
	@cd libspud;  echo '    MAKE libspud'; $(MAKE) ; $(MAKE) install-libspud; cd python; python setup.py build; cd ../..; cp libspud/python/build/lib*/libspud.so python/
endif

libfemtools: sub_system
	@echo '    MKDIR lib'; mkdir -p lib
	@echo '    MAKE debug'
	@cd debug; $(MAKE)
	@echo '    MAKE libwm'
	@cd libwm; $(MAKE)
	@cd femtools; echo '    MAKE libfemtools'; $(MAKE) libfemtools ; cp libfemtools.a ../lib/; cd ..
ifeq (@FEMDEM@,yes)
@LIB_FEMDEM@:
	@echo '    MAKE 3dfemdem library'
	@cd @FLFEMDEM_PATH@;$(MAKE)
endif

include/libspud.h: lib/libspud.a

main.o: include/version.h include/libspud.h

include/version.h:
	@echo "DEFINE __FLUIDITY_VERSION__"
	@grep "$(PACKAGE_VERSION)" include/version.h >/dev/null 2>&1 || \
	printf "#ifndef _FLUIDITY_VERSION_H\n\
	#define _FLUIDITY_VERSION_H\n\
	#define __FLUIDITY_VERSION__ \"$(PACKAGE_VERSION)\"\n\
	#endif /* _FLUIDITY_VERSION_H */\n" > include/version.h

.PHONY: include/version.h

bin/$(FLUIDITY): main.o lib/lib$(FLUIDITY).a
	@echo "BUILD fluidity"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD $(PROGRAM)"
	@$(EVAL) $(LINKER) -o $(PROGRAM) main.o $(LIBS)

sw: bin/shallow_water
be: bin/burgers_equation
hh: bin/hybridized_helmholtz_solver

bin/shallow_water: fluidity_library bin/hybridized_helmholtz_solver main/Shallow_Water.F90
	@cd main; $(MAKE) Shallow_Water.o
	@echo "BUILD shallow_water"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD shallow_water"
	@$(EVAL) $(FLLINKER) -o bin/hybridized_helmholtz_solver main/Hybridized_Helmholtz_Solver.o $(LIBS)
	@$(EVAL) $(FLLINKER) -o bin/shallow_water main/Shallow_Water.o $(LIBS)

bin/hybridized_helmholtz_solver: fluidity_library main/Hybridized_Helmholtz_Solver.F90
	@cd main; $(MAKE) Hybridized_Helmholtz_Solver.o
	@echo "BUILD hybridized_helmholtz_solver"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD hybridized_helmholtz_solver"
	@$(EVAL) $(FLLINKER) -o bin/hybridized_helmholtz_solver main/Hybridized_Helmholtz_Solver.o $(LIBS)

bin/burgers_equation: fluidity_library main/Burgers_Equation.F90
	@cd main; $(MAKE) Burgers_Equation.o
	@echo "BUILD burgers_equation"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD burgers_equation"
	@$(EVAL) $(FC) -o bin/burgers_equation main/Burgers_Equation.o $(FCFLAGS) $(LIBS)

ifeq (@ENABLE_PSMILE@,yes)
LIBPSMILE=@FLPSMILE_PATH@/lib/libpsmile_oa4.MPI1.a @FLPSMILE_PATH@/lib/libcommon_oa4.a @FLPSMILE_PATH@/lib/libmpp_io.a -lxml2
bin/test_coupler: fluidity_library main/test_coupler.F90
	@cd main; $(MAKE) test_coupler.o
	@echo "BUILD test_coupler"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD test_coupler"
	@$(EVAL) $(FC) -o bin/test_coupler main/test_coupler.o $(LIBPSMILE) $(FCFLAGS) $(LIBS)
else
bin/test_coupler:
	@echo "     Unable to build bin/test_coupler without psmile libraries"
	@echo "     Please reconfigure --with-psmile=/path/to/oasis4"
	exit 1
endif

bin/form_pod_basis: fluidity_library reduced_modelling/Form_Pod_Basis_Main.F90
	@cd reduced_modelling; $(MAKE) Form_Pod_Basis_Main.o
	@echo "BUILD Form_Pod_Basis"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD Form_Pod_Basis"
	@$(EVAL) $(LINKER) -o bin/form_pod_basis reduced_modelling/Form_Pod_Basis_Main.o $(LIBS)

bin/initial_ensemble: fluidity_library enkf/perturb_initial.F90
	@cd enkf; $(MAKE) perturb_initial.o
	@echo "BUILD Initial_Ensemble"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD Initial_Ensemble"
	@$(EVAL) $(LINKER) -o bin/initial_ensemble enkf/perturb_initial.o $(LIBS)

bin/enkf: fluidity_library enkf/EnKF.F90
	@cd enkf; $(MAKE) EnKF.o
	@echo "BUILD EnKF"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD EnKF"
	@$(EVAL) $(LINKER) -o bin/enkf enkf/EnKF.o $(LIBS)

bin/adjoint_rom: fluidity_library adjoint_reduced_modelling/Adjoint_main.F90
	@cd adjoint_reduced_modelling; $(MAKE) Adjoint_main.o
	@echo "BUILD Adjoint_main"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@echo "    LD adjoint_rom"
	@$(EVAL) $(LINKER) -o bin/adjoint_rom adjoint_reduced_modelling/Adjoint_main.o $(LIBS)

static: fluidity_library

shared: lib/shared/$(SLIB_FLUIDITY).1

lib/shared/$(SLIB_FLUIDITY).1: fluidity_library 
	@echo "BUILD shared libfluidity"
	@rm -rf tmp
	@mkdir -p tmp lib/shared
	@cp $(LIB_FLUIDITY) tmp
	@cd tmp; ar x lib$(FLUIDITY).a; rm lib$(FLUIDITY).a; cd ..
	@echo "    LD lib$(FLUIDITY).so"
	@$(EVAL) $(LINKER) -shared -Wl,-soname,$(SLIB_FLUIDITY).1 -o lib/shared/$(SLIB_FLUIDITY).1 tmp/* -L./lib -lvtkfortran 
	@rm -rf tmp
	@cd lib/shared; ln -sf $(SLIB_FLUIDITY).1 $(SLIB_FLUIDITY); cd ../..

fltools: fluidity_library
	@$(MAKE) fldecomp
	@echo "BUILD fluidity tools"
	@cd tools; $(MAKE)
	@echo "    MAKE climatology"
	@cd climatology; $(MAKE)

.PHONY:manual

manual:
	@cd manual; $(MAKE)

python_build:
ifeq (@HAVE_PYTHON@,yes)
	@echo "    MAKE python"
	@cd python; python setup.py build > build.log 2>&1
	@cd python/fluidity; find ../build/lib* -name '*.so' -exec ln -sf {} . \;
endif

python_clean:
	@echo "    CLEAN python"
	@cd python; rm -rf build
	@cd python/fluidity; find . -type l -name '*.so' -exec rm -f {} \;

.PHONY: scripts

scripts:
	@echo "INSTALL local scripts"
	@cd tools ; $(MAKE) scripts

fluidity_library: lib/lib$(FLUIDITY).a
lib/lib$(FLUIDITY).a: $(OBJS) python_build sub_system scripts
	@echo "BUILD libfluidity"
	@echo "    MKDIR lib"
	@mkdir -p lib
	@echo "    MAKE debug"
	@cd debug; 	$(MAKE)
	@echo '    MAKE libwm'
	@cd libwm; $(MAKE)
	@echo "    MAKE femtools"
	@cd femtools;	$(MAKE)
	@echo "    MAKE bathymetry"
	@cd bathymetry; $(MAKE)
	@echo "    MAKE ocean_forcing"
	@cd ocean_forcing; $(MAKE)
ifeq (@HYPERLIGHT@,yes)
	@echo "    MAKE hyperlight"
	@cd hyperlight; $(MAKE)
endif
	@echo "    MAKE sediments"
	@cd sediments; $(MAKE)
	@echo "    MAKE parameterisation"
	@cd parameterisation; $(MAKE)
	@echo "    MAKE forward_interfaces"
	@cd forward_interfaces;	$(MAKE)
	@echo "    MAKE horizontal_adaptivity"
	@cd horizontal_adaptivity;   	$(MAKE)
	@echo "    MAKE preprocessor"
	@cd preprocessor; $(MAKE)
	@echo "    MAKE error_measures"
	@cd error_measures;   	$(MAKE)
	@echo "    MAKE assemble"
	@cd assemble;   	$(MAKE)
	@echo "    MAKE diagnostics"
	@cd diagnostics;   	$(MAKE)
	@echo "    MAKE reduced_modelling"
	@cd reduced_modelling;   	$(MAKE)
	@echo "    MAKE enkf"
	@cd enkf;          $(MAKE)
	@echo "    MAKE adjoint_reduced_modelling"
	@cd adjoint_reduced_modelling;  $(MAKE)
	@echo "    MAKE adjoint"
	@cd adjoint; $(MAKE)
	@echo "    MAKE main"
	@cd main; $(MAKE)
	@echo "    MAKE options_check"
	@./tools/make_check_options.py
	@cd preprocessor; $(MAKE) check_options.o
	@echo "    MAKE register_diagnostics"
	@./tools/make_register_diagnostics.py
	@cd preprocessor; $(MAKE) register_diagnostics.o
	@echo "    BUILDING fluidity_library"
	@$(AR) $(ARFLAGS) lib/libfluidity.a \
debug/*.o \
libwm/*.o \
femtools/*.o \
bathymetry/*.o \
ocean_forcing/*.o \
sediments/*.o \
parameterisation/*.o \
forward_interfaces/*.o \
horizontal_adaptivity/*.o \
preprocessor/*.o \
error_measures/*.o \
assemble/*.o \
diagnostics/*.o \
reduced_modelling/*.o \
enkf/*.o \
adjoint_reduced_modelling/*.o \
adjoint/*.o \
main/*.o
ifeq (@HYPERLIGHT@,yes)
	@$(AR) $(ARFLAGS) lib/libfluidity.a hyperlight/*.o
endif



fldecomp: fluidity_library 
	@echo "BUILD fldecomp"
	@echo "    MKDIR bin"
	@mkdir -p bin
	@cd fldecomp; $(MAKE)

all:
	$(MAKE) default
	$(MAKE) fltools

clean-light:
	@echo "    CLEAN debug"
	@cd debug; $(MAKE) clean
	@echo "    CLEAN libwm"
	@cd libwm; $(MAKE) clean
	@echo "    CLEAN femtools"
	@cd femtools; $(MAKE) clean
	@echo "    CLEAN femtools/tests"
	@cd femtools/tests; $(MAKE) clean
	@echo "    CLEAN forward_interfaces"
	@cd forward_interfaces; $(MAKE) clean
	@echo "    CLEAN parameterisation"
	@cd parameterisation; $(MAKE) clean
	@echo "    CLEAN sediments"
	@cd sediments; $(MAKE) clean
	@echo "    CLEAN parameterisation/tests"
	@cd parameterisation/tests; $(MAKE) clean
	@echo "    CLEAN assemble"
	@cd assemble;   $(MAKE) clean
	@echo "    CLEAN assemble/tests"
	@cd assemble/tests;   $(MAKE) clean
	@echo "    CLEAN diagnostics"
	@cd diagnostics;   $(MAKE) clean
	@echo "    CLEAN preprocessor"
	@cd preprocessor; $(MAKE) clean
	@echo "    CLEAN error_measures/tests"
	@cd error_measures/tests;   $(MAKE) clean
	@echo "    CLEAN error_measures"
	@cd error_measures;   $(MAKE) clean
	@echo "    CLEAN horizontal_adaptivity"
	@cd horizontal_adaptivity;   $(MAKE) clean
	@echo "    CLEAN horizontal_adaptivity/tests"
	@cd horizontal_adaptivity/tests;   $(MAKE) clean
	@echo "    CLEAN tools"
	@cd tools;    $(MAKE) clean
	@echo "    CLEAN adjoint"
	@cd adjoint;    $(MAKE) clean
	@cd adjoint/tests;    $(MAKE) clean
	@echo "    CLEAN bathymetry"
	@cd bathymetry;  $(MAKE) clean
	@echo "    CLEAN ocean_forcing"
	@cd ocean_forcing;  $(MAKE) clean
	@cd ocean_forcing/tests;   $(MAKE) clean
	@echo "    CLEAN fldecomp"
	@cd fldecomp;	$(MAKE) clean
ifeq (@HYPERLIGHT@,yes)
	@echo "    CLEAN hyperlight"
	@cd hyperlight; $(MAKE) clean
endif
	@cd climatology;  $(MAKE) clean
	@echo "    CLEAN climatology"
	@echo "    CLEAN reduced_modelling"
	@cd reduced_modelling; $(MAKE) clean
	@echo "    CLEAN enkf"
	@cd enkf; $(MAKE) clean
	@echo "    CLEAN adjoint_reduced_modelling"
	@cd adjoint_reduced_modelling; $(MAKE) clean
	@echo "    CLEAN adjoint"
	@cd adjoint; $(MAKE) clean
	@echo "    CLEAN main"
	@cd main; $(MAKE) clean
	@rm -fr bin/* lib

clean: clean-light clean-test python_clean clean-debian
	@echo "    CLEAN libvtkfortran"
	@cd libvtkfortran; $(MAKE) clean
	@echo "    CLEAN libjudy"
	@cd libjudy; $(MAKE) clean >> make.log 2>&1
	@echo "    CLEAN libspud"
	@cd libspud; $(MAKE) clean
	@echo "    CLEAN libspatialindex"
	@cd @SPATIALINDEXDIR@; $(MAKE) clean >> make.log
	@echo "    CLEAN libmba2d"
	@cd libmba2d; $(MAKE) clean
	@echo "    CLEAN libmba3d"
	@cd libmba3d; $(MAKE) clean
	@echo "    CLEAN libalgencan"
	@cd libalgencan; $(MAKE) clean
	@echo "    CLEAN libwm"
	@cd libwm; $(MAKE) clean
	@echo "    CLEAN manual"
	@cd manual; $(MAKE) clean
	@CLEAN_LIBADAPT@
	@rm -fr include/*.mod *.cache core *.o config.status
	@find ./ \( -name work.pc \) -exec rm {} \;
	@find ./ \( -name work.pcl \) -exec rm {} \;

clean-debian:
	@echo "    CLEAN debian"
	@cd debian; rm -rf files tmp fluidity python-fluidity *.substvars *.debhelper* 

clean-test:      
	@echo "    CLEAN tests"
	@cd tests; PYTHONPATH=../python ../tools/testharness.py --clean >/dev/null
	@cd tests/data; $(MAKE) clean

distclean: clean
	@echo "    DISTCLEAN"
	@cd spatialindex-1.5 ; make distclean > /dev/null ; rm -rf	\
	 make.log regressiontest/mvrtree/.deps				\
	 regressiontest/rtree/.deps regressiontest/tprtree/.deps >	\
	 /dev/null
	@cd libadaptivity ; make distclean > /dev/null
	@cd libjudy ; make distclean > /dev/null
	@cd libvtkfortran ; make distclean > /dev/null
	@cd libspud ; make distclean > /dev/null ; rm -rf		\
	 libspud.so.0 libtool diamond/build python/build > /dev/null
	@rm -fr `find ./ -name config.status` `find ./ -name		\
	 config.log` share include/Judy.h include/Wm4Command.h		\
	 include/Wm4FoundationLIB.h include/Wm4FoundationPCH.h		\
	 include/Wm4Intersector.h include/Wm4Intersector1.h		\
	 include/Wm4IntrBox3Box3.h include/Wm4IntrQuad2Quad2.h		\
	 include/Wm4IntrTetrahedron3Tetrahedron3.h			\
	 include/Wm4IntrTriangle2Triangle2.h				\
	 include/Wm4IntrUtility3.h include/Wm4LinComp.h			\
	 include/Wm4Math.h include/Wm4MathMCR.h include/Wm4Memory.h	\
	 include/Wm4Plane3.h include/Wm4Platforms.h			\
	 include/Wm4Quad2.h include/Wm4Segment3.h include/Wm4System.h	\
	 include/Wm4THashSet.h include/Wm4THashTable.h			\
	 include/Wm4TMinHeap.h include/Wm4TSmallUnorderedSet.h		\
	 include/Wm4TStringHashTable.h include/Wm4TTuple.h		\
	 include/Wm4Tetrahedron3.h include/Wm4Triangle2.h		\
	 include/Wm4Triangle3.h include/Wm4Vector2.h			\
	 include/Wm4Vector3.h include/confdefs.h include/config.h	\
	 include/spatialindex include/spud include/spud.h		\
	 include/spud_enums.h include/tinystr.h include/tinyxml.h	\
	 include/version.h include/vtk.h				\
	 preprocessor/check_options.F90 schemas/flml			\
	 preprocessor/register_diagnostics.F90 python/setup.py >	\
	 /dev/null
	@for i in `find ./*/ -name Makefile.in`; do rm -f `echo $$i | sed 's/.in$$//'`; done > /dev/null
	@find ./ \( -name make.log \) -exec rm -f {} \; > /dev/null
	@rm -f Makefile > /dev/null

test: fltools bin/$(FLUIDITY) bin/shallow_water serialtest bin/burgers_equation

serialtest: fltools bin/$(FLUIDITY) bin/shallow_water
	@cd tests; ../bin/testharness -l short -p serial $(EXCLUDE_TAGS) -n $(THREADS)

mediumtest: fltools bin/$(FLUIDITY) manual bin/burgers_equation bin/shallow_water spudtools
	@cd tests; ../bin/testharness -l medium $(EXCLUDE_TAGS) -n $(THREADS)

.PHONY: spudtools

spudtools:
	@cd libspud ; $(MAKE) install-spudtools
	@echo "    INSTALL spudtools"

setuputs: 
	@echo "SETUP tests"
	@echo "    RMDIR bin/tests"
	@rm -rf bin/tests
	@echo "    MKDIR bin/tests"
	@mkdir -p bin/tests
	@ln -sf ../../tests/data bin/tests/data

build_unittest: fluidity_library libfemtools setuputs
	@echo "    UNITTEST libspud"
	@cd libspud/src/tests; $(MAKE) test-binaries; find bin/* -maxdepth 1 -type f -exec ln -sf ../../libspud/src/tests/{} ../../../bin/tests \; 
	@echo "    UNITTEST error_measures"
	@cd error_measures/tests; $(MAKE) unittest
	@echo "    UNITTEST horizontal_adaptivity"
	@cd horizontal_adaptivity/tests; $(MAKE) unittest
	@echo "    UNITTEST femtools"
	@cd femtools/tests; $(MAKE) unittest
	@echo "    UNITTEST parameterisation"
	@cd parameterisation/tests; $(MAKE) unittest
	@echo "    UNITTEST assemble"
	@cd assemble/tests; $(MAKE) unittest
	@echo "    UNITTEST adjoint"
	@cd adjoint/tests; $(MAKE) unittest
	@echo "    UNITTEST ocean_forcing"
	@cd ocean_forcing/tests; $(MAKE) unittest


unittest: build_unittest
	@echo "RUN bin/tests"
	@bin/unittestharness bin/tests

bin/spud-preprocess:
	@echo "Installing spudtools"
	@$(MAKE) -C libspud install-spudtools

schema: bin/spud-preprocess
	@echo "Rebuilding schema fluidity_options.rng"
	@./bin/spud-preprocess schemas/fluidity_options.rnc

.PHONY: makefiles

makefiles: sub_system scripts
ifneq (@GFORTRAN_4_5_OR_NEWER@,yes)
	@echo "makefile dependency generation requires gfortran (>=4.5)"
	@false
endif
ifneq (@HAVE_ZOLTAN@,yes)
	@echo "makefile dependency generation requires zoltan"
	@false
endif
ifneq (@HAVE_ADJOINT@,yes)
	@echo "makefile dependency generation requires adjoint"
	@false
endif
	@echo "    Generating debug dependencies"
	@cd debug; 	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating libwm dependencies"
	@cd libwm; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating femtools dependencies"
	@cd femtools;	../bin/create_makefile --exclude \
	"Refcount_interface_templates.F90 Refcount_templates.F90" $(TESTOPTS)
	@echo "    Generating bathymetry dependencies"
	@cd bathymetry; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating ocean_forcing dependencies"
	@cd ocean_forcing; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating sediments dependencies"
	@cd sediments; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating parameterisation dependencies"
	@cd parameterisation; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating forward_interfaces dependencies"
	@cd forward_interfaces;	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating horizontal_adaptivity dependencies"
	@cd horizontal_adaptivity;   	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating preprocessor dependencies"
	@cd preprocessor; ../bin/create_makefile --exclude \
	"register_diagnostics.F90 check_options.F90" $(TESTOPTS)
	@echo "    Generating error_measures dependencies"
	@cd error_measures;   	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating assemble dependencies"
	@cd assemble;   	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating diagnostics dependencies"
	@cd diagnostics;   	../bin/create_makefile --exclude \
	"Diagnostic_Fields_Interfaces.F90 Diagnostic_Fields_New.F90" $(TESTOPTS)
	@cd diagnostics;   	$(MAKE) Diagnostic_Fields_Interfaces.o \
	Diagnostic_Fields_New.o 
	@echo "    Generating reduced_modelling dependencies"
	@cd reduced_modelling;   	../bin/create_makefile $(TESTOPTS)
	@echo "    Generating enkf dependencies"
	@cd enkf; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating adjoint dependencies"
	@cd adjoint; ../bin/create_makefile $(TESTOPTS)
	@echo "    Generating main dependencies"
	@cd main; ../bin/create_makefile --exclude test_coupler.F90 $(TESTOPTS)
	@echo "    Cleaning up the mess"
	$(MAKE) clean-light
	@echo "    Congratulations, make makefiles succeeded!"

install: default fltools bin/shallow_water bin/burgers_equation
	@mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(docdir)/fluidity
	find bin/ -maxdepth 1 -type f -exec cp '{}' $(DESTDIR)$(bindir) \;
	rm -f $(DESTDIR)$(bindir)/spud-* $(DESTDIR)$(bindir)/diamond $(DESTDIR)$(bindir)/silenteval $(DESTDIR)$(bindir)/runut
	[ -f manual/fluidity_manual.pdf ] && cp manual/fluidity_manual.pdf $(DESTDIR)$(docdir)/fluidity || true
	mkdir -p $(DESTDIR)$(datadir)/fluidity
	cp -r schemas/ $(DESTDIR)$(datadir)/fluidity/
	mkdir -p $(DESTDIR)$(datadir)/diamond/schemata
	cp schemas/flml $(DESTDIR)$(datadir)/diamond/schemata
	cd python ; python setup.py install --root=$(shell echo ${DESTDIR} | sed 's/^$$/\//') --prefix="$(prefix)" $$FLUIDITY_PYTHON_INSTALL_ARGS
	cp -r examples/ $(DESTDIR)$(docdir)/fluidity
	find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec sed -i "s/\.\.\/\.\.\/\.\.\/bin\///" '{}' \;
	find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec sed -i "s/\.\.\/\.\.\/bin\///" '{}' \;
	tar -czvf $(DESTDIR)$(docdir)/fluidity/examples.tar.gz $(DESTDIR)$(docdir)/fluidity/examples/
	rm -rf $(DESTDIR)$(docdir)/fluidity/examples/

install-diamond: 
	cd libspud; ./configure --prefix=$(DESTDIR)@prefix@; cd ../..
	cd libspud; $(MAKE) clean; cd ../..
	cd libspud; $(MAKE) install-diamond; cd ../..
	cd libspud; $(MAKE) install-dxdiff; cd ../..
	cd libspud; $(MAKE) install-spudtools; cd ../..
	cd libspud; ./configure --prefix=$(PWD); cd ../..

install-user-schemata:
	mkdir -p $(HOME)/.diamond/schemata/
	echo "Fluidity Markup Language" > $(HOME)/.diamond/schemata/flml
	echo "$(PWD)/schemas/fluidity_options.rng" >> $(HOME)/.diamond/schemata/flml