@@ -214,68 +214,91 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
214
214
# Create new makefile
215
215
with open (makefile , 'w' ) as file :
216
216
print ("# %s created by makedep" % (makefile ), file = file )
217
- print ("" , file = file )
217
+ print (file = file )
218
218
print ("# Invoked as" , file = file )
219
219
print ('# ' + ' ' .join (sys .argv ), file = file )
220
- print ("" , file = file )
220
+ print (file = file )
221
221
print ("all:" , " " .join (targets ), file = file )
222
- print ("" , file = file )
223
222
223
+ # print(file=file)
224
224
# print("# SRC_DIRS is usually set in the parent Makefile but in case is it not we", file=file)
225
225
# print("# record it here from when makedep was previously invoked.", file=file)
226
226
# print("SRC_DIRS ?= ${SRC_DIRS}", file=file)
227
- # print("", file=file)
228
227
228
+ # print(file=file)
229
229
# print("# all_files:", ' '.join(all_files), file=file)
230
- # print("", file=file)
231
230
232
231
# 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 ]
236
235
found_deps = [
237
236
dep for pair in zip (found_mods , found_objs ) for dep in pair
238
237
]
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 ]
240
239
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
+ ]
243
244
244
245
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 )
246
250
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 )
251
255
print ("# found mods:" , ' ' .join (found_mods ), file = file )
252
256
print ("# found objs:" , ' ' .join (found_objs ), file = file )
253
257
print ("# missing:" , ' ' .join (missing_mods ), file = file )
254
258
print ("# includes_all:" , ' ' .join (incs ), file = file )
255
259
print ("# includes_pth:" , ' ' .join (incdeps ), file = file )
256
260
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 )
262
274
263
275
# 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 )
267
282
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 )
271
286
print ("# includes_pth:" , ' ' .join (incdeps ), file = file )
272
287
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 )
275
298
276
299
# Externals (so called)
277
300
if link_externals :
278
- print ("" , file = file )
301
+ print (file = file )
279
302
print ("# Note: The following object files are not associated with "
280
303
"modules so we assume we should link with them:" , file = file )
281
304
print ("# " , ' ' .join (externals ), file = file )
@@ -286,23 +309,23 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
286
309
# Write rules for linking executables
287
310
for p in sorted (prg2o .keys ()):
288
311
o = prg2o [p ]
289
- print ("" , file = file )
312
+ print (file = file )
290
313
print (p + ':' , ' ' .join (link_obj (o , o2uses , mod2o , all_modules ) + externals ), file = file )
291
314
print ('\t $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)' , file = file )
292
315
293
316
# Write rules for building libraries
294
317
for lb in sorted (targ_libs ):
295
- print ("" , file = file )
318
+ print (file = file )
296
319
print (lb + ':' , ' ' .join (list (o2F90 .keys ()) + list (o2c .keys ())), file = file )
297
320
print ('\t $(AR) $(ARFLAGS) $@ $^' , file = file )
298
321
299
322
# Write cleanup rules
300
- print ("" , file = file )
323
+ print (file = file )
301
324
print ("clean:" , file = file )
302
325
print ('\t rm -f *.mod *.o' , ' ' .join (list (prg2o .keys ()) + targ_libs ), file = file )
303
326
304
327
# Write re-generation rules
305
- print ("" , file = file )
328
+ print (file = file )
306
329
print ("remakedep:" , file = file )
307
330
print ('\t ' + ' ' .join (sys .argv ), file = file )
308
331
@@ -366,24 +389,23 @@ def scan_fortran_file(src_file, defines=None):
366
389
367
390
cpp_defines = defines if defines is not None else []
368
391
369
- #cpp_macros = [define.split('=')[0] for define in cpp_defines]
370
392
cpp_macros = dict ([t .split ('=' ) for t in cpp_defines ])
371
393
cpp_group_stack = []
372
394
373
395
with io .open (src_file , 'r' , errors = 'replace' ) as file :
374
396
lines = file .readlines ()
375
397
376
398
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
378
400
379
401
file_has_externals = False
380
- # True if the file contains any external objects
402
+ # True if the file contains any external objects
381
403
382
404
cpp_exclude = False
383
- # True if the parser excludes the subsequent lines
405
+ # True if the parser excludes the subsequent lines
384
406
385
407
cpp_group_stack = []
386
- # Stack of condition group exclusion states
408
+ # Stack of condition group exclusion states
387
409
388
410
for line in lines :
389
411
# Start of #ifdef condition group
@@ -446,14 +468,16 @@ def scan_fortran_file(src_file, defines=None):
446
468
if match :
447
469
new_macro = line .lstrip ()[1 :].split ()[1 ]
448
470
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."
452
475
continue
453
476
454
477
match = re_module .match (line .lower ())
455
478
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' :
457
481
module_decl .append (match .group (1 ))
458
482
external_namespace = False
459
483
@@ -632,9 +656,9 @@ parser.add_argument(
632
656
)
633
657
parser .add_argument (
634
658
'-f' , '--fc_rule' ,
635
- default = "$(FC) $(DEFS) $(FCFLAGS ) $(CPPFLAGS) -c $< " ,
659
+ default = "$(FC) $(DEFS) $(CPPFLAGS ) $(FCFLAGS) " ,
636
660
help = "String to use in the compilation rule. Default is: "
637
- "'$(FC) $(DEFS) $(FCFLAGS ) $(CPPFLAGS) -c $< '"
661
+ "'$(FC) $(DEFS) $(CPPFLAGS ) $(FCFLAGS) '"
638
662
)
639
663
parser .add_argument (
640
664
'-x' , '--exec_target' ,
0 commit comments