Skip to content

Commit 117f16b

Browse files
committed
Makedep output cleanup and PEP8 fixes
This patch makes some changes to makedep output: * Compile commands now end with the source code, rather than the include files. This makes it easier to see which file is being compiled. * Blank lines were added inbetween object file rules. * Redundant spaces from absent include flags is now removed. Also some minor PEP8-like cleanups: * Some (but not all) 79+ character lines were reduced or split. * Some (but not all) single-letter variables were renamed. * A bad error handler for missing macros was fixed. Nothing particularly major here, but build output should be more readable.
1 parent f1ba822 commit 117f16b

File tree

1 file changed

+69
-45
lines changed

1 file changed

+69
-45
lines changed

ac/makedep

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -214,68 +214,91 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
214214
# Create new makefile
215215
with open(makefile, 'w') as file:
216216
print("# %s created by makedep" % (makefile), file=file)
217-
print("", file=file)
217+
print(file=file)
218218
print("# Invoked as", file=file)
219219
print('# '+' '.join(sys.argv), file=file)
220-
print("", file=file)
220+
print(file=file)
221221
print("all:", " ".join(targets), file=file)
222-
print("", file=file)
223222

223+
# print(file=file)
224224
# print("# SRC_DIRS is usually set in the parent Makefile but in case is it not we", file=file)
225225
# print("# record it here from when makedep was previously invoked.", file=file)
226226
# print("SRC_DIRS ?= ${SRC_DIRS}", file=file)
227-
# print("", file=file)
228227

228+
# print(file=file)
229229
# print("# all_files:", ' '.join(all_files), file=file)
230-
# print("", file=file)
231230

232231
# Write rule for each object from Fortran
233-
for o in sorted(o2F90.keys()):
234-
found_mods = [m for m in o2uses[o] if m in all_modules]
235-
found_objs = [mod2o[m] for m in o2uses[o] if m in all_modules]
232+
for obj in sorted(o2F90.keys()):
233+
found_mods = [m for m in o2uses[obj] if m in all_modules]
234+
found_objs = [mod2o[m] for m in o2uses[obj] if m in all_modules]
236235
found_deps = [
237236
dep for pair in zip(found_mods, found_objs) for dep in pair
238237
]
239-
missing_mods = [m for m in o2uses[o] if m not in all_modules]
238+
missing_mods = [m for m in o2uses[obj] if m not in all_modules]
240239

241-
incs, inc_used = nested_inc(o2h[o] + o2inc[o], f2F, defines)
242-
inc_mods = [u for u in inc_used if u not in found_mods and u in all_modules]
240+
incs, inc_used = nested_inc(o2h[obj] + o2inc[obj], f2F, defines)
241+
inc_mods = [
242+
u for u in inc_used if u not in found_mods and u in all_modules
243+
]
243244

244245
incdeps = sorted(set([f2F[f] for f in incs if f in f2F]))
245-
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
246+
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))
247+
248+
# Header
249+
print(file=file)
246250
if debug:
247-
print("# Source file {} produces:".format(o2F90[o]), file=file)
248-
print("# object:", o, file=file)
249-
print("# modules:", ' '.join(o2mods[o]), file=file)
250-
print("# uses:", ' '.join(o2uses[o]), file=file)
251+
print("# Source file {} produces:".format(o2F90[obj]), file=file)
252+
print("# object:", obj, file=file)
253+
print("# modules:", ' '.join(o2mods[obj]), file=file)
254+
print("# uses:", ' '.join(o2uses[obj]), file=file)
251255
print("# found mods:", ' '.join(found_mods), file=file)
252256
print("# found objs:", ' '.join(found_objs), file=file)
253257
print("# missing:", ' '.join(missing_mods), file=file)
254258
print("# includes_all:", ' '.join(incs), file=file)
255259
print("# includes_pth:", ' '.join(incdeps), file=file)
256260
print("# incargs:", ' '.join(incargs), file=file)
257-
print("# program:", ' '.join(o2prg[o]), file=file)
258-
if o2mods[o]:
259-
print(' '.join(o2mods[o])+':', o, file=file)
260-
print(o + ':', o2F90[o], ' '.join(inc_mods + incdeps + found_deps), file=file)
261-
print('\t'+fc_rule, ' '.join(incargs), file=file)
261+
print("# program:", ' '.join(o2prg[obj]), file=file)
262+
263+
# Fortran Module dependencies
264+
if o2mods[obj]:
265+
print(' '.join(o2mods[obj]) + ':', obj, file=file)
266+
267+
# Fortran object dependencies
268+
obj_incs = ' '.join(inc_mods + incdeps + found_deps)
269+
print(obj + ':', o2F90[obj], obj_incs, file=file)
270+
271+
# Fortran object build rule
272+
obj_rule = ' '.join([fc_rule] + incargs + ['-c', '$<'])
273+
print('\t' + obj_rule, file=file)
262274

