5 # mf-deps.py -- dependencies for metafont
7 # source file of the GNU LilyPond music typesetter
9 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 """look into metafont source for dependencies.
16 fixme: error reporting
17 fixem: python sucks slightly: why doesn't it have closures?
26 lilypath
= os
.environ
['LILYPOND_SOURCEDIR'] + '/'
29 lilypath
= os
.environ
['top_srcdir'] + '/'
31 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
35 lilypath
= lilypath
+ '/bin/'
36 sys
.path
.append(lilypath
)
39 from regsub
import * ;
45 input_re
= compile('^[ \t]*input *\([^;]+\);')
46 postfixes
= ['log', 'dvi', '2602gf', 'tfm']
49 return "mf-deps.py %s" % version
60 """Dependencies for one toplevel sourcefile
64 def __init__(self
,nm
):
65 split
= os
.path
.splitext(nm
)
66 self
.basename
=split
[0];
70 def checkdep(self
, name
):
71 split
= os
.path
.splitext(name
)
72 name
= split
[0] + '.mf';
74 if name
not in self
.depfiles
:
75 self
.get_filedeps(name
)
77 def get_filedeps(self
,filename
):
78 # print sys.stderr.write( 'checking ' + filename + '\n');
82 # print sys.stderr.write( 'can\'t open ' + filename + '\n')
85 self
.depfiles
.append(filename
)
86 lines
= file.readlines()
89 if input_re
.search (line
) <> -1:
90 self
.checkdep( input_re
.group(1))
92 def target_string(self
):
93 # ugh. Closures, anyone?
94 # targets = map (lambda x,y = self.basename: 'out/' + y + '.' + x, postfixes)
95 targets
= map (lambda x
,y
= self
.basename
: y
+ '.' + x
, postfixes
)
96 depstring
= reduce(lambda x
,y
: x
+ ' ' + y
, self
.depfiles
)
97 dependencies
= map (lambda x
, y
=depstring
: x
+ ': ' + y
, targets
)
99 return reduce(line_concat
, dependencies
)
101 print "# Automatically generated by %s\n" % identify ()
103 for file in sys
.argv
[1:]: # skip programname
105 print t
.target_string()