forked from Goddard-Fortran-Ecosystem/pFUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
308 lines (267 loc) · 7.97 KB
/
GNUmakefile
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
.PHONY: tests all install documentation config
TOP_DIR ?=$(shell pwd)
DOC_DIR = $(TOP_DIR)/documentation
EXAMPLES_DIR = $(TOP_DIR)/Examples
SOURCE_DIR = $(TOP_DIR)/source
TESTS_DIR = $(TOP_DIR)/tests
INCLUDE_DIR = $(TOP_DIR)/include
VPATH += $(SOURCE_DIR) $(INCLUDE_DIR)
# Set DOXYGEN to the desired executable.
# NOTE: Doxygen Version 1.8.5 does not respect CamelCase names from
# Fortran source code by currently converting all to lowercase. It
# does this to get HTML links correct for references in the source
# code that also do not respect the CamelCase convention. The Fortran
# standard specifies case insensitivity.
#
# DOXYGEN = /opt/local/share/doxygen/doxygen-1.7.6/bin/doxygen
# DOXYGEN = /opt/local/share/doxygen/doxygen-1.7.5.1/bin/doxygen
DOXYGEN ?= doxygen
#
# Set PYTHON executable if needed. Python scripts all use
# /usr/bin/env to call python. Explicit calls to python in the
# makefiles now use $(PYTHON). If python defaults to version 3 on a
# system one can set PYTHON to python2 here. Or one can create a
# symbolic link to python2 from python in the PATH. For example:
#
# ln -s /usr/bin/python2 ~/bin/python
# ln -s /usr/bin/python2-config ~/bin/python-config
# export PATH=~/bin:${PATH}
#
# Then build pFUnit.
#
PYTHON = python
# Determine operating system, architecture and compiler
# automatically if possible
UNAME ?=$(shell uname)
ifeq ($(UNAME),)
UNAME =UNKNOWN
else
# Check for Windows/CYGWIN compilation.
ifneq (,$(findstring CYGWIN,$(UNAME)))
UNAME =Windows
endif
endif
# ARCH ?=$(shell arch)
ARCH ?=$(shell uname -m)
ifeq ($(ARCH),)
ARCH =UNKNOWN
endif
ifneq ($(UNAME),Windows)
# Also set the archiver and RANLIB options.
NULL :=
SPACE := ${NULL} ${NULL}
AR = ar -r$(SPACE)
RANLIB ?= ranlib
OUTPUT_FLAG ?= -o$(SPACE)
else
# Also set the archiver and RANLIB options.
AR = lib /out:
RANLIB ?= echo
OUTPUT_FLAG ?= /nologo /Fe
endif
# Set the relevant file extensions
include $(INCLUDE_DIR)/extensions.mk
# 32/64 ABI - almost all architectures are now 64 bit
ifeq ($(ARCH),i386)
PFUNIT_ABI ?=32
else
PFUNIT_ABI ?=64
endif
# Other defaults
MPI ?=NO # do not include MPI capabilities
OPENMP ?=NO # do not include OpenMP threading
# MAX_RANK ?=$(PFUNIT_MAX_RANK) # Maximum rank of arrays in assertions
MAX_RANK ?=5
# Remove the following at version 4.
ifneq ($(origin PFUNIT_MAX_RANK), undefined)
MAX_RANK=$(PFUNIT_MAX_RANK)
endif
# The following supersedes the previous.
ifneq ($(origin PFUNIT_MAX_ARRAY_RANK), undefined)
MAX_RANK=$(PFUNIT_MAX_ARRAY_RANK)
endif
ifneq ($(UNAME),Windows)
ROBUST ?=YES # for now include RobustRunner by default
else
ROBUST = NO
endif
# F90 Vendor common elements (override below)
FFLAGS ?=
D=-D
I=-I
MOD=-I
DEBUG_FLAGS =-g
# Default compiler by architecture - always gfortran for now:
F90 ?=gfortran
F90_VENDOR ?=GNU
# F90 Vendor specifics
# Possibly F90 defined - makes things simple:
ifneq (,$(findstring $(F90), ifort gfortran nag nagfor pgfortran xlf))
ifeq ($(F90),ifort)
COMPILER=Intel
else ifeq ($(F90),gfortran)
COMPILER=GNU
else ifeq ($(F90),nagfor)
COMPILER=NAG
else ifeq ($(F90),pgfortran)
COMPILER=PGI
else ifneq (,$(findstring $(F90),xlf))
COMPILER=IBM
else
COMPILER=UNKNOWN
endif
# Override F90_VENDOR with COMPILER
F90_VENDOR=$(COMPILER)
else # use F90_VENDOR to specify
ifneq (,$(findstring $(F90_VENDOR),INTEL Intel intel ifort))
COMPILER=Intel
else ifneq (,$(findstring $(F90_VENDOR),GNU gnu gfortran GFortran GFORTRAN))
COMPILER=GNU
else ifneq (,$(findstring $(F90_VENDOR),nag NAG nagfor))
COMPILER=NAG
else ifneq (,$(findstring $(F90_VENDOR),pgi PGI pgfortran))
COMPILER=PGI
else ifneq (,$(findstring $(F90_VENDOR),ibm IBM xlf XLF))
COMPILER=IBM
endif
endif
# F90_VENDOR is no longer needed after this point. We keep it around
# until we can verify that it's not needed in subdirectories or for
# recursive calls. TODO: Check F90_VENDOR usage.
ifneq ($(findstring $(MPI),yes YES Yes),)
USEMPI=YES
MPIF90 ?= mpif90
MPIRUN ?= mpirun
FPPFLAGS += $DUSE_MPI
CPPFLAGS += -DUSE_MPI
ifeq ($(MPICH),YES)
LIBMPI ?=-lmpich
else
# The following may be redundant and better handled via an MPI's linking script. 2013-1104 MLR
# LIBMPI ?=-lmpi
LIBMPI ?=
endif
LDFLAGS += $(LIBMPI)
endif
ifneq ($(findstring $(OPENMP),yes YES Yes),)
USEOPENMP=YES
endif
ifneq ($(findstring $(ROBUST),yes YES Yes),)
BUILDROBUST=YES
FPPFLAGS += $DBUILD_ROBUST
CPPFLAGS += -DBUILD_ROBUST
endif
FPPFLAGS += $D$(COMPILER) $D$(UNAME)
CPPFLAGS += -D$(COMPILER) -D$(UNAME) -I$(INCLUDE_DIR)
# FPPFLAGS += $D$(F90_VENDOR) $D$(UNAME)
# CPPFLAGS += -D$(F90_VENDOR) -D$(UNAME) -I$(INCLUDE_DIR)
ifeq ($(PFUNIT_ABI),64)
FPPFLAGS += $DLONG_PTR
CPPFLAGS += -DLONG_PTR
endif
FFLAGS +=$I$(INCLUDE_DIR) $(MOD)$(SOURCE_DIR)
CFLAGS +=-I$(INCLUDE_DIR)
ifeq ($(DEBUG),YES)
FFLAGS += $(DEBUG_FLAGS)
endif
all: include/configuration.mk
$(MAKE) -C $(SOURCE_DIR) all
$(MAKE) -C $(TESTS_DIR) all
documentation:
$(DOXYGEN) documentation/doxygen.conf
documentation/pFUnit3-ReferenceManual.pdf: documentation
$(MAKE) -C documentation/latex all
mv -f documentation/latex/refman.pdf documentation/pFUnit3-ReferenceManual.pdf
clean: local-top1-clean local-top1-cleanExamples
local-top1-clean: local-top1-cleanExamples
$(MAKE) -C $(SOURCE_DIR) clean
$(MAKE) -C $(TESTS_DIR) clean
\rm -f include/configuration.mk test.xml
local-top1-cleanExamples:
\rm -f Examples/Simple/tests.xml
tools/clean Examples
distclean: local-top1-distclean
local-top1-distclean: local-top1-cleanExamples
$(MAKE) -C $(SOURCE_DIR) distclean
$(MAKE) -C $(TESTS_DIR) distclean
$(MAKE) -C $(DOC_DIR) distclean
\rm -f include/configuration.mk test.xml
tests: all
ifeq ($(USEMPI),YES)
$(MPIRUN) -np 4 ./tests/tests$(EXE_EXT)
else
./tests/tests$(EXE_EXT)
endif
develop:
cp -f $(TOP_DIR)/include/base-develop.mk $(TOP_DIR)/include/base.mk
install: libpfunit$(LIB_EXT)
ifndef INSTALL_DIR
$(error Must specify INSTALL_DIR. Example: make install INSTALL_DIR=SOME_PATH, \
where SOME_PATH is different than $(TOP_DIR))
else
ifeq ($(INSTALL_DIR),$(TOP_DIR))
$(error INSTALL_DIR cannot be the same as TOP_DIR)
endif
ifeq ($(INSTALL_DIR),.)
$(error INSTALL_DIR cannot be the same as TOP_DIR)
endif
@echo Installing pFUnit in $(INSTALL_DIR)
tools/install $(INSTALL_DIR)/lib source/lib*
tools/install $(INSTALL_DIR)/mod source/*.mod
tools/install $(INSTALL_DIR) include
mv -f $(INSTALL_DIR)/include/base-install.mk $(INSTALL_DIR)/include/base.mk
tools/install $(INSTALL_DIR) bin
@echo +++
@echo PFUNIT has been installed in $(INSTALL_DIR).
@echo For normal usage please ensure PFUNIT is set to $(INSTALL_DIR).
@echo For example, in bash: export PFUNIT=$(INSTALL_DIR)
endif
include/configuration.mk:
@echo "# include/configuration.mk generated automatically during build" \
> include/configuration.mk
@echo COMPILER ?= $(COMPILER) >> include/configuration.mk
@echo USEOPENMP ?= $(USEOPENMP) >> include/configuration.mk
@echo USEMPI ?= $(USEMPI) >> include/configuration.mk
@echo MAX_RANK ?= $(MAX_RANK) >> include/configuration.mk
@echo BUILDROBUST ?= $(BUILDROBUST) >> include/configuration.mk
@echo VERSION = \"`cat VERSION`\" >> include/configuration.mk
export UNAME
export OBJ_EXT
export EXE_EXT
export LIB_EXT
export AR
export RANLIB
export OUTPUT_FLAG
export F90
export F90_VENDOR
export FFLAGS
export FPPFLAGS
export CPP
export CFLAGS
export CPPFLAGS
export LDFLAGS
export SOURCE_DIR
export INCLUDE_DIR
export VPATH
export MPI
export USEMPI
export USEOPENMP
export MAX_RANK
export BUILDROBUST
export MPIF90
export LIBMPI
export COMPILER
export PYTHON
ifeq ($(DEBUG),YES)
$(warning Compilation configuration is as follows:)
$(warning UNAME: $(UNAME))
$(warning ARCH: $(ARCH))
$(warning F90 vendor: $(COMPILER))
$(warning F90 command: $(F90))
$(warning USE MPI: $(MPI))
$(warning ABI: $(PFUNIT_ABI))
$(warning File extensions:)
$(warning OBJ_EXT $(OBJ_EXT))
$(warning LIB_EXT $(LIB_EXT))
$(warning EXE_EXT $(EXE_EXT))
endif