-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.in
295 lines (249 loc) · 11 KB
/
Makefile.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# 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_subdirs= @subdirs_extra@
# Path to the directory with the Fortran module files:
moddir:= mod
# Relative path to the directory with the resulting executables:
bindir:= bin
# Paths to the installation directories:
prefix= @prefix@
exec_prefix= @exec_prefix@
# Package tarname:
PACKAGE_TARNAME= @PACKAGE_NAME@-@PACKAGE_VERSION@
# Compilers and utilities:
SHELL= @SHELL@
CC= @CC@
FC= @FC@
PYTHON= @PYTHON@
DEPLIST= ${PYTHON} $(srcdir)/mkhelper/deplist.py
DEPGEN= ${PYTHON} $(srcdir)/mkhelper/depgen.py
MODCMP= ${PYTHON} $(srcdir)/mkhelper/fortmodcmp.py
INSTALL= @INSTALL@
GIT= git
TAR= tar
BZIP2 = bzip2
# Fortran compiler flags:
FCFLAGS= @FCFLAGS@
makefile_FCFLAGS= @FCMODINC@$(moddir) @FCMODOUT@$(moddir) @BUNDLED_FCFLAGS@ @NETCDF_FCFLAGS@ @CDI_FCFLAGS@
# C compiler and preprocessor flags:
CFLAGS= @CFLAGS@
CPPFLAGS= @CPPFLAGS@
makefile_CPPFLAGS= -Isrc @DEFS@
# Linker flags and libraries:
LDFLAGS= @LDFLAGS@ @RPATH_LDFLAGS@
BUNDLED_LIBFILES= @BUNDLED_LIBFILES@
LIBS= @NETCDF_FCLIBS@ @CDI_FCLIBS@ @LIBS@
# Dependency generator flags:
DEPGEN_f90= --src-root='@srcdir@' --pp-enable --pp-eval-expr --fc-enable \
--pp-inc-flag='@FCINCFLAG_PP@' --pp-inc-order='@FCINCORDER_PP@' --pp-macro-flag='@FCDEF_PP@' \
--fc-mod-ext='@[email protected]' --fc-mod-upper='@FCMODUC@' --fc-inc-flag='@FCINCFLAG@' \
--fc-inc-order='@FCINCORDER@' --fc-mod-dir-flag='@FCMODOUT@' --fc-external-mods='f90_unix,omp_lib,netcdf,mo_cdi'
DEPGEN_c= --src-root='@srcdir@' --pp-enable --pp-eval-expr
DEPGEN_FCFLAGS= @DEPGEN_FCFLAGS@
# Silent rule prefixes:
V=@DEFAULT_VERBOSITY@
ifeq ($(V), 0)
silent_CC= @echo " CC " $@;
silent_DEPGEN= @echo " DEPGEN " $@;
silent_FC= @echo " FC " $@;
silent_FCLD= @echo " FCLD " $@;
silent_GEN= @echo " GEN " $@;
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' -o -name '*.c'))
f90_files:= $(filter %.f90,$(src_files))
# We need to treat src/info_extpar.f90 differently:
f90_files:= $(filter-out src/info_extpar.f90,$(f90_files))
c_files:= $(filter %.c,$(src_files))
# Installable scripts:
script_files:= \
$(srcdir)/python/extpar_alb_to_buffer.py \
$(srcdir)/python/extpar_cru_to_buffer.py \
$(srcdir)/python/extpar_emiss_to_buffer.py \
$(srcdir)/python/extpar_era_to_buffer.py \
$(srcdir)/python/extpar_ndvi_to_buffer.py \
$(srcdir)/python/extpar_edgar_to_buffer.py \
$(srcdir)/python/extpar_cdnc_to_buffer.py \
$(srcdir)/python/extpar_ahf_to_buffer.py \
$(srcdir)/python/extpar_isa_to_buffer.py
# Dependency files:
dep_files:= $(addsuffix .d,$(f90_files) $(c_files))
# Stamp files of the building subdirectories:
dir_files= $(addsuffix .dirstamp, $(sort $(dir $(dep_files)))) $(moddir)/.dirstamp $(bindir)/.dirstamp
# Selective search path:
vpath %.f90 $(srcdir)
vpath %.c $(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 sanitize-mod-proxies force-create-info dist
# Targets that do not need the inclusion of the dependency files:
NO_INC_TARGETS:= depend dummy-depend mostlyclean clean distclean dist
# Call make inside the subdirectories unconditionally:
.PHONY: $(bundled_subdirs)
# Keep directory stamps:
.PRECIOUS: $(dir_files)
prog_names:= \
extpar_aot_to_buffer \
extpar_consistency_check \
extpar_flake_to_buffer \
extpar_landuse_to_buffer \
extpar_soil_to_buffer \
extpar_topo_to_buffer \
extpar_hwsdART_to_buffer
# Another option is to use the value from the configure script
# (i.e. EXEEXT surrounded with @):
EXEEXT:= .exe
prog_files:= $(addprefix $(bindir)/,$(addsuffix $(EXEEXT),$(prog_names)))
script_links:= $(addprefix $(bindir)/,$(notdir $(script_files)))
# Default rule:
all: $(prog_files) $(script_links)
# Explicit dependency generation rule:
depend: $(dep_files)
# Delete the results of compilation and linking:
mostlyclean: $(bundled_subdirs)
rm -f $(addsuffix .@OBJEXT@,$(basename $(f90_files) $(c_files))) src/info_extpar.@OBJEXT@
rm -f $(moddir)/*.@FCMODEXT@ $(moddir)/*.@[email protected]
rm -f $(prog_files)
# Delete files generated at the building stage:
clean: mostlyclean
rm -f src/info_extpar.f90
rm -f $(script_links)
# Delete everything generated at the configure stage (and clean the created
# directories if they are empty):
distclean: clean
rm -f src/config.h config.log config.status
rm -f $(dep_files)
rm -f $(dir_files)
@for dir in $(bindir) $(moddir); do \
if test -d "$$dir"; then \
echo "find '$$dir' -type d -empty -delete"; \
find "$$dir" -type d -empty -delete; \
fi; \
done
@if test '.' != '$(srcdir)'; then \
for dir in $(subdirs) bundled; do \
if test -d "$$dir"; then \
echo "find '$$dir' -type d -empty -delete"; \
find "$$dir" -type d -empty -delete; \
fi; \
done; \
fi
rm -f Makefile
rm -f modules.env
# Installation rules:
install: $(prog_files) $(script_links)
$(INSTALL) -d $(DESTDIR)@bindir@ && $(INSTALL) $^ $(DESTDIR)@bindir@
# Check rule
check: all
@test -z '$(bundled_subdirs)' && echo "The list of bundled libraries is empty: nothing to check." && exit 0; \
fail=; pass=; \
for d in $(bundled_subdirs); do \
if $(MAKE) -C "$$d" check V=$(V); then pass="$$pass$$d "; \
else fail="$$fail$$d "; fi; \
done; \
test -n "$$pass" && echo "PASS: $$pass"; \
if test -n "$$fail"; then echo "FAIL: $$fail" && false; fi # exit code of the last command must be zero if $fail is empty
# Tarball creation rule:
dist:
@if test ! -e @top_srcdir@/.git; then echo "'@top_srcdir@' is not a git repository" >&2; exit 1; fi
$(GIT) -C @top_srcdir@ archive --prefix=$(PACKAGE_TARNAME)/ --format tar -o @abs_top_builddir@/$(PACKAGE_TARNAME).tar HEAD
$(GIT) -C @top_srcdir@ submodule foreach '$(GIT) archive --prefix=$(PACKAGE_TARNAME)/$$path/ --format tar -o @abs_top_builddir@/$$name.tar HEAD && $(TAR) -Af @abs_top_builddir@/$(PACKAGE_TARNAME).tar @abs_top_builddir@/$$name.tar && rm @abs_top_builddir@/$$name.tar'
rm -f $(PACKAGE_TARNAME).tar.bz2 && BZIP2=$${BZIP2--9} $(BZIP2) $(PACKAGE_TARNAME).tar
prog_rule = $(bindir)/$(1)$$(EXEEXT): $$(filter %.@OBJEXT@,$$(shell $(DEPLIST) --inc-oo -t src/$(1).@OBJEXT@ -f Makefile $$(dep_files))) $$(BUNDLED_LIBFILES)
$(foreach name,$(prog_names),$(eval $(call prog_rule,$(name))))
$(prog_files): | $(dir_files)
$(silent_FCLD)$(FC) -o $@ $(makefile_FCFLAGS) $(FCFLAGS) $(LDFLAGS) $+ $(LIBS)
script_rule = $(bindir)/$(notdir $(1)): $(1)
$(foreach script,$(script_files),$(eval $(call script_rule,$(script))))
$(script_links): | $(dir_files)
$(silent_GEN)cd $(bindir) && @LN_S@ $(abspath $^) $(@F)
# C compilation rule:
%.@OBJEXT@: %.c | $(dir_files)
$(silent_CC)$(CC) -o $@ -c $(CFLAGS) $(makefile_CPPFLAGS) $(CPPFLAGS) $<
# Fortran compilation rule:
%.@OBJEXT@: %.f90 | $(dir_files) $(bundled_subdirs)
$(silent_FC)$(FC) -o $@ -c $(makefile_FCFLAGS) $(FCFLAGS) @FCFLAGS_f90@ $<
# Fortran module file rule:
$(moddir)/%.@[email protected]:| 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
# Delete 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)/*.@FCMODEXT@)),$(wildcard $(moddir)/*.@[email protected]))
# Make bundled libraries:
$(bundled_subdirs):
@if test -f '$@/Makefile'; then \
$(MAKE) -C $@ $(filter all mostlyclean clean distclean,$(MAKECMDGOALS)) V=$(V); \
else \
test xdistclean = x$(filter distclean,$(MAKECMDGOALS)); \
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);
# Info source file generation rule:
@abs_builddir@/src/info_extpar.f90: force-create-info | $(dir_files)
$(silent_GEN):;{ \
echo 'Compiler command : $(FC)' && \
echo 'Compiler version : @FC_VENDOR@ @FC_VERSION@' && \
echo 'Compiler includes: @NETCDF_FCFLAGS@ @CDI_FCFLAGS@' && \
echo 'Compiler flags : $(FCFLAGS)' && \
echo 'Linker command : $(FC)' && \
echo 'Linker version : @FC_VENDOR@ @FC_VERSION@' && \
echo 'Linker flags : $(FCFLAGS) $(LDFLAGS)' && \
echo 'Linker libraries : $(LIBS)'; \
} >.fconfig && \
$(srcdir)/bin/gen_info.sh .fconfig '$(srcdir)/src' 'src' || exit 1; \
rm -f .fconfig && test -f $@
# Directory creation rule:
%/.dirstamp:
$(silent_MKDIR)@MKDIR_P@ $(@D) && touch $@
# C dependency generation rule:
%.c.d: %.c Makefile | $(dir_files)
$(silent_DEPGEN)$(DEPGEN) $(DEPGEN_c) -o $@ --obj-name $(@:.c.d=.@OBJEXT@) -i $< -- $(CFLAGS) $(makefile_CPPFLAGS) $(CPPFLAGS)
# Fortran dependency generation rule:
%.f90.d: %.f90 Makefile | $(dir_files)
$(silent_DEPGEN)$(DEPGEN) $(DEPGEN_f90) -o $@ --obj-name $(@:.f90.d=.@OBJEXT@) -i $< -- $(DEPGEN_FCFLAGS) $(makefile_FCFLAGS) $(FCFLAGS)
# Dummy dependency file generation rule (called by config.status):
dummy-depend: | $(dir_files)
@for file in $(dep_files); do \
test -e "$$file" || touch "$$file"; \
done
# Additional dependencies:
# This section is parsed by $(DEPLIST), which does not understand variables.
# Therefore, we need to specify everythin literally.
# 1. Source file 'info_extpar.f90' is unconditionally regenerated every time
# 'make' processes this makefile. In our case, the file might be processed
# twice within one call to 'make': first time to update $(dep_files) if
# required and second time to update everything else if any of $(dep_files)
# has been updated during the first step. This means that we would generate
# 'info_extpar.f90' twice per call to 'make' if we treated the file as
# other source file. To avoid that, we manually specify the dependencies
# here (note that we should treat the object file by the absolute path
# to account for out-of-source builds properly):
@abs_builddir@/src/info_extpar.@OBJEXT@: mod/mo_logging.@[email protected]
mod/info_extpar.@[email protected]: @abs_builddir@/src/info_extpar.@OBJEXT@
# 2. The list of dependencies related to Fortran-to-C bindings:
src/mo_util_mmap_cache.@OBJEXT@:| src/util_mmap_cache.@OBJEXT@
current_targets:= $(strip $(MAKECMDGOALS))
ifeq (,$(current_targets))
current_targets:= all
endif
ifneq (,$(filter-out $(NO_INC_TARGETS),$(current_targets)))
include $(dep_files)
endif