forked from atoms-ufrj/EmDee
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
227 lines (163 loc) · 8.32 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
# Define DEBUG or FAST mode:
# Build the "fast" version with: `make` or `make DEBUG=0`
# Build the "debug" version with: `make DEBUG=1`
DEBUG ?= 0
# Installation prefix:
PREFIX ?= /usr/local
# Compilers and their basic options:
FORT ?= gfortran
CC ?= gcc
BASIC_F_OPTS = -march=native -m64 -fPIC -fopenmp -cpp -fmax-errors=1
BASIC_C_OPTS = -march=native -m64 -fPIC -fopenmp -cpp -fmax-errors=1
# Warning-related options:
BASIC_F_OPTS += -Wall -Wno-maybe-uninitialized
BASIC_C_OPTS += -Wall -Wno-maybe-uninitialized
# Option FAST (default):
FAST_F_OPTS = -Ofast
FAST_C_OPTS = -Ofast
# Option DEBUG:
DEBUG_F_OPTS = --coverage -g -Og -fcheck=all -Ddebug
DEBUG_C_OPTS = --coverage -g -Og -fstack-check -fsanitize=null -fbounds-check -Ddebug
# Checks chosen option:
ifeq ($(DEBUG), 1)
F_OPTS = $(BASIC_F_OPTS) $(DEBUG_F_OPTS)
C_OPTS = $(BASIC_C_OPTS) $(DEBUG_C_OPTS)
else
F_OPTS = $(BASIC_F_OPTS) $(FAST_F_OPTS)
C_OPTS = $(BASIC_C_OPTS) $(FAST_C_OPTS)
endif
LN_INC_OPT = -I$(INCDIR)
LN_SO_OPT = -Wl,-rpath,'$$ORIGIN/../lib'
LN_OPTS = $(LN_INC_OPT) $(LN_SO_OPT)
SRCDIR = ./src
OBJDIR = $(SRCDIR)/obj
BINDIR = ./bin
LIBDIR = ./lib
INCDIR = ./include
TSTDIR = ./test
LIBS = -lgfortran -lm -lgomp
EMDEELIB = -L$(LIBDIR) -lemdee
obj = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(1)))
src = $(addprefix $(SRCDIR)/, $(addsuffix .f90, $(1)))
# Force-field models (from source files starting with pair_, coul_, bond_, angle_, and dihedral_):
MODELTERMS = pair coul bond angle dihedral
PAIRMODELS = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/pair_*.f90))
COULMODELS = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/coul_*.f90))
BONDMODELS = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/bond_*.f90))
ANGLEMODELS = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/angle_*.f90))
DIHEDMODELS = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/dihedral_*.f90))
ALLMODELS = $(shell bash $(SRCDIR)/make_pair_list.sh $(PAIRMODELS)) \
$(COULMODELS) $(BONDMODELS) $(ANGLEMODELS) $(DIHEDMODELS)
KSPACE = $(patsubst $(SRCDIR)/%.f90,%,$(wildcard $(SRCDIR)/kspace_*.f90))
OBJECTS = $(call obj,EmDeeCode neighbor_lists EmDeeData ArBee math structs models \
$(ALLMODELS) $(KSPACE) $(addprefix modelClass_,$(MODELTERMS) kspace) \
modelClass lists global)
COMPUTES = $(addprefix compute_,$(MODELTERMS))
ENERGYCOMPUTES = $(addprefix energy_compute_,pair coul)
VIRIALCOMPUTES = $(addprefix virial_compute_,pair coul)
TESTS = $(patsubst %.f90,%,$(wildcard $(TSTDIR)/*.f90))
.PHONY: all test clean install uninstall lib include
.DEFAULT_GOAL := all
# Phony targets:
all: lib include $(TSTDIR)/testfortran
# DELETE $(TSTDIR)/testfortran above
test: $(addprefix $(BINDIR)/,testc testjulia) $(TESTS)
cd $(TSTDIR) && bash run_tests.sh
clean:
rm -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(INCDIR)
rm -rf $(call src,$(COMPUTES) $(ENERGYCOMPUTES) $(VIRIALCOMPUTES) models)
rm -rf $(TESTS) *.gcda *.gcno
install:
cp $(LIBDIR)/libemdee.* $(PREFIX)/lib/
cp $(INCDIR)/*.* $(PREFIX)/include/
ldconfig
uninstall:
rm -f $(PREFIX)/lib/libemdee.so
rm -f $(addprefix $(PREFIX)/include/,emdee.h emdee.f03 libemdee.jl)
ldconfig
lib: $(LIBDIR)/libemdee.so
include: $(INCDIR)/emdee.f03 $(INCDIR)/emdee.h $(INCDIR)/libemdee.jl
# Executables:
$(TSTDIR)/%: $(TSTDIR)/%.f90 $(INCDIR)/emdee.f03 $(TSTDIR)/common/contained.f90 $(OBJDIR)/mConfig.o
$(FORT) $(F_OPTS) -o $@ $(LN_OPTS) -J$(OBJDIR) $< $(OBJDIR)/mConfig.o $(EMDEELIB)
$(BINDIR)/testc: $(SRCDIR)/testc.c $(INCDIR)/emdee.h $(LIBDIR)/libemdee.so
mkdir -p $(BINDIR)
$(CC) $(C_OPTS) -o $@ $(LN_OPTS) $< $(EMDEELIB) -lm
$(BINDIR)/testjulia: $(SRCDIR)/testjulia.jl $(INCDIR)/libemdee.jl $(LIBDIR)/libemdee.so
mkdir -p $(BINDIR)
(echo '#!/usr/bin/env julia' && echo 'DIR="${CURDIR}"' && cat $<) > $@
chmod +x $@
$(OBJDIR)/mConfig.o: $(TSTDIR)/common/mConfig.f90 $(LIBDIR)/libemdee.so
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
# Shared library and includes:
$(LIBDIR)/libemdee.so: $(OBJECTS)
mkdir -p $(LIBDIR)
$(FORT) $(F_OPTS) -shared -fPIC -o $@ $(OBJECTS) $(LIBS)
$(INCDIR)/emdee.f03: $(SRCDIR)/emdee_header.f03 $(SRCDIR)/make_f_header.sh
mkdir -p $(INCDIR) $(LIBDIR)
bash $(SRCDIR)/make_f_header.sh $(ALLMODELS) $(KSPACE) > $(INCDIR)/emdee.f03
$(INCDIR)/emdee.h: $(SRCDIR)/emdee_header.h $(SRCDIR)/make_c_header.sh
mkdir -p $(INCDIR) $(LIBDIR)
bash $(SRCDIR)/make_c_header.sh $(ALLMODELS) $(KSPACE) > $(INCDIR)/emdee.h
$(INCDIR)/libemdee.jl: $(SRCDIR)/emdee_header.jl $(SRCDIR)/make_j_header.sh
mkdir -p $(INCDIR) $(LIBDIR)
bash $(SRCDIR)/make_j_header.sh $(ALLMODELS) $(KSPACE) > $(INCDIR)/libemdee.jl
# Object files:
$(OBJDIR)/EmDeeCode.o: $(call src,EmDeeCode) \
$(call src,$(COMPUTES) $(ENERGYCOMPUTES) $(VIRIALCOMPUTES)) \
$(call obj,neighbor_lists EmDeeData ArBee structs models lists global)
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/neighbor_lists.o: $(SRCDIR)/neighbor_lists.f90 $(OBJDIR)/EmDeeData.o
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/EmDeeData.o: $(call src,EmDeeData compute) \
$(call obj,ArBee structs models lists math global)
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/ArBee.o: $(SRCDIR)/ArBee.f90 $(call obj,math global)
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/structs.o: $(SRCDIR)/structs.f90 $(OBJDIR)/models.o
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(SRCDIR)/compute_pair.f90: $(call src,$(PAIRMODELS)) $(SRCDIR)/make_compute.sh
bash $(SRCDIR)/make_compute.sh pair $(PAIRMODELS) > $@
$(SRCDIR)/compute_coul.f90: $(call src,$(COULMODELS)) $(SRCDIR)/make_compute.sh
bash $(SRCDIR)/make_compute.sh coul $(COULMODELS) > $@
$(SRCDIR)/compute_bond.f90: $(call src,$(BONDMODELS)) $(SRCDIR)/make_compute.sh
bash $(SRCDIR)/make_compute.sh bond $(BONDMODELS) > $@
$(SRCDIR)/compute_angle.f90: $(call src,$(ANGLEMODELS)) $(SRCDIR)/make_compute.sh
bash $(SRCDIR)/make_compute.sh angle $(ANGLEMODELS) > $@
$(SRCDIR)/compute_dihedral.f90: $(call src,$(DIHEDMODELS)) $(SRCDIR)/make_compute.sh
bash $(SRCDIR)/make_compute.sh dihedral $(DIHEDMODELS) > $@
$(SRCDIR)/energy_compute_pair.f90: $(call src,$(PAIRMODELS)) $(SRCDIR)/make_energy_compute.sh
bash $(SRCDIR)/make_energy_compute.sh pair $(PAIRMODELS) > $@
$(SRCDIR)/energy_compute_coul.f90: $(call src,$(COULMODELS)) $(SRCDIR)/make_energy_compute.sh
bash $(SRCDIR)/make_energy_compute.sh coul $(COULMODELS) > $@
$(SRCDIR)/virial_compute_pair.f90: $(call src,$(PAIRMODELS)) $(SRCDIR)/make_virial_compute.sh
bash $(SRCDIR)/make_virial_compute.sh pair $(PAIRMODELS) > $@
$(SRCDIR)/virial_compute_coul.f90: $(call src,$(COULMODELS)) $(SRCDIR)/make_virial_compute.sh
bash $(SRCDIR)/make_virial_compute.sh coul $(COULMODELS) > $@
$(OBJDIR)/models.o: $(call obj,$(ALLMODELS) $(addprefix modelClass_,$(MODELTERMS))) \
$(call obj,$(KSPACE) modelClass_kspace) $(SRCDIR)/make_models_module.sh
bash $(SRCDIR)/make_models_module.sh $(ALLMODELS) $(KSPACE) > $(SRCDIR)/models.f90
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $(SRCDIR)/models.f90
$(OBJDIR)/pair_%.o: $(SRCDIR)/pair_%.f90 $(OBJDIR)/modelClass_pair.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/coul_%.o: $(SRCDIR)/coul_%.f90 $(OBJDIR)/modelClass_coul.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/bond_%.o: $(SRCDIR)/bond_%.f90 $(OBJDIR)/modelClass_bond.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/angle_%.o: $(SRCDIR)/angle_%.f90 $(OBJDIR)/modelClass_angle.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/dihedral_%.o: $(SRCDIR)/dihedral_%.f90 $(OBJDIR)/modelClass_dihedral.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/kspace_%.o: $(SRCDIR)/kspace_%.f90 $(OBJDIR)/modelClass_kspace.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/modelClass_%.o: $(SRCDIR)/modelClass_%.f90 $(OBJDIR)/modelClass.o
$(FORT) $(F_OPTS) -Wno-unused-dummy-argument -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/modelClass.o: $(SRCDIR)/modelClass.f90 $(call obj,lists math)
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/lists.o: $(SRCDIR)/lists.f90 $(OBJDIR)/global.o
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/math.o: $(SRCDIR)/math.f90 $(OBJDIR)/global.o
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<
$(OBJDIR)/global.o: $(SRCDIR)/global.f90
mkdir -p $(OBJDIR)
$(FORT) $(F_OPTS) -J$(OBJDIR) -c -o $@ $<