forked from thomas-robinson/mkmf2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseShort.py.out
More file actions
123 lines (91 loc) · 3.24 KB
/
Copy pathparseShort.py.out
File metadata and controls
123 lines (91 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import re;
import os;
"""Package Parser
Resolves dependencies
"""
fName = "diag_manager.F90"
"""@brief Parses Fortran file and returns module dependencies
This function takes in a file to parse through.
Using regex pattern matching a module list is populated, cleaned up, and returned without duplicates.
"""
def getModules(fileName, verbose = False):
MODS = []
fileContents = open(fileName).read()
if verbose:
print("Open" + fileName + " and read contents")
"""Regex pattern to find matches in the file
Checks for USE and possible & on the same or next line, until module name is found signified by the '?'
Ignores cases and tries to match on all lines
"""
patternMatch = re.compile('^ *USE[ &\n]+.*?[ &\n]*,', re.IGNORECASE | re.M)
if verbose:
print("Parsing the file, finding all possible matches using regex")
"""Finds all possible matches in the file
Puts all possible matches in a list
"""
matches = re.findall(patternMatch, fileContents)
"""Grooms and populates return list of modules
Removes spaces, characters from pattern matching, and checks for duplicates
"""
for match in matches:
if verbose:
print("Match found: " + match)
match = match.lower().strip()
badChars = ["use", "&", '\n', ' ', ',']
for char in badChars:
match = match.replace(char, '')
if verbose:
print("Cleaning up the match: " + match +"\n")
if not match in MODS:
MODS.append(match)
if verbose:
print("The module dependencies are:")
return MODS
def getFileModuleName(fileName):
print(fileName)
fileContents = open(fileName).read()
moduleNameMatch = re.compile('MODULE+.*', re.IGNORECASE)
matches = re.findall(moduleNameMatch, fileContents)
return matches[0].split(' ')[1]
"""@brief Creates a Makefile.am
Creates a Makefile.am in the path provided, resolving all the dependencies
"""
def writeModules(path):
os.chdir(path)
folder = path.split('/')[len(path.split('/'))-1]
makefile = open('Makefile.am', 'w')
fileList = os.listdir(path)
fortranMatch = re.compile('.*F90', re.IGNORECASE)
makefile.write("SUBDIRS = \ \n")
for file in fileList:
if not fortranMatch.match(file) and not os.path.isfile(file):
makefile.write("\t" + file + " \ \n")
makefile.write("\n\n")
makefile.write("noinst_LTLIBRARIES = lib" + folder + ".la\n")
makefile.write("lib" + folder +"_la_SOURCES = \ \n")
for file in fileList:
if fortranMatch.match(file):
makefile.write("\t" + file + " \ \n")
makefile.write("\n\n")
for file in fileList:
if fortranMatch.match(file):
makefile.write(getFileModuleName(file) + ".$(FC_MODEXT) : " + file.split('.')[0] + ".$(OBJEXT)\n")
makefile.write("\n\n")
for file in fileList:
print(file)
if fortranMatch.match(file):
makefile.write(file.split('.')[0] + ".$(OBJEXT) : \ \n")
for mod in getModules(file):
makefile.write("\t" + mod + ".$(FC_MODEXT) \ \n")
makefile.write("\n\n")
makefile.write("MODFILES = \ \n")
for file in fileList:
if fortranMatch.match(file):
for mod in getModules(file):
makefile.write("\t" + mod + ".$(FC_MODEXT) \ \n")
makefile.write("BUILT_SOURCES = $(MODFILES)\n")
makefile.write("include_HEADERS = $(MODFILES)\n")
makefile.write("\n\n")
makefile.write("CLEANFILES = *.$(FC_MODEXT)")
if __name__ == '__main__':
writeModules('/home/Diyor.Zakirov/atmos_param')