8 def verbose_opt (env, opt):
13 srcdir = env['srcdir']
15 def join_path (path, infix=os.pathsep, prefix = ''):
20 return string.join (map (lambda x: prefix + dir (x), path), infix)
22 verbose = verbose_opt (env, ' --verbose')
23 MAKEINFO_INCLUDES = join_path (env['MAKEINFO_PATH'], '', ' -I')
24 MAKEINFO = env['MAKEINFO']
25 a = ('%(MAKEINFO)s%(verbose)s %(MAKEINFO_INCLUDES)s'\
26 ' --no-split --no-headers --output=$TARGET $SOURCE') % vars ()
27 texi2txt = Builder (action = a, suffix = '.txt', src_suffix = '.texi')
28 env.Append (BUILDERS = {'Texi2txt': texi2txt})
31 PYTHON = env['PYTHON']
32 ABC2LY_PY = env['ABC2LY_PY']
33 LILYPOND_PY = env['LILYPOND_PY']
34 LILYPOND_BIN = env['LILYPOND_BIN']
35 LILYPOND_BOOK = env['LILYPOND_BOOK']
36 LILYPOND_BOOK_FLAGS = env['LILYPOND_BOOK_FLAGS']
37 LILYPOND_BOOK_FORMAT = env['LILYPOND_BOOK_FORMAT']
38 LILYPOND_BOOK_INCLUDES = join_path (env['LILYPOND_BOOK_PATH'], '',
40 LILYPONDPREFIX = env['LILYPONDPREFIX']
42 env.Append (ENV = {'PATH' : os.environ['PATH']})
43 if os.environ.has_key ('LD_LIBRARY_PATH'):
44 env.Append (ENV = {'LD_LIBRARY_PATH' : os.environ['LD_LIBRARY_PATH']})
45 if os.environ.has_key ('GUILE_LOAD_PATH'):
46 env.Append (ENV = {'GUILE_LOAD_PATH' : os.environ['GUILE_LOAD_PATH']})
48 if os.environ.has_key ('TEXMF'):
49 env.Append (ENV = {'TEXMF' : os.environ['TEXMF']})
50 env.Append (ENV = {'TEXMF' : '{' + LILYPONDPREFIX + ',' \
51 + os.popen ('kpsexpand \$TEXMF').read ()[:-1] + '}' })
53 verbose = verbose_opt (env, ' --verbose')
54 a = (r'''rm -f $$(grep -LF '\lilypondend' ${TARGET.dir}/lily-*.tex 2>/dev/null); ''' \
55 + 'LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
56 + '%(PYTHON)s %(LILYPOND_BOOK)s%(verbose)s'\
57 + ' --include=${TARGET.dir} %(LILYPOND_BOOK_INCLUDES)s'\
58 + r""" --process='%(LILYPOND_BIN)s %(LILYPOND_BOOK_INCLUDES)s'"""\
59 + ' --output=${TARGET.dir} --format=%(LILYPOND_BOOK_FORMAT)s\
60 %(LILYPOND_BOOK_FLAGS)s\
62 tely2texi = Builder (action = a, suffix = '.texi', src_suffix = '.tely')
63 env.Append (BUILDERS = {'Tely2texi': tely2texi})
65 TEXINFO_PAPERSIZE_OPTION = env['TEXINFO_PAPERSIZE_OPTION']
66 a = '(cd ${TARGET.dir} &&\
67 texi2dvi --batch %(TEXINFO_PAPERSIZE_OPTION)s ${SOURCE.file})' % vars ()
68 texi2dvi = Builder (action = a, suffix = '.dvi', src_suffix = '.texi')
69 env.Append (BUILDERS = {'Texi2dvi': texi2dvi})
71 env.Append (DVIPSFLAGS = '-Ppdf -u+lilypond.map -u+ec-mftrace.map')
73 DVIPS_PAPERSIZE = 'a4'
74 DVIPSFLAGS = env['DVIPSFLAGS']
75 a = ('set -x; dvips %(DVIPSFLAGS)s' \
76 + ' -o ${TARGET}.pdfps'\
77 + ' -t %(DVIPS_PAPERSIZE)s $SOURCE &&'\
78 + ' ps2pdf -sPAPERSIZE=%(DVIPS_PAPERSIZE)s ${TARGET}.pdfps $TARGET') \
80 dvi2pdf = Builder (action = a, suffix = '.pdf', src_suffix = '.dvi')
81 env.Append (BUILDERS = {'Dvi2pdf': dvi2pdf})
83 a = 'convert $SOURCE $TARGET'
84 png2eps = Builder (action = a, suffix = '.eps', src_suffix = '.png')
85 env.Append (BUILDERS = {'Png2eps': png2eps})
87 def add_ps_target (target, source, env):
88 base = os.path.splitext (str (target[0]))[0]
89 return (target + [base + '.ps'], source)
91 a = ('LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
92 + '%(PYTHON)s %(LILYPOND_PY)s%(verbose)s'\
93 + ' --include=${TARGET.dir}'\
94 + ' --output=${TARGET.base}'\
95 + ' $SOURCE') % vars ()
96 lilypond = Builder (action = a, suffix = '.pdf', src_suffix = '.ly')
97 ## emitter = add_ps_target)
98 env.Append (BUILDERS = {'LilyPond': lilypond})
100 verbose = verbose_opt (env, ' --verbose')
101 a = ('LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
102 + '%(PYTHON)s %(ABC2LY_PY)s%(verbose)s'\
103 + ' --include=${TARGET.dir}'\
104 + ' --output=${TARGET.base}'\
105 + ' $SOURCE') % vars ()
106 abc2ly = Builder (action = a, suffix = '.ly', src_suffix = '.abc')
107 env.Append (BUILDERS = {'Abc2ly': abc2ly})
110 MFMODE = env['MFMODE']
111 def add_log_target (target, source, env):
112 base = os.path.splitext (str (target[0]))[0]
113 return (target + [base + '.log'], source)
115 def add_enc_ly_tex_target (target, source, env):
116 base = os.path.splitext (str (target[0]))[0]
117 return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
120 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
121 base = os.path.splitext (str (target[0]))[0]
122 return (target + map (lambda x: base + x, target_suffixes),
123 source + map (lambda x: base + x, src_suffixes))
125 #outdir = os.path.join (env['build'], reldir, env['out'])
126 outdir = '${TARGET.dir}'
127 scrdir = env['srcdir']
128 #MFINPUTS = '.:' + str (Dir ('#/mf'))
129 #MFINPUTS = '.:${SOURCE.dir}'
130 a = ('(cd ${TARGET.dir} &&'\
131 # + ' MFINPUTS=.:${SOURCE.dir}'\
132 + ' MFINPUTS=.:${SOURCE.dir}:%(srcdir)s/${SOURCE.dir}'\
133 + ' mf "\\mode:=%(MFMODE)s; nonstopmode;'\
134 + ' input ${SOURCE.filebase};" ' \
135 + ' | grep -v "@\|>>")') % vars ()
136 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
137 # emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
138 emitter = add_log_target)
139 env.Append (BUILDERS = {'TFM': tfm})
141 MF_TO_TABLE_PY = env['MF_TO_TABLE_PY']
142 #verbose = verbose_opt (env, ' --verbose')
144 a = ('%(PYTHON)s %(MF_TO_TABLE_PY)s%(verbose)s'\
145 + ' --outdir=${TARGET.dir}'\
146 + ' --afm=${TARGET.base}.afm' \
147 + ' --enc=${TARGET.base}.enc' \
148 + ' --tex=${TARGET.base}' \
149 + ' --ly=${TARGET.base}list.ly'\
150 + ' ${TARGET.base}.log') % vars ()
151 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
152 emitter = add_enc_ly_tex_target)
153 env.Append (BUILDERS = {'AFM': afm})
155 def add_enc_src (target, source, env):
156 base = os.path.splitext (str (target[0]))[0]
157 return (target, source + [base + '.enc'])
159 def encoding_opt (target):
160 base = os.path.splitext (os.path.basename (str (target[0])))[0]
162 if os.path.exists (os.path.join (outdir, enc)):
163 return ' --encoding=' + enc
166 # UGH, should fix --output option for mftrace
167 xpfa = Builder (action = ('MFINPUTS=.:' + str (Dir ('#/mf')) \
168 + ' mftrace -I %(outdir)s --pfa' \
169 + ' --simplify --keep-trying' \
170 + ' ${SOURCE.filebase} ' \
171 + ' && mv ${TARGET.filebase} $TARGET') % vars (),
174 emitter = add_enc_src)
176 verbose = verbose_opt (env, ' --verbose')
177 def run_mftrace (target, source, env):
180 mf = os.path.basename (str (source[0]))
181 base = os.path.splitext (os.path.basename (str (target[0])))[0]
183 mfdir = os.path.join (here, reldir)
184 outdir = os.path.join (env['build'], reldir, env['out'])
185 encoding = encoding_opt (target)
186 command = ('(cd ${TARGET.dir} && '
187 + ' MFINPUTS=.:${TARGET.dir}:' + mfdir\
188 + ' mftrace --pfa --simplify --keep-trying%(verbose)s'\
189 + ' --include=${TARGET.dir}'\
190 + ' %(encoding)s %(mf)s)') % vars ()
191 return os.system (command)
193 pfa = Builder (action = run_mftrace, suffix = '.pfa', src_suffix = '.mf',
194 emitter = add_enc_src)
195 env.Append (BUILDERS = {'PFA': pfa})