4 # mf-deps.py -- dependencies for metafont
6 # source file of the GNU LilyPond music typesetter
8 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
12 """look into metafont source for dependencies.
15 fixme: error reporting
16 fixem: python sucks slightly: why doesn't it have closures?
21 from regsub
import * ;
25 input_re
= compile('^[ \t]*input *\([^;]+\);')
26 postfixes
= ['log', 'dvi', '2602gf', 'tfm']
36 """Dependencies for one toplevel sourcefile
40 def __init__(self
,nm
):
41 split
= os
.path
.splitext(nm
)
42 self
.basename
=split
[0];
46 def checkdep(self
, name
):
47 split
= os
.path
.splitext(name
)
48 name
= split
[0] + '.mf';
50 if name
not in self
.depfiles
:
51 self
.get_filedeps(name
)
53 def get_filedeps(self
,filename
):
54 # print sys.stderr.write( 'checking ' + filename + '\n');
58 # print sys.stderr.write( 'can\'t open ' + filename + '\n')
61 self
.depfiles
.append(filename
)
62 lines
= file.readlines()
65 if input_re
.search (line
) <> -1:
66 self
.checkdep( input_re
.group(1))
68 def target_string(self
):
69 # ugh. Closures, anyone?
70 targets
= map (lambda x
,y
= self
.basename
: 'out/' + y
+ '.' + x
, postfixes
)
71 depstring
= reduce(lambda x
,y
: x
+ ' ' + y
, self
.depfiles
)
72 dependencies
= map (lambda x
, y
=depstring
: x
+ ': ' + y
, targets
)
74 return reduce(line_concat
, dependencies
)
78 for file in sys
.argv
[1:]: # skip programname
80 print t
.target_string()