9 def verbose_opt (env, opt):
14 srcdir = env['srcdir']
16 def join_path (path, infix=os.pathsep, prefix = ''):
21 return string.join (map (lambda x: prefix + dir (x), path), infix)
23 verbose = verbose_opt (env, ' --verbose')
24 MAKEINFO_INCLUDES = join_path (env['MAKEINFO_PATH'], '', ' -I')
25 MAKEINFO = env['MAKEINFO']
26 a = ('%(MAKEINFO)s%(verbose)s %(MAKEINFO_INCLUDES)s'\
27 ' --no-split --no-headers --output=$TARGET $SOURCE') % vars ()
28 texi2txt = Builder (action = a, suffix = '.txt', src_suffix = '.texi')
29 env.Append (BUILDERS = {'Texi2txt': texi2txt})
32 PYTHON = env['PYTHON']
33 ABC2LY_PY = env['ABC2LY_PY']
34 LILYPOND_PY = env['LILYPOND_PY']
35 LILYPOND_BIN = env['LILYPOND_BIN']
36 LILYPOND_BOOK = env['LILYPOND_BOOK']
37 LILYPOND_BOOK_FLAGS = env['LILYPOND_BOOK_FLAGS']
38 LILYPOND_BOOK_FORMAT = env['LILYPOND_BOOK_FORMAT']
39 LILYPOND_BOOK_INCLUDES = join_path (env['LILYPOND_BOOK_PATH'], '',
41 LILYPONDPREFIX = env['LILYPONDPREFIX']
43 # UGHR, lilypond.py uses lilypond-bin from PATH
44 #env.Append (ENV = {'PATH' : os.environ['PATH']})
45 env.PrependENVPath ('PATH',
46 os.path.join (env['absbuild'], env['out'], 'usr/bin'))
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 if os.environ.has_key ('LD_LIBRARY_PATH'):
54 env.Append (ENV = {'LD_LIBRARY_PATH' : os.environ['LD_LIBRARY_PATH']})
55 if os.environ.has_key ('GUILE_LOAD_PATH'):
56 env.Append (ENV = {'GUILE_LOAD_PATH' : os.environ['GUILE_LOAD_PATH']})
58 env.Append (PYTHONPATH = [os.path.join (env['absbuild'], env['out'],
60 os.path.join (srcdir, 'buildscripts'),
61 os.path.join (srcdir, 'python')])
62 env.Append (ENV = { 'PYTHONPATH' : string.join (env['PYTHONPATH'],
65 verbose = verbose_opt (env, ' --verbose')
66 a = (r'''rm -f $$(grep -LF '\lilypondend' ${TARGET.dir}/lily-*.tex 2>/dev/null); ''' \
67 + 'LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
68 + '%(PYTHON)s %(LILYPOND_BOOK)s%(verbose)s'\
69 + ' --include=${TARGET.dir} %(LILYPOND_BOOK_INCLUDES)s'\
70 + r""" --process='%(LILYPOND_BIN)s %(LILYPOND_BOOK_INCLUDES)s'"""\
71 + ' --output=${TARGET.dir} --format=%(LILYPOND_BOOK_FORMAT)s\
72 %(LILYPOND_BOOK_FLAGS)s\
74 tely2texi = Builder (action = a, suffix = '.texi', src_suffix = '.tely')
75 env.Append (BUILDERS = {'Tely2texi': tely2texi})
77 TEXINFO_PAPERSIZE_OPTION = env['TEXINFO_PAPERSIZE_OPTION']
78 a = '(cd ${TARGET.dir} &&\
79 texi2dvi --batch %(TEXINFO_PAPERSIZE_OPTION)s ${SOURCE.file})' % vars ()
80 texi2dvi = Builder (action = a, suffix = '.dvi', src_suffix = '.texi')
81 env.Append (BUILDERS = {'Texi2dvi': texi2dvi})
83 env.Append (DVIPSFLAGS = '-Ppdf -u+lilypond.map -u+ec-mftrace.map')
85 DVIPS_PAPERSIZE = 'a4'
86 DVIPSFLAGS = env['DVIPSFLAGS']
87 a = ('set -x; dvips %(DVIPSFLAGS)s' \
88 + ' -o ${TARGET}.pdfps'\
89 + ' -t %(DVIPS_PAPERSIZE)s $SOURCE &&'\
90 + ' ps2pdf -sPAPERSIZE=%(DVIPS_PAPERSIZE)s ${TARGET}.pdfps $TARGET') \
92 dvi2pdf = Builder (action = a, suffix = '.pdf', src_suffix = '.dvi')
93 env.Append (BUILDERS = {'Dvi2pdf': dvi2pdf})
95 a = 'convert $SOURCE $TARGET'
96 png2eps = Builder (action = a, suffix = '.eps', src_suffix = '.png')
97 env.Append (BUILDERS = {'Png2eps': png2eps})
99 def add_ps_target (target, source, env):
100 base = os.path.splitext (str (target[0]))[0]
101 return (target + [base + '.ps'], source)
103 #a = ('echo "PATH=$$PATH"; echo "TEXMF=$$TEXMF"; which lilypond-bin;'\
104 a = (' LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
105 + '%(PYTHON)s %(LILYPOND_PY)s%(verbose)s'\
106 + ' --include=${TARGET.dir}'\
107 + ' --output=${TARGET.base}'\
108 + ' $SOURCE') % vars ()
109 lilypond = Builder (action = a, suffix = '.pdf', src_suffix = '.ly')
110 ## emitter = add_ps_target)
111 env.Append (BUILDERS = {'LilyPond': lilypond})
113 #verbose = verbose_opt (env, ' --verbose')
115 a = ('LILYPONDPREFIX=%(LILYPONDPREFIX)s '\
116 + '%(PYTHON)s %(ABC2LY_PY)s%(verbose)s'\
117 # + ' --include=${TARGET.dir}'\
119 + ' --output=${TARGET.base}'\
120 + ' $SOURCE') % vars ()
121 abc2ly = Builder (action = a, suffix = '.ly', src_suffix = '.abc')
122 env.Append (BUILDERS = {'Abc2ly': abc2ly})
125 MFMODE = env['MFMODE']
126 def add_log_target (target, source, env):
127 base = os.path.splitext (str (target[0]))[0]
128 return (target + [base + '.log'], source)
130 def add_enc_ly_tex_target (target, source, env):
131 base = os.path.splitext (str (target[0]))[0]
132 return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
135 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
136 base = os.path.splitext (str (target[0]))[0]
137 return (target + map (lambda x: base + x, target_suffixes),
138 source + map (lambda x: base + x, src_suffixes))
140 scrdir = env['srcdir']
141 a = ('(cd ${TARGET.dir} &&'\
142 + ' MFINPUTS=.:${SOURCE.dir}:%(srcdir)s/${SOURCE.dir}'\
143 + ' mf "\\mode:=%(MFMODE)s; nonstopmode;'\
144 + ' input ${SOURCE.filebase};" ' \
145 + ' | grep -v "@\|>>")') % vars ()
146 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
147 # emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
148 emitter = add_log_target)
149 env.Append (BUILDERS = {'TFM': tfm})
151 MF_TO_TABLE_PY = env['MF_TO_TABLE_PY']
152 #verbose = verbose_opt (env, ' --verbose')
154 a = ('%(PYTHON)s %(MF_TO_TABLE_PY)s%(verbose)s'\
155 + ' --outdir=${TARGET.dir}'\
156 + ' --afm=${TARGET.base}.afm' \
157 + ' --enc=${TARGET.base}.enc' \
158 + ' --tex=${TARGET.base}.tex' \
159 + ' --ly=${TARGET.base}list.ly'\
160 + ' ${TARGET.base}.log') % vars ()
161 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
162 emitter = add_enc_ly_tex_target)
163 env.Append (BUILDERS = {'AFM': afm})
165 def add_enc_src (target, source, env):
166 base = os.path.splitext (str (target[0]))[0]
167 return (target, source + [base + '.enc'])
169 def encoding_opt (target):
170 base = os.path.splitext (os.path.basename (str (target[0])))[0]
172 if os.path.exists (os.path.join (outdir, enc)):
173 return ' --encoding=' + enc
176 # UGH, should fix --output option for mftrace
177 verbose = verbose_opt (env, ' --verbose')
178 a = ('(cd ${TARGET.dir} && '
179 + ' if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi;' \
180 # + ' MFINPUTS=.:${TARGET.dir}:${SOURCE.dir}'\
182 + ' MFINPUTS=%(srcdir)s/mf}:.:'\
183 + ' mftrace --pfa --simplify --keep-trying $$encoding%(verbose)s'\
184 + ' --include=${TARGET.dir}'\
185 + ' ${SOURCE.file})') % vars ()
187 pfa = Builder (action = a,
190 emitter = add_enc_src)
191 env.Append (BUILDERS = {'PFA': pfa})
194 #verbose = verbose_opt (env, ' --verbose')
196 DIFF_PY = os.path.join (srcdir, 'stepmake/bin/package-diff.py')
198 a = ('%(PYTHON)s %(DIFF_PY)s%(verbose)s'\
199 + ' --outdir=${TARGET.dir}') % vars ()
200 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
201 env.Append (BUILDERS = {'PATCH': patch})
204 def ln (target, source, env):
205 base = os.path.splitext (source[0].name)[0]
206 suf = os.path.splitext (str (source[0]))[1]
208 target = [target[0].path + suf,]
209 source = [re.sub ('/' + env['out'] + '/', '/', base + suf)]
210 return (target, source)
212 def baller (dir_name, sources, env):
213 ballprefix = os.path.join (env['ballprefix'], dir_name)
214 ball = Builder (prefix = ballprefix + '/',
215 action = 'ln $SOURCE $TARGET',
217 et = env.Copy (BUILDERS = {'BALL': ball})
218 ballize = map (et.BALL, sources)
219 return env.Tar (env['tarball'],
220 map (lambda x: os.path.join (ballprefix, x), sources))
222 env['baller'] = baller