-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
1157 lines (1062 loc) · 44.1 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
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- Makefile -*-
#
# PURPOSE
# -------
# JAMS Makefile for Fortran, C, C++, and mixed projects
#
#
# DESCRIPTION
# -----------
# Compiling a program from source code is an elaborate process. The compiler has
# to find all source files, of course. It has to know all dependencies between
# the source files. For C programs, it has to find all the header (.h) files.
# For Fortran programs, it has to find the module (.mod) files, which are
# produced by the compiler itself, which means that the files have to be
# compiled in a certain order. Last but not least, the compiler and linker have
# to find external libraries and use appropriate compiler options.
#
# Different solutions exist for this problem, the two most prominent being GNU's
# configure and Kitware's CMake. One amost always gives non-standard directories
# on the command line, e.g.
# configure --with-netcdf=/path/to/netcdf
# cmake -DCMAKE_NETCDF_DIR:STRING=/path/to/netcd
# Therefore, one has to know all installation directories etc. for the current
# computer (system) or load the appropriate, matching modules, which is tedious
# if you work on several computers such as your local computer for development
# and one or two clusters or supercomputers for production. This can be
# externalised in CMake by giving a script with -C or -P once all information
# was gathered.
#
# This Makefile follows a similar idea that the information about the current
# computer (system) must only be gathered once and stored in a config file. The
# user can then easily compile the same code on different computer (systems)
# with different compilers in debug or release mode, by simply telling on the
# command line
# make system=mcinra compiler=gnu release=debug
# This uses the system specific files mcinra.alias to look for the default gnu
# compiler, which is version 6.1 in this case and then uses all variables set in
# the file mcinra.gnu61. The user has to provide these mcinra.alias and
# mcinra.gnu61 populated with the directories and specific compiler options for
# the GNU compiler suite 6.1 on the macOS system mcinra. The files can then be
# reused for every other project on the computer (system) mcinra.
#
# The project includes examples for different operating systems, i.e. Unix (e.g.
# pearcey), Linux (e.g. explor), macOS (e.g. mcinra), and Windows (e.g. uwin).
# The computer system mcinra provides examples for different compilers, i.e. the
# GNU compiler suite, the Intel compiler suite, the NAG Fortran compiler, and
# the PGI Fortran compiler.
#
# The project provides some standard configurations for the GNU compiler suite
# such as homebrew on macOS, ubuntu on Linux, and cygwin and ubuntu (uwin) on
# Windows.
#
# The README.md includes a section how to add a new compiler and how to setup
# the Makefile project on a new computer (system).
#
#
# CALLING SEQUENCE
# ----------------
# make [options] [VARIABLE=VARIABLE ...] [targets]
#
# Variables can be set on the command line [VAR=VAR] or in the section SWITCHES
# below.
#
# If $(PROGNAME) is given, an executable will be compiled.
# If $(LIBNAME) is given, a library will be created.
#
# Sources are in $(SRCPATH), which can be several directories separated by
# whitespace.
#
# File suffixes can be given in $(F90SUFFIXES), $(F77SUFFIXES),
# $(CSUFFIXES), $(CXXSUFFIXES), and $(LIBSUFFIXES)
# Defaults are:
# Fortran 90: .f90, .F90, .f95, .F95, .f03, .F03, .f08, .F08
# Fortran 77: .f, .F, .for, .FOR, .f77, .F77, .ftn, .FTN
# C: .c, .C, .cc, .CC
# C++: .cpp, .CPP, .cxx, .CXX, .cp, .CP, .c++, .C++
# Library: .a .so .dylib
# Note that .F and .FOR are Fortran 77 by default.
#
#
# TARGETS
# -------
# all (default), check (=test), dependencies (=depend), html, pdf, latex,
# doxygen, info clean, cleanclean (=distclean),
# cleancheck (=cleantest=checkclean=testclean),
# cleancleancheck (=cleancleantest=checkcleanclean=testcleanclean),
#
#
# OPTIONS
# -------
# All make options such as -f makefile. See 'man make'.
#
#
# VARIABLES
# ---------
# All variables defined in this makefile. This makefile has lots of conditional
# statements depending on variables. If the variable works as a switch then the
# condition checks for variable = true, i.e. ifeq ($(variable),true), otherwise
# the variable can have any other value. See individual variables in section
# SWITCHES below or type 'make info'.
#
# Variables can be empty for disabling a certain behaviour, e.g. if you do not
# want to use LAPACK, set: lapack=no or lapack=
#
# For main variables see 'make info'.
#
#
# DEPENDENCIES
# ------------
# This makefile uses the following files:
# $(MAKEDPATH)/make.d.py, $(CONFIGPATH)/$(system).$(compiler),
# $(CONFIGPATH)/$(system).alias
# The default $(MAKEDPATH) and $(CONFIGPATH) is make.config.
# The makefile can use doxygen for html and pdf automatic documentation. It is
# then using $(DOXCONFIG).
#
# If this is not available, it uses the perl script f2html for html
# documentation:
# $(TOOLPATH)/f2html, $(TOOLPATH)/f2html.fgenrc
#
#
# RESTRICTIONS
# ------------
# 1. The makefile provides dependency generation. This process must be done in
# serial. Parallel make (-j) does hence not work from scratch. One can split
# dependency generation and compilation by first calling make with a dummy
# target, which creates all dependencies, and then second calling parallel
# make with the -j switch, i.e.
# make system=mcinra compiler=intel release=release dummy
# make system=mcinra compiler=intel release=release -j 8
#
# 2. The static switch is maintained like a red-headed stepchild. Libraries
# might be not ordered correctly if static linking and
# --begin-group/--end-group is not supported by the linker.
#
# 3. C- and C++-file dependencies are generated with:
# $(CC) -E $(DEFINES) -MM
#
#
# EXAMPLES
# --------
# make system=eve release=true
# make system=mcinra compiler=gcc release=debug lapack=true mpi=openmpi
#
#
# NOTES
# -----
# Further information is given in the README.md, for example on the repository
# of the makefile, further reading, how to add a new compiler on a given system,
# or how to add a new system.
#
#
# LICENSE
# -------
# This file is part of the JAMS Makefile system, distributed under the MIT License.
#
# Copyright (c) 2011-2022 Matthias Cuntz - mc (at) macu (dot) de
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
SHELL = /bin/bash
# ----------------------------------------------------------
# START OF USER SECTION
# ----------------------------------------------------------
# . is current directory, .. is parent directory
# where are the source files; whitespace separated list
SRCPATH := ./test/test_standard
# where to place the executable
PROGPATH := .
# where are the $(system).$(compiler) config files
CONFIGPATH := make.config
# where is the make.d.py script
MAKEDPATH := $(CONFIGPATH)
# path for $(CHECKPATH)/test* and $(CHECKPATH)/check* directories if target is check
CHECKPATH := ../test
# tools such as f2html
TOOLPATH := tools
# the doxygen config file
DOXCONFIG := ./doxygen.config
PROGNAME := prog # Name of executable
LIBNAME := # Name of library, e.g. libminpack.a
# Program should be linked using the compiler of the main file (-> fortran:
# program prog, C: void main()).
# Default: $(F90) if source files include fortran files, otherwise $(CC).
# Possible values: fortran Fortran FORTRAN for For FOR, c C, c++ C++ cxx CXX
LINKER :=
# Options
# Systems: computer (system) name given during installation
# such as mcair for Matthias' MacBook Air.
# Look in $(MAKEDPATH) or type 'make info' for available computer systems.
system := mcinra
# Compiler: e.g. gnu or gnuX where X stands for version number, e.g. gnu102;
# look at $(MAKEDPATH)/$(system).alias for shortcuts
# such as gnu for gnuX or type 'make info'
compiler := gnu
# Releases: debug, release, true (the last two are equal)
release := debug
# netCDF versions (Network Common Data Form): netcdf3, netcdf4, [anything else]
netcdf := netcdf4
# LAPACK (Linear Algebra Pack): true, mkl, [anything else]
lapack := true
# MKL (Intel's Math Kernel Library): mkl, mkl95, [anything else]
mkl :=
# Proj4 (Cartographic Projections Library): true, [anything else]
proj :=
# IMSL (IMSL Numerical Libraries): vendor, imsl, [anything else]
imsl :=
# OpenMP parallelization: true, [anything else]
openmp :=
# MPI parallelization - experimental: openmpi, mpich, [anything else]
mpi :=
# Linking: static, shared, dynamic (the last two are equal)
static := shared
# The Makefile sets the following variables depending on the above options:
# FC, FCFLAGS, F90, F90FLAGS, CC, CFLAGS, CPP, DEFINES, INCLUDES, LD, LDFLAGS,
# LIBS.
# Flags, defines, etc. will be set incremental. They will be initialised
# with the following EXTRA_* variables, which are not in the config files.
# This allows for example to set an extra compiler option or define a
# preprocessor variable such as: EXTRA_DEFINES := -DNOGUI -DDPREC
# Fortran 77 compiler flags, such as -ffixed-form
EXTRA_FCFLAGS :=
# Fortran 90 compiler flags, such as -ffree-form
EXTRA_F90FLAGS :=
# Preprocessor flags, such as -DgFortran
EXTRA_DEFINES :=
# Include directives, such as -I/usr/local/include
EXTRA_INCLUDES :=
# Linker flags, such as -ipo (interprocedural optimization)
EXTRA_LDFLAGS :=
# External library flags, -L/usr/local/lib -lcurl
EXTRA_LIBS :=
# C-compiler flags, such as -std=c99
EXTRA_CFLAGS :=
# C++-compiler flags, such as -fstrict-enums
EXTRA_CXXFLAGS :=
# Base variable for extra library, such as HOMEBREWDIR
# This will search for the variables
# HOMEBREWDIR, HOMEBREWINC, HOMEBREWFLAG, HOMEBREWDEF,
# which content will be added to the compilation flags, linker flags.
# If *DIR is found but not *INC or *LIB, the standard directories
# include and lib will be used in directory *DIR
EXTRA_DIRS :=
# In Fortran 2003, arrays can be (re-)allocated as a result of a function.
# The Intel compiler adds this feature with the compiler option: -assume realloc-lhs
# If you encouter the following error with the Intel compiler (compiler bug):
# 0_10708
# : catastrophic error: **Internal compiler error: internal abort**
# Please report this error along with the circumstances in which it occurred
# in a Software Problem Report.
# Note: File and line given may not be explicit cause of this error.
# This comes often from this feature.
# Add the affected file to the list INTEL_EXCLUDE to compile it without the delete
# realloc-lhs flag.
# If this does not work, try to reduce the optimisation in the make.config files
# (e.g. -O1)
INTEL_EXCLUDE :=
# The Makefile compiles all files found in the source directories.
# If you want excludes files from compilation, set EXCLUDE_FILES, e.g.
# make EXCLUDE_FILES="*mpi*.f90"
# Exclude specific files from compilation
EXCLUDE_FILES :=
# Fortran 90 suffixes: .f90 .F90 .f95 .F95 .f03 .F03 .f08 .F08
F90SUFFIXES := .f90 .F90 .f95 .F95 .f03 .F03 .f08 .F08
# Fortran 77 suffixes: .f .F .for .FOR .f77 .F77 .ftn .FTN
F77SUFFIXES := .f .F .for .FOR .f77 .F77 .ftn .FTN
# C suffixes: .c .C .cc .CC
CSUFFIXES := .c .C .cc .CC
# C++ suffixes: .cpp .CPP .cxx .CXX .cp .CP .c++ .C++
# often .C and .cc are also taken as C++, e.g. in gcc compiler suite
CXXSUFFIXES := .cpp .CPP .cxx .CXX .cp .CP .c++ .C++
# Library suffixes: .a .so .dylib
LIBSUFFIXES := .a .so .dylib
#
# ----------------------------------------------------------
# END OF USER SECTION
# ----------------------------------------------------------
#
#
# --- PATHS ------------------------------------------------
#
# Make absolute paths from relative paths - there should be no space nor comment
# at the end of the next lines
SRCPATH1 := $(word 1, $(SRCPATH))
SRCPATH1 := $(abspath $(SRCPATH1:~%=${HOME}%))
override SRCPATH := $(abspath $(SRCPATH:~%=${HOME}%))
override PROGPATH := $(abspath $(PROGPATH:~%=${HOME}%))
override CONFIGPATH := $(abspath $(CONFIGPATH:~%=${HOME}%))
override MAKEDPATH := $(abspath $(MAKEDPATH:~%=${HOME}%))
override CHECKPATH := $(abspath $(CHECKPATH:~%=${HOME}%))
override DOXCONFIG := $(abspath $(DOXCONFIG:~%=${HOME}%))
# $(info "DOXCONFIG: "$(DOXCONFIG))
# check that all source paths exist
allexist := $(shell for pp in $(SRCPATH) ; do if [[ ! -d $$pp ]] ; then echo 'Not' ; fi ; done)
ifneq ($(allexist),)
$(error Error: Not all SRCPATH exist: $(SRCPATH))
endif
# Only Prog or Lib
ifneq ($(and $(strip $(PROGNAME)),$(strip $(LIBNAME))),)
$(error Error: only one of PROGNAME or LIBNAME can be given.)
else ifeq ($(or $(strip $(PROGNAME)),$(strip $(LIBNAME))),)
$(error Error: PROGNAME or LIBNAME must be given.)
else ifneq ($(strip $(PROGNAME)),)
ifeq ($(findstring //, /$(PROGNAME)),)
override PROGNAME := $(PROGPATH)/$(strip $(PROGNAME))
LIBNAME :=
endif
else
ifeq ($(findstring //, /$(LIBNAME)),)
override LIBNAME := $(PROGPATH)/$(strip $(LIBNAME))
PROGNAME :=
endif
endif
# allow release=true and debug=true; debug comes from command line only and
# supercedes release
releases := release debug
irelease := $(if $(debug),debug,$(release:true=release))
ifeq (,$(filter $(irelease),$(releases)))
$(error Error: release '$(irelease)' not in known releases: $(releases))
endif
# this makefile
THISMAKEFILE := $(lastword $(MAKEFILE_LIST))
# dependency files creation script
MAKEDSCRIPT := make.d.py
MAKEDPROG := $(MAKEDPATH)/$(MAKEDSCRIPT)
# .PHONY targets
# some targets should not compile the code, e.g. documentation but some targets
# should not compile but be aware of the source files, e.g. clean
iphony := False
iphonyall := False
ifneq ($(strip $(MAKECMDGOALS)),)
ifneq ($(filter $(strip $(MAKECMDGOALS)),check test html latex pdf doxygen),)
iphony := True
endif
ifneq (,$(filter $(strip $(MAKECMDGOALS)),check test html latex pdf doxygen info clean cleanclean distclean cleancheck checkclean cleantest testclean cleancleancheck checkcleanclean cleancleantest testcleanclean))
iphonyall := True
endif
endif
# ToDo: modules
# 1. set default system: modules
# 2. get SRCS1, FSRCS1, ...
# 3. search compiler
# search for the first instance of a program in PATH
# pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
# gives /bin/ls
# LS := $(call pathsearch,ls)
# 4. load modules config file which searches directories
#
# --- CHECK SYSTEM ----------------------------------------------
#
systems := $(shell ls -1 $(CONFIGPATH) | sed -e "/$(MAKEDSCRIPT)/d" -e '/f2html/d' -e '/^old/d' | cut -d '.' -f 1 | sort | uniq)
ifeq (,$(filter $(system),$(systems)))
$(error Error: system '$(system)' not found: known systems are $(systems))
endif
#
# --- ALIASES ---------------------------------------------------
#
# Include compiler alias on specific systems, e.g. nag for nag53
icompiler := $(compiler)
ALIASINC := $(CONFIGPATH)/$(system).alias
ifneq ($(strip $(ALIASINC)),)
include $(ALIASINC)
endif
#
# --- CHECK COMPILER --------------------------------------------
#
compilers := $(shell ls -1 $(CONFIGPATH) | sed -e "/$(MAKEDSCRIPT)/d" -e '/f2html/d' -e '/alias/d' -e '/~$$/d' | grep $(system) | cut -d '.' -f 2- | sort | uniq)
gnucompilers := $(filter gnu%, $(compilers))
nagcompilers := $(filter nag%, $(compilers))
intelcompilers := $(filter intel%, $(compilers))
ifeq (,$(filter $(icompiler),$(compilers)))
$(error Error: compiler '$(icompiler)' not found: configured compilers for system $(system) are $(compilers))
endif
#
# --- SOURCE FILES ---------------------------------------------------
#
# System specific files
ifeq (False,$(iphony))
SSRCS := $(foreach suff,$(system),$(wildcard $(addsuffix /*.$(suff), $(SRCPATH))))
endif
SOBJS := $(foreach suff, $(system), $(patsubst %.$(suff), %, $(filter %$(suff), $(SSRCS))))
# Available Fortran90 source files
ifeq (False,$(iphony))
SRCS1 := $(foreach suff,$(F90SUFFIXES),$(wildcard $(addsuffix /*$(suff), $(SRCPATH))))
endif
# exclude user-defined $(EXCLUDE_FILES)
SRCS := $(foreach f,$(SRCS1),$(if $(findstring $(f),$(abspath $(EXCLUDE_FILES))),,$(f)))
# source files but with suffix .o
OSRCS := $(foreach suff, $(F90SUFFIXES), $(patsubst %$(suff), %.o, $(filter %$(suff), $(SRCS))))
# object files
OBJS := $(join $(dir $(OSRCS)), $(addprefix .$(strip $(icompiler)).$(strip $(irelease))/,$(notdir $(OSRCS))))
# dependency files
DOBJS := $(OBJS:.o=.d)
# g90 debug files of NAG compiler are in current directory or in source directory
GOBJS := $(addprefix $(CURDIR)/,$(patsubst %.o,%.g90,$(notdir $(OBJS)))) $(patsubst %.o,%.g90,$(OSRCS))
# Fortran77
ifeq (False,$(iphony))
FSRCS1 := $(foreach suff,$(F77SUFFIXES),$(wildcard $(addsuffix /*$(suff), $(SRCPATH))))
endif
FSRCS := $(foreach f,$(FSRCS1),$(if $(findstring $(f),$(abspath $(EXCLUDE_FILES))),,$(f)))
FOSRCS := $(foreach suff, $(F77SUFFIXES), $(patsubst %$(suff), %.o, $(filter %$(suff), $(FSRCS))))
FOBJS := $(join $(dir $(FOSRCS)), $(addprefix .$(strip $(icompiler)).$(strip $(irelease))/,$(notdir $(FOSRCS))))
FDOBJS := $(FOBJS:.o=.d)
FGOBJS := $(addprefix $(CURDIR)/,$(patsubst %.o,%.g90,$(notdir $(FOBJS)))) $(patsubst %.o,%.g90,$(FOSRCS))
# C
ifeq (False,$(iphony))
CSRCS1 := $(foreach suff,$(CSUFFIXES),$(wildcard $(addsuffix /*$(suff), $(SRCPATH))))
endif
CSRCS := $(foreach f,$(CSRCS1),$(if $(findstring $(f),$(abspath $(EXCLUDE_FILES))),,$(f)))
COSRCS := $(foreach suff, $(CSUFFIXES), $(patsubst %$(suff), %.o, $(filter %$(suff), $(CSRCS))))
COBJS := $(join $(dir $(COSRCS)), $(addprefix .$(strip $(icompiler)).$(strip $(irelease))/,$(notdir $(COSRCS))))
CDOBJS := $(COBJS:.o=.d)
# C++
ifeq (False,$(iphony))
CXXSRCS1 := $(foreach suff,$(CXXSUFFIXES),$(wildcard $(addsuffix /*$(suff), $(SRCPATH))))
endif
CXXSRCS := $(foreach f,$(CXXSRCS1),$(if $(findstring $(f),$(abspath $(EXCLUDE_FILES))),,$(f)))
CXXOSRCS := $(foreach suff, $(CXXSUFFIXES), $(patsubst %$(suff), %.o, $(filter %$(suff), $(CXXSRCS))))
CXXOBJS := $(join $(dir $(CXXOSRCS)), $(addprefix .$(strip $(icompiler)).$(strip $(irelease))/,$(notdir $(CXXOSRCS))))
CXXDOBJS := $(CXXOBJS:.o=.d)
# Libraries
ifeq (False,$(iphony))
LSRCS1 := $(foreach suff,$(LIBSUFFIXES),$(wildcard $(addsuffix /*$(suff), $(SRCPATH))))
endif
LSRCS := $(foreach f,$(LSRCS1),$(if $(findstring $(f),$(abspath $(EXCLUDE_FILES))),,$(f)))
LOSRCS := $(foreach suff, $(LIBSUFFIXES), $(patsubst %$(suff), %, $(filter %$(suff), $(LSRCS))))
LOBJS := $(addprefix -L,$(dir $(SRCPATH))) $(addprefix -l, $(patsubst lib%, %, $(notdir $(LOSRCS))))
#
# --- DEFAULTS ---------------------------------------------------
#
# These variables will be used to compile and link, and therefore expanded below
# Fortran77
FC :=
FCFLAGS := $(EXTRA_FCFLAGS)
# Fortran90
F90 :=
F90FLAGS := $(EXTRA_F90FLAGS)
# C
CC :=
CFLAGS := $(EXTRA_CFLAGS)
# C++
CXX :=
CXXFLAGS := $(EXTRA_CXXFLAGS)
# all
CPP :=
DEFINES := $(EXTRA_DEFINES)
INCLUDES := $(EXTRA_INCLUDES) $(addprefix -I,$(SRCPATH))
# linking
LD :=
LDFLAGS := $(EXTRA_LDFLAGS)
LIBS := $(EXTRA_LIBS) $(addprefix -L,$(SRCPATH))
# library
AR := ar
ARFLAGS := -ru
RANLIB := ranlib
#
# --- COMPILER / MACHINE SPECIFIC --------------------------------
#
# Set path where all the .mod, .o, etc. files will be written, set before include $(MAKEINC)
OBJPATH := $(addsuffix /.$(strip $(icompiler)).$(strip $(irelease)), $(SRCPATH))
# Files with lists of file names
OBJPATH1 := $(addsuffix /.$(strip $(icompiler)).$(strip $(irelease)), $(SRCPATH1))
MAKEDICT := $(addsuffix /$(MAKEDSCRIPT:.py=.dict), $(OBJPATH1))
SRCSFILE := $(OBJPATH1)/make.d.srcs
OBJSFILE := $(OBJPATH1)/make.d.objs
DOBJSFILE := $(OBJPATH1)/make.d.dobjs
FSRCSFILE := $(OBJPATH1)/make.d.fsrcs
FOBJSFILE := $(OBJPATH1)/make.d.fobjs
FDOBJSFILE := $(OBJPATH1)/make.d.fdobjs
CSRCSFILE := $(OBJPATH1)/make.d.csrcs
COBJSFILE := $(OBJPATH1)/make.d.cobjs
CDOBJSFILE := $(OBJPATH1)/make.d.cdobjs
CXXSRCSFILE := $(OBJPATH1)/make.d.cxxsrcs
CXXOBJSFILE := $(OBJPATH1)/make.d.cxxobjs
CXXDOBJSFILE := $(OBJPATH1)/make.d.cxxdobjs
LSRCSFILE := $(OBJPATH1)/make.d.lsrcs
LOBJSFILE := $(OBJPATH1)/make.d.lobjs
ifeq (False,$(iphonyall))
$(shell for dd in $(OBJPATH) ; do if [[ ! -d $$dd ]] ; then mkdir -p $$dd ; fi ; done)
$(shell if [[ -f $(SRCSFILE) ]] ; then rm $(SRCSFILE) ; fi ; echo $(SRCS) | tr ' ' '\n' >> $(SRCSFILE))
$(shell if [[ -f $(OBJSFILE) ]] ; then rm $(OBJSFILE) ; fi ; echo $(OBJS) | tr ' ' '\n' >> $(OBJSFILE))
$(shell if [[ -f $(DOBJSFILE) ]] ; then rm $(DOBJSFILE) ; fi ; echo $(DOBJS) | tr ' ' '\n' >> $(DOBJSFILE))
$(shell if [[ -f $(FSRCSFILE) ]] ; then rm $(FSRCSFILE) ; fi ; echo $(FSRCS) | tr ' ' '\n' >> $(FSRCSFILE))
$(shell if [[ -f $(FOBJSFILE) ]] ; then rm $(FOBJSFILE) ; fi ; echo $(FOBJS) | tr ' ' '\n' >> $(FOBJSFILE))
$(shell if [[ -f $(FDOBJSFILE) ]] ; then rm $(FDOBJSFILE) ; fi ; echo $(FDOBJS) | tr ' ' '\n' >> $(FDOBJSFILE))
$(shell if [[ -f $(CSRCSFILE) ]] ; then rm $(CSRCSFILE) ; fi ; echo $(CSRCS) | tr ' ' '\n' >> $(CSRCSFILE))
$(shell if [[ -f $(COBJSFILE) ]] ; then rm $(COBJSFILE) ; fi ; echo $(COBJS) | tr ' ' '\n' >> $(COBJSFILE))
$(shell if [[ -f $(CDOBJSFILE) ]] ; then rm $(CDOBJSFILE) ; fi ; echo $(CDOBJS) | tr ' ' '\n' >> $(CDOBJSFILE))
$(shell if [[ -f $(CXXSRCSFILE) ]] ; then rm $(CXXSRCSFILE) ; fi ; echo $(CXXSRCS) | tr ' ' '\n' >> $(CXXSRCSFILE))
$(shell if [[ -f $(CXXOBJSFILE) ]] ; then rm $(CXXOBJSFILE) ; fi ; echo $(CXXOBJS) | tr ' ' '\n' >> $(CXXOBJSFILE))
$(shell if [[ -f $(CXXDOBJSFILE) ]] ; then rm $(CXXDOBJSFILE) ; fi ; echo $(CXXDOBJS) | tr ' ' '\n' >> $(CXXDOBJSFILE))
$(shell if [[ -f $(LSRCSFILE) ]] ; then rm $(LSRCSFILE) ; fi ; echo $(LSRCS) | tr ' ' '\n' >> $(LSRCSFILE))
$(shell if [[ -f $(LOBJSFILE) ]] ; then rm $(LOBJSFILE) ; fi ; echo $(LOBJS) | tr ' ' '\n' >> $(LOBJSFILE))
endif
# macOS is special, there is (almost) no static linking.
# macOS does not work with -rpath. Set DYLD_LIBRARY_PATH if needed.
iOS := $(shell uname -s)
istatic := $(static)
ifneq (,$(filter $(iOS),Darwin))
istatic := dynamic
endif
# Include the individual configuration files
MAKEINC := $(addsuffix /$(system).$(icompiler), $(abspath $(CONFIGPATH:~%=${HOME}%)))
ifeq ($(strip $(MAKEINC)),)
$(error Error: Individual configuration file '$(MAKEINC)' not found.)
endif
include $(MAKEINC)
# Always use -D__CFORTRAN__ for mixed C and Fortran compilations
DEFINES += -D__CFORTRAN__
# Start group for cyclic search in static linking
iLIBS :=
ifeq ($(istatic),static)
iLIBS += -Bstatic -Wl,--start-group
else
ifneq (,$(filter $(iOS),Darwin))
iLIBS += -Wl,-dynamic
else
iLIBS += -Bdynamic
endif
endif
ifneq (,$(SOBJS))
$(foreach ff,$(SOBJS),$(shell if [[ -f $(ff) ]] ; then isdiff=`diff $(ff) $(ff).$(system)` ; if [[ "$${isdiff}z" != "z" ]] ; then cp $(ff).$(system) $(ff) ; fi ; else cp $(ff).$(system) $(ff) ; fi))
endif
# --- LINKER ---------------------------------------------------
# Link with compiler for main file
ifneq ($(LINKER),)
ifneq ($(filter $(strip $(LINKER)),fortran Fortran FORTRAN for For FOR),)
LD := $(F90)
endif
ifneq ($(filter $(strip $(LINKER)),c C),)
LD := $(CC)
endif
ifneq ($(filter $(strip $(LINKER)),c++ C++ cxx CXX),)
LD := $(CXX)
endif
else
# Link with the fortran compiler if fortran code
ifneq ($(SRCS)$(FSRCS),)
LD := $(F90)
else
LD := $(CC)
endif
endif
# --- INCLUDES/LIBS/FLAGS/DEFINES/RPATH --------------------------
SDIRS := $(EXTRA_DIRS)
ifeq ($(lapack),true)
ifeq (,$(filter $(mkl),mkl mkl95))
SDIRS += LAPACKDIR
SDIRS += BLASDIR
endif
else ifeq ($(lapack),mkl)
ifeq (,$(filter $(mkl),mkl mkl95))
override mkl := mkl
endif
endif
ifneq (,$(filter $(mkl),mkl mkl95))
# First mkl95 then mkl for .mod files other then intel
ifeq ($(mkl),mkl95)
SDIRS += MKL95DIR
endif
SDIRS += MKLDIR
endif
ifneq (,$(filter $(netcdf),netcdf3 netcdf4))
SDIRS += NCFDIR NCDIR
ifeq ($(netcdf),netcdf4)
SDIRS += HDF5DIR SZDIR CURLDIR ZDIR
endif
endif
ifeq ($(proj),true)
SDIRS += PROJ4DIR FPROJDIR
endif
ifneq (,$(filter $(mpi),openmpi mpich))
ifeq ($(netcdf),openmpi)
SDIRS += OPENMPIDIR
endif
ifeq ($(netcdf),mpich)
SDIRS += MPICHDIR
endif
endif
ifneq (,$(filter $(imsl),vendor imsl))
SDIRS += IMSLDIR
endif
# function (=) used below to set flag if given
if_flag = $(if $($(dir:DIR=FLAG)),$($(dir:DIR=FLAG)))
# include flags such as -I/usr/local/include
INCLUDES += $(foreach dir,$(SDIRS),$(if $($(dir:DIR=INC)),-I$($(dir:DIR=INC)),$(if $($(dir)),-I$($(dir))/include)))
# lib flags such as -L/usr/local/lib -lcurl
iLIBS += $(foreach dir,$(SDIRS),$(if $($(dir:DIR=LIB)),-L$($(dir:DIR=LIB)) $(if_flag),$(if $($(dir)),-L$($(dir))/lib $(if_flag))))
# lib flags that do not have a directory such as -lz or -framework Accelerate
iLIBS += $(foreach dir,$(SDIRS),$(if $(or $($(dir)),$($(dir:DIR=LIB))),,$(if_flag)))
# rpath
WL := -Wl,-rpath,
RPATH += $(foreach dir,$(SDIRS),$(if $($(dir:DIR=LIB)),$(WL)$($(dir:DIR=LIB)),$(if $($(dir)),$(WL)$($(dir))/lib)))
# defines
DEFINES += $(foreach dir,$(SDIRS),$(if $($(dir:DIR=DEF)),$($(dir:DIR=DEF))))
# --- MPI ---------------------------------------------------
MPI_F90FLAGS :=
MPI_FCFLAGS :=
MPI_CFLAGS :=
MPI_CXXFLAGS :=
MPI_LDFLAGS :=
ifeq ($(mpi),openmpi)
MPIINC ?= $(OPENMPIDIR)/include
MPILIB ?= $(OPENMPIDIR)/lib
MPIBIN ?= $(OPENMPIDIR)/bin
MPI_F90FLAGS += $(shell $(MPIBIN)/mpif90 --showme:compile)
MPI_FCFLAGS += $(shell $(MPIBIN)/mpif77 --showme:compile)
MPI_CFLAGS += $(shell $(MPIBIN)/mpicc --showme:compile)
MPI_CXXFLAGS += $(shell $(MPIBIN)/mpicxx --showme:compile)
ifeq ($(LD),$(F90))
MPI_LDFLAGS += $(shell $(MPIBIN)/mpif90 --showme:link)
else
MPI_LDFLAGS += $(shell $(MPIBIN)/mpicc --showme:link)
endif
INCLUDES += -I$(MPILIB) # mpi.h in lib and not include
endif
ifeq ($(mpi),mpich)
MPIINC ?= $(MPICHDIR)/include
MPILIB ?= $(MPICHDIR)/lib
MPIBIN ?= $(MPICHDIR)/bin
MPI_F90FLAGS += $(shell $(MPIBIN)/mpifort -compile_info | cut -d ' ' -f 2-)
MPI_FCFLAGS += $(shell $(MPIBIN)/mpifort -compile_info | cut -d ' ' -f 2-)
MPI_CFLAGS += $(shell $(MPIBIN)/mpicc -compile_info | cut -d ' ' -f 2-)
MPI_CXXFLAGS += $(shell $(MPIBIN)/mpicxx -compile_info | cut -d ' ' -f 2-)
ifeq ($(LD),$(F90))
MPI_LDFLAGS += $(shell $(MPIBIN)/mpif90 -link_info | cut -d ' ' -f 2-)
else
MPI_LDFLAGS += $(shell $(MPIBIN)/mpicc -link_info | cut -d ' ' -f 2-)
endif
endif
# --- OPENMP ---------------------------------------------------
iopenmp :=
ifeq ($(openmp),true)
F90FLAGS += $(F90OMPFLAG)
FCFLAGS += $(FCOMPFLAG)
CFLAGS += $(COMPFLAG)
CXXFLAGS += $(CXXOMPFLAG)
LDFLAGS += $(LDOMPFLAG)
DEFINES += $(OMPDEFINE)
else ifneq (,$(filter $(imsl),vendor imsl))
# IMSL needs openmp during linking in any case
LDFLAGS += $(LDOMPFLAG)
endif
# --- DOXYGEN ---------------------------------------------------
DOXYGEN := $(if $(DOXYGENDIR),$(strip $(DOXYGENDIR))/doxygen,$(shell which doxygen 2>/dev/null))
DOTPATH := $(if $(DOTDIR),$(strip $(DOTDIR)),$(dir $(shell which dot 2>/dev/null)))
TEXPATH := $(if $(TEXDIR),$(strip $(TEXDIR)),$(dir $(shell which latex 2>/dev/null)))
PERLPATH := $(if $(PERLDIR),$(strip $(PERLDIR)),$(dir $(shell which perl 2>/dev/null)))
# --- INTEL F2003 REALLOC-LHS ---------------------------------------
ifneq (,$(filter $(icompiler),$(intelcompilers)))
F90FLAGS1 := $(subst -assume realloc-lhs,,"$(F90FLAGS)")
else
F90FLAGS1 := $(F90FLAGS)
endif
#
# --- FINISH SETUP ---------------------------------------------------
#
ifeq ($(irelease),debug)
DEFINES += -D__DEBUG__
endif
# End group for cyclic search in static linking
ifeq ($(istatic),static)
iLIBS += -Wl,--end-group
endif
# The NAG compiler links via gcc so that one has to give -Wl twice and double
# commas for the option,
# i.e. instead of -Wl,rpath,/path you need -Wl,-Wl,,rpath,,/path
ifneq (,$(filter $(icompiler),$(nagcompilers)))
comma := ,
iiLIBS := $(subst -Wl,-Wl$(comma)-Wl,$(subst $(comma),$(comma)$(comma),$(iLIBS)))
iRPATH := $(subst -Wl,-Wl$(comma)-Wl,$(subst $(comma),$(comma)$(comma),$(RPATH)))
else
iiLIBS := $(iLIBS)
iRPATH := $(RPATH)
endif
LIBS += $(iiLIBS)
# Only Linux and Solaris can use -rpath in executable
ifeq (,$(filter $(iOS),Darwin))
LIBS += $(iRPATH)
endif
# export LD_LIBRARY_PATH of make.config files
ifneq ($(LDPATH),)
empty:=
space:= $(empty) $(empty)
export LD_LIBRARY_PATH=$(subst $(space),$(empty),$(LDPATH))
endif
INCLUDES += $(addprefix -I,$(OBJPATH))
#
# --- TARGETS ---------------------------------------------------
#
#.SUFFIXES: .f90 .F90 .f95 .F95 .f03 .F03 .f08 .F08 .f .F .for .FOR
# .ftn .FTN .c .C .cc .CC .d .o .a .so .dylib
.SUFFIXES:
.PHONY: clean cleanclean distclean cleantest testclean checkclean cleancheck cleancleantest testcleanclean checkcleanclean cleancleancheck html latex pdf doxygen check test info
all: $(PROGNAME) $(LIBNAME)
# Link program
$(PROGNAME): $(OBJS) $(FOBJS) $(COBJS) $(CXXOBJS)
@echo "Linking program"
$(LD) $(LDFLAGS) -o $(PROGNAME) $(OBJS) $(FOBJS) $(COBJS) $(CXXOBJS) $(LIBS) $(LOBJS) $(MPI_LDFLAGS)
# Link library
# $(LIBNAME): $(DOBJS) $(FDOBJS) $(CDOBJS) $(CXXDOBJS) $(OBJS) $(FOBJS) $(COBJS) $(CXXOBJS)
$(LIBNAME): $(OBJS) $(FOBJS) $(COBJS) $(CXXOBJS)
@echo "Linking library"
$(AR) $(ARFLAGS) $(LIBNAME) $(OBJS) $(FOBJS) $(COBJS) $(CXXOBJS)
$(RANLIB) $(LIBNAME)
# make all .d for the non-pre-processed Fortran source files
$(MAKEDICT):
@if [[ ! -f $(MAKEDICT) ]] ; then \
$(MAKEDPROG) .$(strip $(icompiler)).$(strip $(irelease)) $(SRCSFILE) $(FSRCSFILE) ; fi
# Get dependencies, retreat pre-processed files if needed
$(DOBJS): $(MAKEDICT)
@nobj=$$(grep -n -w -F $@ $(DOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(SRCSFILE)) ; \
$(CPP) -C -P $(DEFINES) $(INCLUDES) $$src > $$src.pre 2>/dev/null ; \
dd=$$(diff -B -q $$src -i $$src.pre) ; \
if [[ -n $$dd ]] ; then \
$(MAKEDPROG) -f $$src -i $$src.pre .$(strip $(icompiler)).$(strip $(irelease)) $(SRCSFILE) $(FSRCSFILE) ; fi ; \
\rm $$src.pre
$(FDOBJS):
@nobj=$$(grep -n -w -F $@ $(FDOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(FSRCSFILE)) ; \
obj=$$(sed -n $${nobj}p $(FOBJSFILE)) ; \
dobj=$$(sed -n $${nobj}p $(FOBJSFILE) | sed 's|\.o[[:blank:]]*$$|.d|') ; \
echo "$$obj $$dobj : $$src" > $$dobj
$(CDOBJS):
@nobj=$$(grep -n -w -F $@ $(CDOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(CSRCSFILE)) ; \
pobj=$(dir $@) ; psrc=$(dir $$src) ; \
$(CC) -E $(DEFINES) $(INCLUDES) -MM $$src | sed "s|.*:|$(patsubst %.d,%.o,$@) $@ :|" > $@
$(CXXDOBJS):
@nobj=$$(grep -n -w -F $@ $(CXXDOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(CXXSRCSFILE)) ; \
pobj=$(dir $@) ; psrc=$(dir $$src) ; \
$(CXX) -E $(DEFINES) $(INCLUDES) -MM $$src | sed "s|.*:|$(patsubst %.d,%.o,$@) $@ :|" > $@
# Compile
$(OBJS):
ifneq (,$(filter $(icompiler),gnu41 gnu42))
@nobj=$$(grep -n -w -F $@ $(OBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(SRCSFILE)) ; \
ssrc=$$(basename $$(sed -n $${nobj}p $(SRCSFILE))) ; \
tmp=$@.$$(echo $${src} | sed 's/.*\.//') ; \
doex=$$(echo $(INTEL_EXCLUDE) | grep -i "$${ssrc}" -) ; \
f90flag=$$(if [[ "$${doex}" != "" ]] ; then echo "$(F90FLAGS1)" ; else echo "$(F90FLAGS)" ; fi) ; \
echo "$(F90) -E $(DEFINES) $(INCLUDES) $${f90flag} $${src} | sed 's/^#[[:blank:]]\{1,\}[[:digit:]]\{1,\}.*$$//' > $${tmp}" ; \
$(F90) -E $(DEFINES) $(INCLUDES) $${f90flag} $${src} | sed 's/^#[[:blank:]]\{1,\}[[:digit:]]\{1,\}.*$$//' > $${tmp} ; \
echo "$(F90) $(DEFINES) $(INCLUDES) $(MPI_F90FLAGS) $(F90FLAGS) $(MODFLAG)$(dir $@) -c $${tmp} -o $@" ; \
$(F90) $(DEFINES) $(INCLUDES) $(MPI_F90FLAGS) $(F90FLAGS) $(MODFLAG)$(dir $@) -c $${tmp} -o $@ ; \
rm $${tmp}
else
@nobj=$$(grep -n -w -F $@ $(OBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(SRCSFILE)) ; \
ssrc=$$(basename $$(sed -n $${nobj}p $(SRCSFILE))) ; \
doex=$$(echo $(INTEL_EXCLUDE) | grep -i "$${ssrc}" -) ; \
f90flag=$$(if [[ "$${doex}" != "" ]] ; then echo "$(F90FLAGS1)" ; else echo "$(F90FLAGS)" ; fi) ; \
echo $(F90) $(DEFINES) $(INCLUDES) $(MPI_F90FLAGS) $${f90flag} $(MODFLAG)$(dir $@) -c $${src} -o $@ ; \
$(F90) $(DEFINES) $(INCLUDES) $(MPI_F90FLAGS) $${f90flag} $(MODFLAG)$(dir $@) -c $${src} -o $@
endif
$(FOBJS):
ifneq (,$(filter $(icompiler),gnu41 gnu42))
@nobj=$$(grep -n -w -F $@ $(FOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(FSRCSFILE)) ; \
tmp=$@.$$(echo $${src} | sed 's/.*\.//') ; \
echo "$(FC) -E $(DEFINES) $(INCLUDES) $(FCFLAGS) $${src} | sed 's/^#[[:blank:]]\{1,\}[[:digit:]]\{1,\}.*$$//' > $${tmp}" ; \
$(FC) -E $(DEFINES) $(INCLUDES) $(FCFLAGS) $${src} | sed 's/^#[[:blank:]]\{1,\}[[:digit:]]\{1,\}.*$$//' > $${tmp} ; \
echo "$(FC) $(DEFINES) $(INCLUDES) $(MPI_FCFLAGS) $(FCFLAGS) -c $${tmp} -o $@" ; \
$(FC) $(DEFINES) $(INCLUDES) $(MPI_FCFLAGS) $(FCFLAGS) -c $${tmp} -o $@ ; \
rm $${tmp}
else
@nobj=$$(grep -n -w -F $@ $(FOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(FSRCSFILE)) ; \
echo $(FC) $(DEFINES) $(INCLUDES) $(MPI_FCFLAGS) $(FCFLAGS) -c $$src -o $@ ; \
$(FC) $(DEFINES) $(INCLUDES) $(MPI_FCFLAGS) $(FCFLAGS) -c $$src -o $@
endif
$(COBJS):
@nobj=$$(grep -n -w -F $@ $(COBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(CSRCSFILE)) ; \
echo $(CC) $(DEFINES) $(INCLUDES) $(MPI_CFLAGS) $(CFLAGS) -c $${src} -o $@ ; \
$(CC) $(DEFINES) $(INCLUDES) $(MPI_CFLAGS) $(CFLAGS) -c $${src} -o $@
$(CXXOBJS):
@nobj=$$(grep -n -w -F $@ $(CXXOBJSFILE) | sed 's/:.*//') ; \
src=$$(sed -n $${nobj}p $(CXXSRCSFILE)) ; \
echo $(CXX) $(DEFINES) $(INCLUDES) $(MPI_CXXFLAGS) $(CXXFLAGS) -c $${src} -o $@ ; \
$(CXX) $(DEFINES) $(INCLUDES) $(MPI_CXXFLAGS) $(CXXFLAGS) -c $${src} -o $@
# Helper Targets
clean:
ifneq (,$(SOBJS))
for ff in $(SOBJS) ; do if [[ -f $${ff}.default ]] ; then cp $${ff}.default $${ff} ; fi ; done
endif
ifneq ($(strip $(OBJS)),)
rm -f $(OBJS)
endif
ifneq ($(strip $(DOBJS)),)
rm -f $(DOBJS)
endif
ifneq ($(strip $(FOBJS)),)
rm -f $(FOBJS)
endif
ifneq ($(strip $(FDOBJS)),)
rm -f $(FDOBJS)
endif
ifneq ($(strip $(COBJS)),)
rm -f $(COBJS)
endif
ifneq ($(strip $(CDOBJS)),)
rm -f $(CDOBJS)
endif
ifneq ($(strip $(CXXOBJS)),)
rm -f $(CXXOBJS)
endif
ifneq ($(strip $(CXXDOBJS)),)
rm -f $(CXXDOBJS)
endif
ifneq ($(strip $(GOBJS)),)
rm -f $(GOBJS)
endif
ifneq ($(strip $(FGOBJS)),)
rm -f $(FGOBJS)
endif
rm -f $(addsuffix /*.mod, $(OBJPATH))
rm -f $(addsuffix /*.pre, $(SRCPATH))
ifneq ($(PROGNAME),)
rm -f "$(PROGNAME)"
rm -rf "$(PROGNAME)".dSYM
endif
ifneq ($(LIBNAME),)
rm -f "$(LIBNAME)"
endif
ifneq ($(SRCPATH),)
rm -rf $(addsuffix /.$(strip $(icompiler)).$(strip $(irelease)),$(SRCPATH))
rm -f $(addsuffix /*make_check_test_file, $(SRCPATH))
rm -f $(addsuffix /*make_check_test_file, .)
endif
cleanclean:
for irr in release debug ; do \
for icc in $(compilers) ; do \
$(MAKE) -f $(THISMAKEFILE) system=$(system) release=$$irr compiler=$$icc \
MAKEDPATH=$(MAKEDPATH) SRCPATH="$(SRCPATH)" PROGPATH=$(PROGPATH) \
CONFIGPATH=$(CONFIGPATH) PROGNAME=$(PROGNAME) \
clean ; \
done ; \
done
rm -rf $(addsuffix /.*.r*, $(SRCPATH))
rm -rf $(addsuffix /.*.d*, $(SRCPATH))
rm -rf $(addsuffix /html, $(SRCPATH))
@if [ -f "$(DOXCONFIG)" ] ; then rm -rf $(PROGPATH)/latex ; fi
@if [ -f "$(DOXCONFIG)" ] ; then rm -rf $(PROGPATH)/html ; fi
distclean: cleanclean
cleancheck:
for i in $(shell ls -d $(CHECKPATH)/test* $(CHECKPATH)/check* 2> /dev/null) ; do \
$(MAKE) -f $(THISMAKEFILE) system=$(system) release=$(irelease) compiler=$(compiler) SRCPATH=$$i clean ; \
done
cleantest: cleancheck
checkclean: cleancheck
testclean: cleancheck
cleancleancheck:
for i in $(shell ls -d $(CHECKPATH)/test* $(CHECKPATH)/check* 2> /dev/null) ; do \
$(MAKE) -f $(THISMAKEFILE) system=$(system) release=$(irelease) compiler=$(compiler) SRCPATH=$$i cleanclean ; \
done
cleancleantest: cleancleancheck
checkcleanclean: cleancleancheck
testcleanclean: cleancleancheck
check:
ifeq ($(PROGNAME),)
$(error Error: check and test must be done with given PROGNAME.)
endif
isdir=${PWD} ; \
for i in $(shell ls -d $(CHECKPATH)/test* $(CHECKPATH)/check* 2> /dev/null) ; do \
rm -f "$(PROGNAME)" ; \
j=$$(echo $${i} | grep -E '(minpack|netcdf3|qhull)$$') ; \
inetcdf=$(netcdf) ; \
libextra= ; \
incextra= ; \
defextra= ; \
if [ "$${j}z" != "z" ] ; then \
ldir=$${i##*_} ; \
lname="lib$${ldir}.a" ; \
libextra="-L. -l$${ldir}" ; \
case $${i} in \
*minpack) true ;; \
*netcdf3) inetcdf= ; \
incextra="-I$${i}/../../netcdf3/.$(strip $(icompiler)).$(strip $(irelease))" ; \
defextra='-D__NETCDF3__' ;; \
*qhull) true ;; \
esac ; \
$(MAKE) -f $(THISMAKEFILE) -s \
MAKEDPATH=$(MAKEDPATH) SRCPATH="$${i}"/../../$${ldir} PROGPATH=$(PROGPATH) \
CONFIGPATH=$(CONFIGPATH) PROGNAME= LIBNAME=$${lname} \
system=$(system) release=$(irelease) compiler=$(compiler) \
netcdf=$${inetcdf} static=$(static) proj=$(proj) imsl=$(imsl) mkl=$(mkl) \
lapack=$(lapack) openmp=$(openmp) > /dev/null ; \
fi ; \
$(MAKE) -f $(THISMAKEFILE) -s \
MAKEDPATH=$(MAKEDPATH) SRCPATH="$${i}" PROGPATH=$(PROGPATH) \
CONFIGPATH=$(CONFIGPATH) PROGNAME=$(PROGNAME) \
system=$(system) release=$(irelease) compiler=$(compiler) \
netcdf=$${inetcdf} static=$(static) proj=$(proj) imsl=$(imsl) mkl=$(mkl) \
lapack=$(lapack) openmp=$(openmp) \
EXTRA_LIBS="$${libextra}" EXTRA_DEFINES="$${defextra}" EXTRA_INCLUDES="$${incextra}" > /dev/null \
&& { cd $${i} ; $(PROGNAME) 2>&1 | grep -E '(o\.k\.|failed)' ; cd - > /dev/null 2>&1 ;} ; status=$$? ; \
if [ $${status} != 0 ] ; then echo "$${i} failed!" ; else echo "$${i} o.k." ; fi ; \