7 def run(files=None, verbose=True, overwrite=None, output=None, macros={}, build=""):
14 for i
in depends.keys():
15 print(
"\033[032m" + i +
"\033[039m depends on :\033[034m")
21 output =
"makefile.dep"
23 write_depend(outfile=output, dep=depends, overwrite=overwrite, build=build)
28 def write_depend(outfile="makefile.dep", dep=[], overwrite=False, build=""):
29 "Write the dependencies to outfile"
31 if os.path.exists(outfile):
33 print(
"\033[031mWarning file exists.\033[039m")
34 opt = input(
"Overwrite? Y... for yes.")
37 if opt.lower().startswith(
"y"):
43 f = open(outfile,
"w")
44 f.write(
"# This file is generated automatically. DO NOT EDIT!\n")
46 tmp, fil = os.path.split(i)
47 stri =
"\n" + os.path.join(build, fil.split(
".")[0] +
".o" +
" : ")
49 tmp, fil = os.path.split(j)
50 stri = stri +
" \\\n\t" + os.path.join(build, fil.split(
".")[0] +
".o")
58 "Return all files ending with any of ext"
62 fil.extend(filter(
lambda x: x.endswith(i), tmp))
75 source_file.file_name = i
76 source_file.uses =
get_uses(i, macros)
79 fileList.append(source_file)
85 "Return which modules are used in infile after expanding macros"
86 p = re.compile(
"^\s*use\s+(?P<moduse>\w*)\s*(,)?\s*(only)?\s*(:)?.*?$", re.IGNORECASE).match
90 with open(infile,
"r")
as f:
96 uses.append(tmp.group(
"moduse").strip())
99 uniq_mods = list(set(uses))
101 for i, mod
in enumerate(uniq_mods):
102 for k, v
in macros.items():
103 if re.match(k, mod, re.IGNORECASE):
104 uniq_mods[i] = mod.replace(k, v)
110 "Return all the modules that are in infile"
111 p = re.compile(
"^\s*module\s*(?P<modname>\w*)", re.IGNORECASE).match
115 with open(infile,
"r")
as f:
121 contains.append(tmp.group(
"modname").strip())
124 return list(set(contains))
128 "Turn a list of file_objs in a dictionary, containing which modules depend on which files"
132 dic[j.lower()] = i.file_name
142 if m2f[j.lower()] != i.file_name:
143 tmp.append(m2f[j.lower()])
145 if j
in [
"petsc",
"mpi",
"iso_fortran_env",
"cgns"]:
149 elif j[-2:] ==
"_b" or j[-2:] ==
"_d":
155 "\033[031mError\033[039m module \033[032m"
157 +
"\033[039m not defined in any files. Skipping..."
160 deps[i.file_name] = tmp
174 if __name__ ==
"__main__":
178 parser = argparse.ArgumentParser(description=
"Generate Fortran dependencies")
179 parser.add_argument(
"-f",
"--files", nargs=
"+", help=
"Files to process")
184 metavar=
"NAME=DESCRIPTION",
185 help=
"""The macro NAME is replaced by DEFINITION in 'use' statements""",
187 parser.add_argument(
"-b",
"--build", nargs=1, help=
"Build Directory (prepended to all files in output", default=
"")
188 parser.add_argument(
"-o",
"--output", nargs=1, help=
"Output file")
189 parser.add_argument(
"-v",
"--verbose", action=
"store_true", help=
"explain what is done")
190 parser.add_argument(
"-w",
"--overwrite", action=
"store_true", help=
"Overwrite output file without warning")
193 args = parser.parse_args()
200 temp = var.split(
"=")
201 macros[temp[0]] = temp[1]
203 output = args.output[0]
if args.output
else None
204 build = args.build[0]
if args.build
else ""
206 run(files=args.files, verbose=args.verbose, overwrite=args.overwrite, macros=macros, output=output, build=build)
real(kind=realtype), dimension(:, :, :), pointer p
def get_depends(fob=[], m2f=[])
def file_objs_to_mod_dict(file_objs=[])
def run(files=None, verbose=True, overwrite=None, output=None, macros={}, build="")
def get_contains(infile=None)
def create_file_objs(files=None, macros={})
def write_depend(outfile="makefile.dep", dep=[], overwrite=False, build="")
def get_source(ext=[".f90", ".F90"])
def get_uses(infile=None, macros={})