263275
# Write rule for each object from C
264-
for o in sorted(o2c.keys()):
265-
incdeps = sorted(set([f2F[h] for h in o2h[o] if h in f2F]))
266-
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
276+
for obj in sorted(o2c.keys()):
277+
incdeps = sorted(set([f2F[h] for h in o2h[obj] if h in f2F]))
278+
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))
279+
280+
# Header
281+
print(file=file)
267282
if debug:
268-
print("# Source file %s produces:" % (o2c[o]), file=file)
269-
print("# object:", o, file=file)
270-
print("# includes_all:", ' '.join(o2h[o]), file=file)
283+
print("# Source file %s produces:" % (o2c[obj]), file=file)
284+
print("# object:", obj, file=file)
285+
print("# includes_all:", ' '.join(o2h[obj]), file=file)
271286
print("# includes_pth:", ' '.join(incdeps), file=file)
272287
print("# incargs:", ' '.join(incargs), file=file)
273-
print(o+':', o2c[o], ' '.join(incdeps), file=file)
274-
print('\t$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c $<', ' '.join(incargs), file=file)
288+
289+
# C object dependencies
290+
print(obj + ':', o2c[obj], ' '.join(incdeps), file=file)
291+
292+
# C object build rule
293+
c_rule = ' '.join(
294+
['$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)'] + incargs + ['-c', '$<']
295+
)
296+
#print('\t' + c_rule, ' '.join(incargs), '-c', '$<', file=file)
297+
print('\t' + c_rule, file=file)
275298

276299
# Externals (so called)
277300
if link_externals:
278-
print("", file=file)
301+
print(file=file)
279302
print("# Note: The following object files are not associated with "
280303
"modules so we assume we should link with them:", file=file)
281304
print("# ", ' '.join(externals), file=file)
@@ -286,23 +309,23 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
286309
# Write rules for linking executables
287310
for p in sorted(prg2o.keys()):
288311
o = prg2o[p]
289-
print("", file=file)
312+
print(file=file)
290313
print(p+':', ' '.join(link_obj(o, o2uses, mod2o, all_modules) + externals), file=file)
291314
print('\t$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)', file=file)
292315

293316
# Write rules for building libraries
294317
for lb in sorted(targ_libs):
295-
print("", file=file)
318+
print(file=file)
296319
print(lb+':', ' '.join(list(o2F90.keys()) + list(o2c.keys())), file=file)
297320
print('\t$(AR) $(ARFLAGS) $@ $^', file=file)
298321

299322
# Write cleanup rules
300-
print("", file=file)
323+
print(file=file)
301324
print("clean:", file=file)
302325
print('\trm -f *.mod *.o', ' '.join(list(prg2o.keys()) + targ_libs), file=file)
303326

304327
# Write re-generation rules
305-
print("", file=file)
328+
print(file=file)
306329
print("remakedep:", file=file)
307330
print('\t'+' '.join(sys.argv), file=file)
308331

@@ -366,24 +389,23 @@ def scan_fortran_file(src_file, defines=None):
366389

367390
cpp_defines = defines if defines is not None else []
368391

369-
#cpp_macros = [define.split('=')[0] for define in cpp_defines]
370392
cpp_macros = dict([t.split('=') for t in cpp_defines])
371393
cpp_group_stack = []
372394

373395
with io.open(src_file, 'r', errors='replace') as file:
374396
lines = file.readlines()
375397

376398
external_namespace = True
377-
# True if we are in the external (i.e. global) namespace
399+
# True if we are in the external (i.e. global) namespace
378400

379401
file_has_externals = False
380-
# True if the file contains any external objects
402+
# True if the file contains any external objects
381403

382404
cpp_exclude = False
383-
# True if the parser excludes the subsequent lines
405+
# True if the parser excludes the subsequent lines
384406

385407
cpp_group_stack = []
386-
# Stack of condition group exclusion states
408+
# Stack of condition group exclusion states
387409

388410
for line in lines:
389411
# Start of #ifdef condition group
@@ -446,14 +468,16 @@ def scan_fortran_file(src_file, defines=None):
446468
if match:
447469
new_macro = line.lstrip()[1:].split()[1]
448470
try:
449-
cpp_macros.remove(new_macro)
450-
except:
451-
# Ignore missing macros (for now?)
471+
cpp_macros.pop(new_macro)
472+
except KeyError:
473+
# C99: "[A macro] is ignored if the specified identifier is
474+
# not currently defined as a macro name."
452475
continue
453476

454477
match = re_module.match(line.lower())
455478
if match:
456-
if match.group(1) not in 'procedure': # avoid "module procedure" statements
479+
# Avoid "module procedure" statements
480+
if match.group(1) not in 'procedure':
457481
module_decl.append(match.group(1))
458482
external_namespace = False
459483

@@ -632,9 +656,9 @@ parser.add_argument(
632656
)
633657
parser.add_argument(
634658
'-f', '--fc_rule',
635-
default="$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<",
659+
default="$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)",
636660
help="String to use in the compilation rule. Default is: "
637-
"'$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<'"
661+
"'$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)'"
638662
)
639663
parser.add_argument(
640664
'-x', '--exec_target',

0 commit comments

Comments
 (0)