-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
188 lines (146 loc) · 4.83 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
#
# Copyright 2016 Christopher MacMackin <cmacmackin@gmail.com>
#
# This program 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.
#
# This program 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Directories
SDIR := ./src
FDIR := ./fsrc
TDIR := ./tests
MDIR := ./mod
ODIR := ./objs
PFUNIT = $(HOME)/Code/pfunit-$(F90)
# Output
EXEC :=
TEXEC := tests.x
LIB := libfactual.a
PREFIX := $(HOME)/.local
LIBDIR := $(PREFIX)/lib
INCDIR := $(PREFIX)/include
BINDIR := $(PREFIX)/bin
# Include paths internal to project
PROJECT_INCDIRS := $(FMDIR) $(TDIR)
# The compiler
VENDOR ?= GNU
VENDOR_ = $(shell echo $(VENDOR) | tr A-Z a-z)
ifeq ($(VENDOR_),intel)
F90 := ifort
#FCFLAGS := -O0 -g -module $(MDIR) -traceback -assume realloc_lhs
#LDFLAGS := -O0 -g -traceback
FCFLAGS := -Ofast -module $(MDIR) -assume realloc_lhs
LDFLAGS := -Ofast
COVFLAGS :=
else
F90 := gfortran-6
#FCFLAGS := -O0 -g -fcheck=all -J$(MDIR)
#LDFLAGS := -O0 -g
#COVFLAGS := -fprofile-arcs -ftest-coverage
FCFLAGS := -O3 -J$(MDIR)
LDFLAGS := -O3
COVFLAGS :=
endif
FPP := fypp
FPP_FLAGS := -DDEBUG -n -DPOOL_SIZE=100
# Include paths
FCFLAGS += $(PROJECT_INCDIRS:%=-I%) -I$(INCDIR) -I/usr/include -I$(PFUNIT)/mod
# Libraries for use at link-time
LIBS := -L$(LIBDIR) -lfftw3 -lhdf5hl_fortran -lhdf5_fortran
LDFLAGS += $(LIBS)
# A regular expression for names of modules provided by external libraries
# and which won't be contained in the module directory of this codebase
EXTERNAL_MODS := ^iso_(fortran_env|c_binding)|ieee_(exceptions|arithmetic|features)|openacc|omp_lib(_kinds)?|mpi|pfunit_mod|h5lt|hdf5$$
# Extensions of Fortran files, case insensitive
F_EXT := f for f90 f95 f03 f08 f15
# Temporary work variables
_F_EXT := $(F_EXT) $(shell echo $(F_EXT) | tr a-z A-Z)
null :=
space := $(null) $(null)
EXT_PATTERN_GREP := '.*\.\($(subst $(space),\|,$(_F_EXT))\)'
EXT_PATTERN_SED := 's/([^ ]*)\.($(subst $(space),|,$(_F_EXT)))/\1.o/g;'
FPP_PATTERN_GREP := '.*\.\(fpp\|FPP\)'
FPP_PATTERN_SED := 's/([^ ]*)\.(fpp|FPP)/\1.o/g;'
# Objects to compile
OBJS := $(shell find $(SDIR) -iregex $(EXT_PATTERN_GREP) | sed -r $(EXT_PATTERN_SED))
OBJS += $(shell find $(SDIR) -iregex $(FPP_PATTERN_GREP) | sed -r $(FPP_PATTERN_SED))
TOBJS := $(patsubst %.pf,%.o,$(wildcard $(TDIR)/*.pf))
#.PRECIOUS: %.F90
# "make" builds all
all: all_objects tests
all_objects: $(OBJS)
exec: $(EXEC)
$(EXEC): $(OBJS)
$(F90) $^ $(LDFLAGS) -o $@
install_exec: exec
cp $(EXEC) $(BINDIR)
tests: $(TEXEC)
./$(TEXEC)
$(TEXEC): $(TOBJS) $(LIB)
$(F90) -I$(PFUNIT)/include $(PFUNIT)/include/driver.F90 $(COVFLAGS) \
$(FCFLAGS) $^ $(LIBS) -L$(PFUNIT)/lib -lpfunit -o $@
lib: $(LIB)
$(LIB): $(OBJS)
$(AR) rcs $@ $^
install_lib: lib
cp $(LIB) $(LIBDIR)
cp $(MDIR)/*.mod $(INCDIR)
ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),doc)
else
-include $(OBJS:.o=.d) $(TOBJS:.o=.d)
endif
%.d: %.pf get_deps
./get_deps $< $$\(MDIR\) "$(EXTERNAL_MODS)" $(PROJECT_INCDIRS) > $@
%.d: %.fpp get_deps
./get_deps $< \$$\(MDIR\) "$(EXTERNAL_MODS)" $(PROJECT_INCDIRS) > $@
%.d: %.FPP get_deps
./get_deps $< \$$\(MDIR\) "$(EXTERNAL_MODS)" $(PROJECT_INCDIRS) > $@
# General rule for building Fortran files, where $(1) is the file extension
define fortran_rule
%.o: %.$(1) $(FMOD) | $(MDIR)
$$(F90) $$(COVFLAGS) $$(FCFLAGS) -c $$< -o $$@
%.d: %.$(1) get_deps
./get_deps $$< \$$$$\(MDIR\) "$$(EXTERNAL_MODS)" $$(PROJECT_INCDIRS) > $$@
endef
# Register compilation rules for each Fortran extension
$(foreach EXT,$(_F_EXT),$(eval $(call fortran_rule,$(EXT))))
%.F90: %.pf
$(PFUNIT)/bin/pFUnitParser.py $< $@
%.F90: %.fpp
$(FPP) $(FPP_FLAGS) $< $@
%.F90: %.FPP
$(FPP) $(FPP_FLAGS) $< $@
$(MDIR):
@mkdir -p $@
clean: clean_obj clean_mod clean_deps clean_backups
clean_obj:
@echo Deleting all object files
@/bin/rm -rf $(OBJS) $(TOBJS)
clean_mod:
@echo Deleting all module files
@/bin/rm -rf $(MDIR)
clean_deps:
@echo Deleting all dependency files
@/bin/rm -rf $(OBJS:.o=.d) $(TOBJS:.o=.d)
clean_exec:
@echo Deleting executable file
@/bin/rm -rf $(EXEC)
clean_backups:
@echo Deleting emacs backup files
@/bin/rm -rf $(shell find '.' -name '*~') $(shell find '.' -name '\#*\#')
doc: documentation.md
ford $<
.PHONEY: all all_objects exec install_exec tests lib install_lib clean \
clean_obj clean_mod clean_backups doc