summaryrefslogtreecommitdiff
path: root/script/make_depend.py
blob: 15c656eef6924ca5dd3a0f17c040d010ae1f1be8 (plain)
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
#!/bin/env python
""" generation of module dependances for a xxx.f90 or xxx.F90 file """

import string,sys
from subprocess import Popen, PIPE

def noComment(mot):
    """ remove comment characters in a word """
    ind= string.find(mot,'!')
    if ind != -1:
        mot= mot[:ind]
    return mot

class md9:
    """ a file, its module and its dependances """
    def __init__(self,fic):
        self.name= fic
        self.used= []
        #find all module dependances
        listeLignes= open(self.name,'r').readlines()
        self.module= "dummy"
        for ligne in listeLignes:
            ligne= string.lower(ligne)
            if string.count(ligne,'use'):
                ligne= string.replace(ligne,',',' ')
                listeMots= string.split(ligne)
                if listeMots[0] == 'use':
                    mod= noComment(listeMots[1])
                    if mod not in self.used and mod != 'intrinsic':
                        self.used.append(mod)
            elif string.count(ligne,'module'):
                listeMots= string.split(ligne)
                if listeMots[0] == 'module' and \
                   noComment(listeMots[1]) != 'procedure':
                    self.module= listeMots[1]
    def utilise(self,other):
        return (other.module in self.used)

listeClasse= list()
for x in sys.argv[1:]:
    if x.endswith('.f90') or x.endswith('.F90') : listeClasse.append(md9(x))
#sort the file list
listeRes= []
while listeClasse:
    lgav= len(listeClasse)
    for fic in listeClasse:
        if len(filter(lambda x,y=fic:y.utilise(x),listeClasse)) == 0:
            listeRes.append(fic)
            listeClasse.remove(fic)
    lgap= len(listeClasse)
    if lgav == lgap and lgap != 0:
        raise RuntimeError("make_depend: cross-references found")
#result output
resstr=''
for fic in listeRes:
    resstr=resstr+fic.name+' '
print resstr