-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkhelper.mk.in
254 lines (207 loc) · 8.78 KB
/
mkhelper.mk.in
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
# Path to the root source directory:
srcdir:= @srcdir@
# Relative paths to the directories with the source files:
subdirs:= src
# Relative paths to the directories of the bundled packages:
bundled_ready_config_subdirs:= @bundled_ready_config_subdirs@
bundled_delayed_config_subdirs:= @bundled_delayed_config_subdirs@
bundled_ready_cmake_subdirs:= @bundled_ready_cmake_subdirs@
bundled_delayed_cmake_subdirs:= @bundled_delayed_cmake_subdirs@
bundled_subdirs:= \
$(bundled_ready_config_subdirs) \
$(bundled_delayed_config_subdirs) \
$(bundled_ready_cmake_subdirs) \
$(bundled_delayed_cmake_subdirs)
# Path to the directory with the Fortran module files:
moddir:= mod
# Paths to the installation directories:
prefix= @prefix@
exec_prefix= @exec_prefix@
# Compilers and utilities:
AR= @AR@
CMAKE= @CMAKE@
DEPGEN= ${PYTHON} $(srcdir)/mkhelper/depgen.py
DEPLIST= ${PYTHON} $(srcdir)/mkhelper/deplist.py
FC= @FC@
INSTALL= @INSTALL@
INSTALL_DATA= @INSTALL_DATA@
MODCMP= ${PYTHON} $(srcdir)/mkhelper/fortmodcmp.py
PYTHON= @PYTHON@
SHELL= @SHELL@
# Fortran compiler flags:
FCFLAGS= @FCFLAGS@
makefile_FCFLAGS= @FC_MOD_IN@$(moddir) @FC_MOD_OUT@$(moddir) @FC_INC_FLAG@$(srcdir)/src/include @FC_INC_FLAG_PP_f90@$(srcdir)/src/include @config_FCFLAGS@ @BUNDLED_FCFLAGS@ @NETCDF_FCFLAGS@
# Archiver flags:
ARFLAGS= @ARFLAGS@
# Linker flags and libraries:
BUNDLED_LIBFILES= @BUNDLED_LIBFILES@
LDFLAGS= @LDFLAGS@
LIBS= @LIBS@
makefile_LIBS= @NETCDF_FCLIBS@
# Dependency generator flags:
DEPGEN_FCFLAGS= @DEPGEN_FCFLAGS@
DEPGEN_args= @depgen.config
DEPLIST_args= @deplist.config
# Silent rule prefixes:
V= @DEFAULT_VERBOSITY@
ifeq ($(V), 0)
silent_AR= @echo " AR " $@;
silent_CMAKE= @echo " CMAKE " $(@D);
silent_CONFIG= @echo " CONFIG " $(@D);
silent_DEPGEN= @echo " DEPGEN " $@;
silent_FC= @echo " FC " $@;
silent_FCLD= @echo " FCLD " $@;
silent_MKDIR= @echo " MKDIR " $(@D);
endif
# Path suffixes (i.e. without $(srcdir) prefix) of the source files:
src_roots:= $(addprefix $(srcdir)/,$(subdirs))
src_files:= $(patsubst $(srcdir)/%,%,$(shell find $(src_roots) -name '*.f90'))
# Libraries:
lib_files:= libmkhelper.a
# For each library we need a list of source files implementing them:
libmkhelper_src_files= $(filter src/library/%,$(src_files))
@INVALID_DISABLED@libmkhelper_src_files:= $(filter-out src/library/invalid/%,$(libmkhelper_src_files))
# Executables:
exe_files:= main@EXEEXT@
# For each executable we need the root object file:
main_obj_file:= src/program/main.@OBJEXT@
# Two distjoint sets of dependency files: one for the libraries and one for
# the executables:
lib_dep_files= $(addsuffix .d,$(libmkhelper_src_files))
exe_dep_files= $(filter-out $(lib_dep_files),$(addsuffix .d,$(src_files))) extra_f90.d
# List of directories that need to be created:
dir_files= $(filter-out ./.dirstamp,$(addsuffix .dirstamp,$(sort $(dir $(lib_dep_files) $(exe_dep_files))) $(moddir)/))
# Selective search paths:
vpath %.f90 $(srcdir)
# Disable built-in suffix rules:
.SUFFIXES:
# Delete partially updated files:
.DELETE_ON_ERROR:
# Targets not associated with files:
.PHONY: all depend dummy-depend mostlyclean clean distclean \
install install-libs install-mods install-exes \
sanitize-mod-proxies
# Targets that do not need the inclusion of the dependency files:
NO_INC_TARGETS:= depend dummy-depend mostlyclean clean distclean
# Call make inside the subdirectories unconditionally:
.PHONY: $(bundled_subdirs)
# Keep sentinel files of created directories:
.PRECIOUS: $(dir_files)
# Default rule:
all: $(lib_files) $(exe_files)
# Explicit dependency generation rule:
depend: $(lib_dep_files) $(exe_dep_files)
# Delete the results of compilation and linking:
mostlyclean: $(bundled_subdirs)
rm -f $(src_files:.f90=.@OBJEXT@)
rm -f $(moddir)/*.@FC_MOD_FILE_EXT@ $(moddir)/*.@FC_MOD_FILE_EXT@.proxy
rm -f $(lib_files) $(exe_files) $(exe_files:=.dSYM)
# Delete files generated at the building stage:
clean: mostlyclean
# Delete everything generated at the configure stage (and clean the created
# directories if they are empty):
distclean: clean
rm -f config.log config.status depgen.config deplist.config
rm -f $(lib_dep_files) $(exe_dep_files)
rm -f $(dir_files)
rm -rf $(bundled_ready_cmake_subdirs) $(bundled_delayed_cmake_subdirs)
@for dir in $(moddir) bundled/build; do \
if test -d "$$dir"; then \
echo "find '$$dir' -type d -empty -delete"; \
find "$$dir" -type d -empty -delete; \
fi; \
done
@test '.' = '$(srcdir)' || \
for dir in $(subdirs) $(bundled_subdirs) bundled; do \
if test -d "$$dir"; then \
echo "find '$$dir' -type d -empty -delete"; \
find "$$dir" -type d -empty -delete; \
fi; \
done
find . -name '*.pyc' -delete -o -name '*.pyo' -delete -o -name '__pycache__' -delete
rm -f mkhelper.mk
# Installation rule:
install: install-libs install-mods install-exes
# Library archiving rules:
libmkhelper.a: $(libmkhelper_src_files:.f90=.@OBJEXT@)
$(lib_files): | $(dir_files)
$(silent_AR)rm -f $@ && $(AR) $(ARFLAGS) $@ $^
# Executable linking rules:
main@EXEEXT@: $(filter %.@OBJEXT@,$(shell $(DEPLIST) $(DEPLIST_args) -t $(main_obj_file) -f $(exe_dep_files))) $(lib_files) $(BUNDLED_LIBFILES)
$(exe_files): | $(dir_files)
$(silent_FCLD)$(FC) -o $@ $(makefile_FCFLAGS) $(FCFLAGS) $(LDFLAGS) $+ $(makefile_LIBS) $(LIBS)
# Fortran compilation rule:
%.@OBJEXT@: %.f90 | $(dir_files) $(bundled_subdirs)
$(silent_FC)$(FC) -o $@ -c $(makefile_FCFLAGS) $(FCFLAGS) @FCFLAGS_f90@ $<
# Fortran module file tracking rule:
$(moddir)/%.@FC_MOD_FILE_EXT@.proxy: | sanitize-mod-proxies
@if test -z '$<'; then \
echo "Cannot find Fortran source file providing module '$(basename $(@F:.proxy=))'." >&2; \
else \
if test ! -f '$(@:.proxy=)'; then rm -f '$<'; $(MAKE) '$<'; fi; \
if cmp '$@' '$(@:.proxy=)' >/dev/null 2>&1 || $(MODCMP) '$@' '$(@:.proxy=)' @FC_VENDOR@ 2>/dev/null; then :; \
else cp '$(@:.proxy=)' '$@' 2>/dev/null; fi; \
fi
# Deletes all Fortran module proxy files that do not have an existing module to
# be a proxy of, i.e. if <filename>.proxy exists but <filename> does not,
# delete <filename>.proxy:
sanitize-mod-proxies:
@rm -f $(filter-out $(addsuffix .proxy,$(wildcard $(moddir)/*.@FC_MOD_FILE_EXT@)),$(wildcard $(moddir)/*.@FC_MOD_FILE_EXT@.proxy))
# Directory creation rule:
%/.dirstamp:
$(silent_MKDIR)@MKDIR_P@ $(@D) && touch $@
# Fortran dependency generation rule:
%.f90.d: %.f90 mkhelper.mk | $(dir_files)
$(silent_DEPGEN)$(DEPGEN) $(DEPGEN_args) -o $@ --obj-name $(@:.f90.d=.@OBJEXT@) -i $< -- $(DEPGEN_FCFLAGS) $(makefile_FCFLAGS) $(FCFLAGS)
# Dependency generation rule for undetectable Fortran dependencies:
extra_f90.d: mkhelper.mk
$(silent_DEPGEN):;{ \
echo 'src/program/main.o:| src/program/implicit_external.o'; \
} >$@
# Configure delayed bundled libraries:
@DELAYED_CONFIG_RULES@
# Make bundled libraries:
$(bundled_ready_config_subdirs):
@if test -f '$@/Makefile'; then \
$(MAKE) -C $@ $(filter all mostlyclean clean distclean,$(MAKECMDGOALS)) V=$(V); \
else \
test -z '$(filter-out distclean,$(or $(MAKECMDGOALS),all))'; \
fi
$(bundled_delayed_config_subdirs):
@if test -f '$@/Makefile'; then \
$(MAKE) -C $@ $(filter all mostlyclean clean distclean,$(MAKECMDGOALS)) V=$(V); \
else \
test -z '$(filter-out mostlyclean clean distclean,$(or $(MAKECMDGOALS),all))'; \
fi
$(bundled_ready_cmake_subdirs):
@if test -f '$@/Makefile'; then \
$(MAKE) -C $@ $(filter all clean,$(MAKECMDGOALS) $(if $(filter mostlyclean distclean,$(MAKECMDGOALS)),clean)) VERBOSE=$(filter-out 0,$(V)); \
else \
test -z '$(filter-out distclean,$(or $(MAKECMDGOALS),all))'; \
fi
$(bundled_delayed_cmake_subdirs):
@if test -f '$@/Makefile'; then \
$(MAKE) -C $@ $(filter all clean,$(MAKECMDGOALS) $(if $(filter mostlyclean distclean,$(MAKECMDGOALS)),clean)) VERBOSE=$(filter-out 0,$(V)); \
else \
test -z '$(filter-out mostlyclean clean distclean,$(or $(MAKECMDGOALS),all))'; \
fi
# Relink executables if any of the source files of the bundled libraries
# is updated (the semicolon is required to support parallel rebuild):
$(BUNDLED_LIBFILES): $(bundled_subdirs);
# Dummy dependency file generation rule (called by config.status):
dummy-depend: | $(dir_files)
@for file in $(lib_dep_files) $(exe_dep_files); do \
test -e "$$file" || touch "$$file"; \
done
# Library installation rule:
install-libs: $(lib_files)
$(INSTALL) -d $(DESTDIR)@libdir@ && $(INSTALL_DATA) $^ $(DESTDIR)@libdir@
# Fortran module installation rule:
install-mods: $(filter %.@FC_MOD_FILE_EXT@.proxy,$(shell $(DEPLIST) $(DEPLIST_args) -f $(lib_dep_files)))
$(INSTALL) -d $(DESTDIR)@includedir@ && $(INSTALL_DATA) $(basename $^) $(DESTDIR)@includedir@
# Executable installation rule:
install-exes: $(exe_files)
$(INSTALL) -d $(DESTDIR)@bindir@ && $(INSTALL) $^ $(DESTDIR)@bindir@
ifneq (,$(filter-out $(NO_INC_TARGETS),$(or $(MAKECMDGOALS),all)))
include $(lib_dep_files) $(exe_dep_files)
endif