-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
241 lines (199 loc) · 6.82 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
#####################################################################################
## ##
## Makefile for Thermochimica ##
## ##
## Base Makefile written by M. Rodriguez Rodriguez and M.H.A. Piro ##
## Modified S. Simunovic
## make - compile shared libraries ##
## make test - compile all tests ##
## make dailytest - compile application and unit tests that run daily ##
## make weeklytest - compile application and unit tests that run weekly ##
## make doc - compile dOxygen HTML and LaTex documents ##
## make docHTML - compile dOxygen HTML document only ##
## make doclatex - compile dOxygen LaTeX document only ##
## make clean - clean object files ##
## make cleandoc - clean dOxygen files ##
## make veryclean - clean object, executable, module and document files. ##
## ##
######################################################################################
## ===================
## COMPILER VARIABLES:
## ===================
AR = ar
FC = gfortran
CC = g++
FFPE_TRAPS ?= zero
FCFLAGS = -Wall -O2 -ffree-line-length-none -fno-automatic -fbounds-check -ffpe-trap=$(FFPE_TRAPS) -cpp -D"DATA_DIRECTORY='$(DATA_DIR)'"
CCFLAGS = -std=gnu++17
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
# links to lapack and blas libraries:
LDLOC = -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas -lgfortran
# link flags for linux users:
LDFLAGS = -O2 -fno-automatic -fbounds-check
endif
ifeq ($(UNAME_S),Darwin)
# link flags for mac users:
LDFLAGS = -O2 -framework Accelerate -fno-automatic -fbounds-check
endif
ifneq (,$(findstring NT,$(UNAME_S)))
LDLOC = -llapack -lblas -lgfortran
# link flags for Windows users:
LDFLAGS = -O2 -fno-automatic -fbounds-check
endif
## ====================
## DIRECTORY VARIABLES:
## ====================
MKDIR_P = mkdir -p
DOC_DIR = doc
TEX_DIR = $(DOC_DIR)/latex
BIN_DIR = bin
OBJ_DIR = obj
SRC_DIR = src
SRC_SDR = debug gem module parser postprocess reinit reset setup ctz api
EXE_DIR = $(SRC_DIR)/exec
TST_DIR = test
LIB_DIR = lib
DTST_DIR = $(TST_DIR)/daily
SHARED_DIR = $(SRC_DIR)
SHARED_DIR += $(addprefix $(SRC_DIR)/,$(SRC_SDR))
CURR_DIR = $(shell pwd)
DATA_DIR = $(CURR_DIR)/data/
VPATH = $(SHARED_DIR)
# Separate modules and non-modules
modfiles := $(shell find src -name "Module*.f90")
srcfiles := $(shell find src -iname "*.f90" -and -not -name "Module*")
##
OBJ_FILES = $(addprefix $(OBJ_DIR)/,$(patsubst %.f90, %.o, $(patsubst %.F90, %.o, $(notdir $(srcfiles)))))
## ========
## MODULES:
## ========
MODS_OBJ = $(patsubst %.f90, %.o, $(notdir $(modfiles)))
MODS_LNK = $(addprefix $(OBJ_DIR)/,$(MODS_OBJ))
## =================
## LIBRARIES:
## =================
TC_LIB = libthermochimica.a
SHARED_SRC = $(foreach dir,$(SHARED_DIR),$(notdir $(wildcard $(dir)/*.f90)))
SHARED_SRCF = $(foreach dir,$(SHARED_DIR),$(notdir $(wildcard $(dir)/*.F90)))
SHARED_OBJ = $(SHARED_SRC:.f90=.o)
SHARED_OBJ += $(SHARED_SRCF:.F90=.o)
SHARED_LNK = $(addprefix $(OBJ_DIR)/,$(SHARED_OBJ))
SHARED_LIB = $(OBJ_DIR)/$(TC_LIB)
## =================
## C interface library:
## =================
C_SRC = Thermochimica-c.C Thermochimica-cxx.C
C_OBJ = $(C_SRC:.C=.o)
C_LNK = $(addprefix $(OBJ_DIR)/,$(C_OBJ))
TC-C_LIB = libthermoc.a
C_LIB = $(OBJ_DIR)/$(TC-C_LIB)
## ============
## OLD EXECUTABLES:
## ============
EXEC_SRC = $(notdir $(wildcard $(TST_DIR)/*.F90))
EXEC_SRC += $(notdir $(wildcard $(EXE_DIR)/*.F90))
EXEC_OBJ = $(EXEC_SRC:.F90=.o)
EXEC_LNK = $(addprefix $(OBJ_DIR)/,$(EXEC_OBJ))
EXE_OBJ = $(basename $(EXEC_SRC))
EXE_BIN = $(addprefix $(BIN_DIR)/,$(EXE_OBJ))
## ============
## DAILY TESTS:
## ============
DTEST_SRC = $(notdir $(wildcard $(DTST_DIR)/*.F90))
DTEST_OBJ = $(DTEST_SRC:.F90=.o)
DTEST_LNK = $(addprefix $(OBJ_DIR)/,$(DTEST_OBJ))
DTST_OBJ = $(basename $(DTEST_SRC))
DTST_BIN = $(addprefix $(BIN_DIR)/,$(DTST_OBJ))
## =======
## COMPILE
## =======
all: directories $(MODS_LNK) $(SHARED_LNK) $(SHARED_LIB) $(EXEC_LNK) $(EXE_BIN) $(C_LNK) $(C_LIB)
directories: ${OBJ_DIR} ${BIN_DIR}
${OBJ_DIR}:
${MKDIR_P} ${OBJ_DIR}
${BIN_DIR}:
${MKDIR_P} ${BIN_DIR}
# Enforce module dependency rules
$(OBJ_FILES): $(srcfiles) $(MODS_LNK)
$(EXEC_LNK) $(DTST_LNK): $(MODS_LNK)
$(OBJ_DIR)/%.o: %.f90 $(OBJ_DIR)
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: %.F90 $(OBJ_DIR)
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(TST_DIR)/%.F90 $(OBJ_DIR)
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(EXE_DIR)/%.F90 $(OBJ_DIR)
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) -c $< -o $@
$(SHARED_LIB): $(SHARED_LNK)
$(AR) rcs $@ $^
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CCFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.C
$(CC) $(CCFLAGS) -c $< -o $@
$(C_LIB): $(C_LNK)
$(AR) rcs $@ $^
$(BIN_DIR)/%: $(OBJ_DIR)/%.o $(SHARED_LNK)
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$* $< $(SHARED_LNK) $(LDLOC)
.PHONY: clean veryclean test doc cleandoc directories
## =====
## CLEAN
## =====
clean:
rm -f $(OBJ_DIR)/*
find bin -name \*.dSYM -exec rm -rf {} \; > /dev/null 2>&1 | :
rm -f $(BIN_DIR)/*
cleanexternal:
rm -f $(SRC_DIR)/*.lo
rm -f $(SRC_DIR)/*.lo.d
rm -f $(SRC_DIR)/.libs/*
rm -f $(SRC_DIR)/*.mod
rm -f $(LIB_DIR)/*
rm -f $(LIB_DIR)/.libs/*
veryclean: clean cleandoc cleanexternal
rm -fr $(OBJ_DIR)/*
rm -fr $(BIN_DIR)/*
rm -f *.mod
## =======
## INSTALL
## =======
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
install: $(SHARED_LIB)
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(SHARED_LIB) $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/
install -m 644 $(OBJ_DIR)/*.mod $(DESTDIR)$(PREFIX)/include/
c-thermo: $(C_LIB)
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(C_LIB) $(DESTDIR)$(PREFIX)/lib/
libraries: install c-thermo
## =============
## DOCUMENTATION
## =============
doc: dochtml doclatex
dochtml:
doxygen Doxyfile
doclatex: dochtml
cd $(TEX_DIR); make
doctest:
cd $(TST_DIR); doxygen Doxyfile; cd $(TEX_DIR); make; cd ../..; mv $(DOC_DIR) ../$(DOC_DIR)/$(TST_DIR)
cleandoc:
rm -r -f $(DOC_DIR)/html; rm -r -f $(TEX_DIR); rm -r -f $(TST_DIR)/$(DOC_DIR)/html; rm -r -f $(TST_DIR)/$(TEX_DIR); rm -r -f $(DOC_DIR)/$(TST_DIR)
## ===========
## DAILY TESTS
## ===========
dailytest: $(DTEST_LNK) $(SHARED_LNK) $(MODS_LNK) $(DTST_BIN)
$(OBJ_DIR)/%.o: $(DTST_DIR)/%.F90
$(FC) -I$(OBJ_DIR) -J$(OBJ_DIR) $(FCFLAGS) -c $< -o $@
## ===========
## ALL TESTS:
## ===========
test: all dailytest
## ===========
## DEBUG:
## ===========
setdebug:
$(eval FCFLAGS = -Wall -O0 -g -fno-automatic -fbounds-check -ffpe-trap=$(FFPE_TRAPS) -D"DATA_DIRECTORY='$(DATA_DIR)'")
debug: setdebug all dailytest