Skip to content

Commit

Permalink
depgen.py: support Fortran module stamp files.
Browse files Browse the repository at this point in the history
  • Loading branch information
skosukhin committed May 14, 2024
1 parent 3486e85 commit 0d3a26e
Showing 1 changed file with 56 additions and 14 deletions.
70 changes: 56 additions & 14 deletions mkhelper/depgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ def default_obj_name(src_name):
"`INCLUDE`, `USE` and `MODULE` statements; if disabled (default), all "
"arguments of this argument group are ignored",
)
fc_arg_group.add_argument(
"--fc-mod-stamp-name",
metavar="FC_MOD_STAMP_NAME",
nargs="+",
help="name of the Fortran module stamp file (a.k.a witness or anchor), "
"the prerequisite of the Fortran module and submodule files that are "
"generated as a result of, and an extra target of the Fortran module "
"and submodule files that are required for the compilation of SRC_NAME "
"as it will appear in the OUTPUT; normally (and by default) equals to "
"the OBJ_NAME",
)
fc_arg_group.add_argument(
"--fc-mod-ext",
default="mod",
Expand Down Expand Up @@ -442,6 +453,14 @@ def default_obj_name(src_name):
args.pp_macros = predefined_macros

if args.fc_enable:
if not args.fc_mod_stamp_name:
args.fc_mod_stamp_name = args.obj_name
elif len(args.fc_mod_stamp_name) != len(args.input):
parser.error(
"number of FC_MOD_STAMP_NAME values is not equal to the number "
"of INPUT values"
)

args.fc_mod_upper = args.fc_mod_upper == "yes"
args.fc_root_smod = args.fc_root_smod == "yes"
args.fc_mod_dir = args.fc_mod_dir[-1] if args.fc_mod_dir else None
Expand All @@ -457,6 +476,8 @@ def default_obj_name(src_name):
args.fc_external_mods = [
m for sublist in args.fc_external_mods for m in sublist
]
else:
args.fc_mod_stamp_name = ()

return args

Expand Down Expand Up @@ -557,8 +578,13 @@ def format_debug_line(line, msg):
format_debug_line(line, msg)
)

for inp, out, src_name, obj_name, dep_name in zip_longest23(
args.input, args.output, args.src_name, args.obj_name, args.dep_name
for inp, out, src_name, obj_name, dep_name, mod_stamp_name in zip_longest23(
args.input,
args.output,
args.src_name,
args.obj_name,
args.dep_name,
args.fc_mod_stamp_name,
):
in_stream, in_stream_close = (
(sys.stdin, False) if inp is None else (open23(inp), True)
Expand All @@ -579,8 +605,12 @@ def format_debug_line(line, msg):

out_lines = gen_lc_deps(src_name, lc_files)

include_targets = [obj_name, dep_name]
if obj_name != mod_stamp_name:
include_targets.append(mod_stamp_name)

out_lines.extend(
gen_include_deps(src_name, obj_name, dep_name, included_files)
gen_include_deps(include_targets, src_name, included_files)
)

if (
Expand All @@ -592,6 +622,7 @@ def format_debug_line(line, msg):
out_lines.extend(
gen_module_deps(
obj_name,
mod_stamp_name,
provided_modules,
required_modules,
provided_submodules,
Expand Down Expand Up @@ -650,9 +681,9 @@ def gen_lc_deps(src_name, lc_files):
return result


def gen_include_deps(src_name, obj_name, dep_name, included_files):
def gen_include_deps(include_targets, src_name, included_files):
result = []
targets = " ".join(filter(None, (obj_name, dep_name)))
targets = " ".join(filter(None, include_targets))
if targets:
prereqs = " ".join(filter(None, [src_name] + list(included_files)))
if prereqs:
Expand All @@ -662,6 +693,7 @@ def gen_include_deps(src_name, obj_name, dep_name, included_files):

def gen_module_deps(
obj_name,
mod_stamp_name,
provided_modules,
required_modules,
provided_submodules,
Expand All @@ -673,20 +705,24 @@ def gen_module_deps(
smod_ext,
):
result = []
if obj_name:
obj_targets = list(
if obj_name or mod_stamp_name:
targets = list(
modules_to_filenames(provided_modules, mod_dir, mod_upper, mod_ext)
)
obj_targets.extend(
targets.extend(
submodules_to_filenames(
provided_submodules, mod_dir, mod_upper, smod_infix, smod_ext
)
)

if obj_targets:
result.append("{0}: {1}\n".format(" ".join(obj_targets), obj_name))
if targets:
result.append(
"{0}: {1}\n".format(
" ".join(targets), mod_stamp_name or obj_name
)
)

obj_prereqs = list(
prereqs = list(
modules_to_filenames(
# Do not depend on the provided modules:
[m for m in required_modules if m not in provided_modules],
Expand All @@ -696,7 +732,7 @@ def gen_module_deps(
)
)

obj_prereqs.extend(
prereqs.extend(
submodules_to_filenames(
# Do not depend on the provided submodules:
[
Expand All @@ -711,9 +747,15 @@ def gen_module_deps(
)
)

if obj_prereqs:
result.append("{0}: {1}\n".format(obj_name, " ".join(obj_prereqs)))
if prereqs:
result.append(
"{0}: {1}\n".format(
" ".join(filter(None, (obj_name, mod_stamp_name))),
" ".join(prereqs),
)
)

if obj_name:
result.extend(
[
"{0}: #-hint {1}\n".format(m, obj_name)
Expand Down

0 comments on commit 0d3a26e

Please sign in to comment.