-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmakefile
271 lines (198 loc) · 11.8 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
# Copyright (c) 2016, 2017 Robert Rüger
# Copyright (c) 2018 Software for Chemistry & Materials BV
#
# This file is part of of the Fortran Template Library.
#
# The Fortran Template 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, either version 3 of the License, or
# (at your option) any later version.
#
# The Fortran Template 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 the Fortran Template Library. If not, see <http://www.gnu.org/licenses/>.
# disable default implicit rules
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
PLATFORM ?= gnu
BUILD ?= debug
BUILDDIR = build.$(PLATFORM).$(BUILD)
PREFIX ?= /usr/local
LIBDIR ?= lib
INCLUDES = -Isrc -Itests
DEFINES =
ifeq ($(PLATFORM), gnu)
FC = gfortran
FCFLAGS += -std=f2008 -fall-intrinsics -ffree-line-length-none -Wall -Wextra -Wpedantic -Wno-target-lifetime -Wno-compare-reals -J$(BUILDDIR)
SOFLAGS = -fPIC
SOLDFLAGS = -shared -Wl,-soname=libftl.so.1
CXX = g++
CXXFLAGS ?= -Ofast -march=native
CXXFLAGS += -std=c++11
SUPPRESSIONS = --suppressions=gfortran.supp
else ifeq ($(PLATFORM), intel)
FC = ifort
SOFLAGS = -fPIC
SOLDFLAGS = -shared -Wl,-soname,libftl.so.1
FCFLAGS += -stand f08 -warn -diag-disable=5268 -module $(BUILDDIR)
CXX = icc
CXXFLAGS ?= -fast -xHost
CXXFLAGS += -std=c++11
SUPPRESSIONS =
else ifeq ($(PLATFORM), nag)
FC ?= nagfor
FCFLAGS += -fpp -colour -I$(BUILDDIR) -mdir $(BUILDDIR)
SOFLAGS = -PIC
SOLDFLAGS = -Wl,-shared -Wl,-soname=libftl.so.1
CXX = g++
CXXFLAGS ?= -Ofast -march=native
CXXFLAGS += -std=c++11
SUPPRESSIONS =
else
$(error unrecognized PLATFORM)
endif
USE_PCRE ?= true
ifeq ($(USE_PCRE), true)
DEFINES += -DUSE_PCRE
LDFLAGS = -lpcreposix -lpcre
endif
ifeq ($(PLATFORM)$(BUILD), gnudebug)
FCFLAGS += -g -Og -fcheck=bounds,do,mem,pointer,recursion
else ifeq ($(PLATFORM)$(BUILD), inteldebug)
FCFLAGS += -g -O0 -check all -debug all -traceback
else ifeq ($(PLATFORM)$(BUILD), nagdebug)
FCFLAGS += -g
else ifeq ($(PLATFORM)$(BUILD), gnurelease)
FCFLAGS += -O2 -march=native -flto
else ifeq ($(PLATFORM)$(BUILD), intelrelease)
FCFLAGS += -O3 -ipo -xHost
else ifeq ($(PLATFORM)$(BUILD), nagrelease)
FCFLAGS += -O
else ifneq ($(BUILD), custom)
$(error unrecognized BUILD (valid values: debug, release, custom))
endif
# Make commands:
libftl: $(BUILDDIR)/libftl.so.1
install: libftl
mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR)
cp $(BUILDDIR)/libftl.so.1 $(DESTDIR)$(PREFIX)/$(LIBDIR)/
ln -s libftl.so.1 $(DESTDIR)$(PREFIX)/$(LIBDIR)/libftl.so
mkdir -p $(DESTDIR)$(PREFIX)/include/ftl
cp $(BUILDDIR)/ftlkindsmodule.mod $(DESTDIR)$(PREFIX)/include/ftl
cp $(BUILDDIR)/ftlhashmodule.mod $(DESTDIR)$(PREFIX)/include/ftl
cp $(BUILDDIR)/ftlregexmodule.mod $(DESTDIR)$(PREFIX)/include/ftl
cp $(BUILDDIR)/ftlstringmodule.mod $(DESTDIR)$(PREFIX)/include/ftl
cp src/*.F90_template $(DESTDIR)$(PREFIX)/include/ftl
cp src/ftlMacros.inc $(DESTDIR)$(PREFIX)/include/ftl
test: $(BUILDDIR)/tests
./$(BUILDDIR)/tests
memcheck: $(BUILDDIR)/tests
valgrind --leak-check=yes $(SUPPRESSIONS) ./$(BUILDDIR)/tests
perftest: $(BUILDDIR)/perftest_sortDynArrayInt $(BUILDDIR)/perftest_sortDynArrayInt_ref $(BUILDDIR)/perftest_countDistinctWords
./$(BUILDDIR)/perftest_countDistinctWords
./perftests/countDistinctWords.py
./$(BUILDDIR)/perftest_sortDynArrayInt
./$(BUILDDIR)/perftest_sortDynArrayInt_ref
$(BUILDDIR):
mkdir $(BUILDDIR)
clean:
rm -rf $(BUILDDIR)
cleanall:
rm -rf build.* src/configure_ftlRegex.inc
# Shared library of non-template components:
$(BUILDDIR)/libftl.so.1: $(BUILDDIR)/ftlKinds.o $(BUILDDIR)/ftlString.o $(BUILDDIR)/ftlHash.o $(BUILDDIR)/ftlRegex.o
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $^ $(LDFLAGS) $(SOLDFLAGS) -o $@
# Unit tests:
$(BUILDDIR)/tests: tests/tests.F90 $(BUILDDIR)/ftlTestTools.o $(BUILDDIR)/ftlArrayTests.o $(BUILDDIR)/ftlDynArrayTests.o $(BUILDDIR)/ftlListTests.o $(BUILDDIR)/ftlHashMapTests.o $(BUILDDIR)/ftlHashSetTests.o $(BUILDDIR)/ftlAlgorithmsTests.o $(BUILDDIR)/ftlSharedPtrTests.o $(BUILDDIR)/ftlStringTests.o $(BUILDDIR)/ftlRegexTests.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $< $(BUILDDIR)/*.o $(LDFLAGS) -o $@
$(BUILDDIR)/ftlTestTools.o: tests/ftlTestTools.F90 tests/ftlTestTools.inc | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlArrayTests.o: tests/ftlArrayTests.F90 $(BUILDDIR)/ftlArrayIntAlgorithms.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayTests.o: tests/ftlDynArrayTests.F90 $(BUILDDIR)/ftlDynArrayInt.o $(BUILDDIR)/ftlDynArrayPoint2D.o $(BUILDDIR)/ftlDynArrayLeaky.o $(BUILDDIR)/ftlDynArrayMovableLeaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlListTests.o: tests/ftlListTests.F90 $(BUILDDIR)/ftlListInt.o $(BUILDDIR)/ftlListLeaky.o $(BUILDDIR)/ftlListMovableLeaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashMapTests.o: tests/ftlHashMapTests.F90 $(BUILDDIR)/ftlHashMapStrInt.o $(BUILDDIR)/ftlHashMapStringInt.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashSetTests.o: tests/ftlHashSetTests.F90 $(BUILDDIR)/ftlHashSetInt.o $(BUILDDIR)/ftlHashSetString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlAlgorithmsTests.o: tests/ftlAlgorithmsTests.F90 $(BUILDDIR)/ftlArrayIntAlgorithms.o $(BUILDDIR)/ftlDynArrayIntAlgorithms.o $(BUILDDIR)/ftlDynArrayPoint2DAlgorithms.o $(BUILDDIR)/ftlListIntAlgorithms.o $(BUILDDIR)/ftlStringAlgorithms.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlSharedPtrTests.o: tests/ftlSharedPtrTests.F90 $(BUILDDIR)/ftlSharedPtrInt.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlStringTests.o: tests/ftlStringTests.F90 $(BUILDDIR)/ftlString.o $(BUILDDIR)/ftlDynArrayString.o $(BUILDDIR)/Animals.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlRegexTests.o: tests/ftlRegexTests.F90 $(BUILDDIR)/ftlRegex.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
# Individual performance tests:
$(BUILDDIR)/perftest_sortDynArrayInt: perftests/sortDynArrayInt.F90 $(BUILDDIR)/ftlTestTools.o $(BUILDDIR)/ftlDynArrayIntAlgorithms.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $< $(BUILDDIR)/*.o $(LDFLAGS) -o $@
$(BUILDDIR)/perftest_sortDynArrayInt_ref: perftests/sortDynArrayInt.cpp | $(BUILDDIR)
$(CXX) $(CXXFLAGS) $(DEFINES) $< -o $@
$(BUILDDIR)/perftest_countDistinctWords: perftests/countDistinctWords.F90 $(BUILDDIR)/ftlString.o $(BUILDDIR)/ftlHashMapStringInt.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $< $(BUILDDIR)/*.o $(LDFLAGS) -o $@
# Container instantiations:
$(BUILDDIR)/ftlDynArrayInt.o: instantiations/ftlDynArrayInt.F90 src/ftlDynArray.F90_template | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayPoint2D.o: instantiations/ftlDynArrayPoint2D.F90 src/ftlDynArray.F90_template $(BUILDDIR)/Point2D.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayLeaky.o: instantiations/ftlDynArrayLeaky.F90 src/ftlDynArray.F90_template $(BUILDDIR)/Leaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayMovableLeaky.o: instantiations/ftlDynArrayMovableLeaky.F90 src/ftlDynArray.F90_template $(BUILDDIR)/Leaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayString.o: src/instantiations/ftlDynArrayString.F90 src/ftlDynArray.F90_template $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlListInt.o: instantiations/ftlListInt.F90 src/ftlList.F90_template | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlListLeaky.o: instantiations/ftlListLeaky.F90 src/ftlList.F90_template $(BUILDDIR)/Leaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlListMovableLeaky.o: instantiations/ftlListMovableLeaky.F90 src/ftlList.F90_template $(BUILDDIR)/Leaky.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashMapStrInt.o: instantiations/ftlHashMapStrInt.F90 src/ftlHashMap.F90_template $(BUILDDIR)/ftlKinds.o $(BUILDDIR)/ftlHash.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashMapStringInt.o: instantiations/ftlHashMapStringInt.F90 src/ftlHashMap.F90_template $(BUILDDIR)/ftlKinds.o $(BUILDDIR)/ftlHash.o $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashSetInt.o: instantiations/ftlHashSetInt.F90 src/ftlHashSet.F90_template $(BUILDDIR)/ftlKinds.o $(BUILDDIR)/ftlHash.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlHashSetString.o: instantiations/ftlHashSetString.F90 src/ftlHashSet.F90_template $(BUILDDIR)/ftlKinds.o $(BUILDDIR)/ftlHash.o $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
# ftlAlgorithms instantiations:
$(BUILDDIR)/ftlArrayIntAlgorithms.o: instantiations/ftlArrayIntAlgorithms.F90 src/ftlArray.F90_template src/ftlAlgorithms.F90_template | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayIntAlgorithms.o: instantiations/ftlDynArrayIntAlgorithms.F90 src/ftlAlgorithms.F90_template $(BUILDDIR)/ftlDynArrayInt.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlDynArrayPoint2DAlgorithms.o: instantiations/ftlDynArrayPoint2DAlgorithms.F90 src/ftlAlgorithms.F90_template $(BUILDDIR)/ftlDynArrayPoint2D.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlListIntAlgorithms.o: instantiations/ftlListIntAlgorithms.F90 src/ftlAlgorithms.F90_template $(BUILDDIR)/ftlListInt.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/ftlStringAlgorithms.o: src/instantiations/ftlStringAlgorithms.F90 src/ftlAlgorithms.F90_template $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
# ftlSharedPtr instantiations:
$(BUILDDIR)/ftlSharedPtrInt.o: instantiations/ftlSharedPtrInt.F90 src/ftlSharedPtr.F90_template | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
# Non-template FTL modules:
#
$(BUILDDIR)/ftlKinds.o: src/ftlKinds.F90 | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $(SOFLAGS) -c $< -o $@
$(BUILDDIR)/ftlHash.o: src/ftlHash.F90 $(BUILDDIR)/ftlKinds.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $(SOFLAGS) -c $< -o $@
$(BUILDDIR)/ftlString.o: src/ftlString.F90 $(BUILDDIR)/ftlHash.o $(BUILDDIR)/ftlKinds.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $(SOFLAGS) -c $< -o $@
$(BUILDDIR)/ftlRegex.o: src/ftlRegex.F90 src/configure_ftlRegex.inc $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) $(SOFLAGS) -c $< -o $@
src/configure_ftlRegex.inc: configure/configure_ftlRegex.c
$(CXX) $(CXXFLAGS) $(DEFINES) configure/configure_ftlRegex.c -o configure/configure_ftlRegex
./configure/configure_ftlRegex | tee src/configure_ftlRegex.inc
rm configure/configure_ftlRegex
# Example derived types:
$(BUILDDIR)/Point2D.o: instantiations/derived_types/Point2D.F90 | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/Leaky.o: instantiations/derived_types/Leaky.F90 | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
$(BUILDDIR)/Animals.o: instantiations/derived_types/Animals.F90 $(BUILDDIR)/ftlString.o | $(BUILDDIR)
$(FC) $(FCFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@