Skip to content

Commit

Permalink
mkhelper.mk.in: apply proxy mechanism to submodules.
Browse files Browse the repository at this point in the history
  • Loading branch information
skosukhin committed Apr 30, 2024
1 parent 60da742 commit 86b2486
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion depgen.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
--fc-enable
--fc-mod-ext=@FC_MOD_FILE_EXT@.proxy
--fc-mod-upper=@FC_MOD_FILE_UPPER@
--fc-smod-ext=@FC_SMOD_FILE_EXT@
--fc-smod-ext=@FC_SMOD_FILE_EXT@.proxy
--fc-root-smod=@FC_ROOT_SMOD@
--fc-inc-flag=@FC_INC_FLAG@
--fc-inc-order=@FC_INC_ORDER@
Expand Down
16 changes: 13 additions & 3 deletions mkhelper.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ depend: $(lib_dep_files) $(exe_dep_files)
mostlyclean: $(bundled_subdirs)
rm -f $(src_files:.f90=.@OBJEXT@)
rm -f $(moddir)/*.@FC_MOD_FILE_EXT@ $(moddir)/*.@FC_MOD_FILE_EXT@.proxy
rm -f $(moddir)/*.@FC_SMOD_FILE_EXT@ $(moddir)/*.@FC_SMOD_FILE_EXT@.proxy
rm -f $(lib_files) $(exe_files) $(exe_files:=.dSYM)

# Delete files generated at the building stage:
Expand Down Expand Up @@ -161,12 +162,12 @@ $(exe_files): | $(dir_files)
$(silent_FCLD)$(FC) -o $@ $(makefile_FCFLAGS) $(FCFLAGS) $(LDFLAGS) $+ $(makefile_LIBS) $(LIBS)

# Fortran compilation rule:
%.@OBJEXT@: %.f90 | $(dir_files) $(bundled_subdirs)
%.@OBJEXT@: %.f90 | $(dir_files) $(bundled_subdirs) sanitize-mod-proxies
$(silent_FC)$(FC) -o $@ -c $(makefile_FCFLAGS) $(FCFLAGS) @FCFLAGS_f90@ $<


# Fortran module file tracking rule:
$(moddir)/%.@FC_MOD_FILE_EXT@.proxy: | sanitize-mod-proxies
$(moddir)/%.@FC_MOD_FILE_EXT@.proxy:
@if test -z '$<'; then \
echo "Cannot find Fortran source file providing module '$(basename $(@F:.proxy=))'." >&2; \
else \
Expand All @@ -175,11 +176,20 @@ $(moddir)/%.@FC_MOD_FILE_EXT@.proxy: | sanitize-mod-proxies
else cp '$(@:.proxy=)' '$@' 2>/dev/null; fi; \
fi

$(moddir)/%.@FC_SMOD_FILE_EXT@.proxy:
@if test -z '$<'; then \
echo "Cannot find Fortran source file providing submodule '$(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))
@rm -f $(filter-out $(addsuffix .proxy,$(wildcard $(moddir)/*.@FC_MOD_FILE_EXT@ $(moddir)/*.@FC_SMOD_FILE_EXT@)),$(wildcard $(moddir)/*.@FC_MOD_FILE_EXT@.proxy $(moddir)/*.@FC_SMOD_FILE_EXT@.proxy))

# Directory creation rule:
%/.dirstamp:
Expand Down

0 comments on commit 86b2486

Please sign in to comment.