* lily/accidental-engraver.cc (process_acknowledged_grobs):
[lilypond.git] / buildscripts / builder.py
blob730a96674334f225bf7a43044c310f3207865109
1 # -*-python-*-
3 import glob
4 import os
5 import string
7 Import ('env')
9 # utility
11 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
12 base = os.path.splitext (str (target[0]))[0]
13 return (target + map (lambda x: base + x, target_suffixes),
14 source + map (lambda x: base + x, src_suffixes))
16 # junkme; see _concat
17 def join_path (path, infix=os.pathsep, prefix = ''):
18 def dir (x):
19 if x and x[0] == '#':
20 return env['srcdir'] + x[1:]
21 return x
22 return string.join (map (lambda x: prefix + dir (x), path), infix)
25 def src_glob (s):
26 here = os.getcwd ()
27 os.chdir (env.Dir ('.').srcnode ().abspath)
28 result = glob.glob (s)
29 os.chdir (here)
30 return result
32 Export ('src_glob')
34 def base_glob (s):
35 return map (lambda x: os.path.splitext (x)[0], src_glob (s))
37 Export ('base_glob')
39 def install (target, dir):
40 dest = env['DESTDIR'] + dir
41 if type (target) == type ([]):
42 map (lambda x: env.Install (dir, x), target)
43 else:
44 env.Install (dir, target)
45 env.Alias ('install', dir)
47 Export ('install')
49 def _fixme (s):
50 x = string.replace (s, '#', env['srcdir'])
51 x = string.replace (x, '@', env['absbuild'])
52 return x
54 # Clean separation between generic action + flags and actual
55 # configuration and flags in environment for this build.
57 # Generic builders could/should be part of SCons.
60 HH = Builder (action = 'bison -d -o ${TARGET.base}.cc $SOURCE',
61 suffix = '.hh', src_suffix = '.yy')
62 env.Append (BUILDERS = {'HH' : HH})
65 # Setup LilyPond environment. For the LilyPond build, we override
66 # some of these commands in the ENVironment.
68 env.Append (
69 _fixme = _fixme,
70 ABC2LY = 'abc2ly',
71 LILYPOND = 'lilypond',
72 LILYPOND_BIN = 'lilypond-bin',
73 LILYOND_BOOK = 'lilypond-book',
75 #ugr
76 #LILYPOND_BOOK_FORMAT = 'texi',
77 LILYPOND_BOOK_FORMAT = '',
78 LILYPOND_BOOK_FLAGS = ['--format=$LILYPOND_BOOK_FORMAT'],
80 LILYPOND_PATH = [],
81 # The SCons way around FOO_PATH:
82 ##LILYPOND_INCFLAGS = '$( ${_concat(INCPREFIX, LILYPOND_PATH, INCSUFFIX, __env__, RDirs)} $)',
83 LILYPOND_INCFLAGS = '$( ${_concat(INCPREFIX, LILYPOND_PATH, INCSUFFIX, __env__)} $)',
85 MAKEINFO_PATH = [],
86 MAKEINFO_FLAGS = [],
87 MAKEINFO_INCFLAGS = '$( ${_concat(INCPREFIX, MAKEINFO_PATH, INCSUFFIX, __env__, RDirs)} $)',
89 TEXI2DVI_FLAGS = [],
90 _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
93 TXT =\
94 Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS\
95 --no-split --no-headers $SOURCE',
96 suffix = '.txt', src_suffix = '.texi')
97 env.Append (BUILDERS = {'TXT': TXT})
99 INFO =\
100 Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
101 suffix = '.info', src_suffix = '.texi')
102 env.Append (BUILDERS = {'INFO': INFO})
104 HTML =\
105 Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCLUDES\
106 --html --no-split --no-headers $MAKEINFO_FLAGS $SOURCE',
107 suffix = '.html', src_suffix = '.texi')
108 env.Append (BUILDERS = {'HTML': HTML})
110 TEXI =\
111 Builder (action =
112 '$LILYPOND_BOOK --output=${TARGET.dir} \
113 --include=${TARGET.dir} $LILYPOND_INCFLAGS \
114 --process="$LILYPOND_BIN $LILYPOND_INCFLAGS" \
115 $LILYPOND_BOOK_FLAGS \
116 $SOURCE',
117 suffix = '.texi', src_suffix = '.tely')
118 env.Append (BUILDERS = {'TEXI': TEXI})
120 TEXIDVI =\
121 Builder (action = 'cd ${TARGET.dir} && \
122 texi2dvi --batch $_TEXI2DVI_FLAGS ${SOURCE.file}',
123 suffix = '.dvi', src_suffix = '.texi')
124 env.Append (BUILDERS = {'TEXIDVI': TEXIDVI})
126 DVIPS =\
127 Builder (action = 'dvips -o $TARGET $DVIPS_FLAGS $SOURCE',
128 suffix = '.ps', src_suffix = '.dvi')
129 env.Append (BUILDERS = {'DVIPS': DVIPS})
131 DVIPDF =\
132 Builder (action = 'dvips -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
133 suffix = '.pdfps', src_suffix = '.dvi')
134 env.Append (BUILDERS = {'DVIPDF': DVIPDF})
136 PSPDF =\
137 Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
138 suffix = '.pdf', src_suffix = '.pdfps')
139 env.Append (BUILDERS = {'PSPDF': PSPDF})
141 PNG2EPS =\
142 Builder (action = 'convert $SOURCE $TARGET',
143 suffix = '.eps', src_suffix = '.png')
144 env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
150 # FIXME: cleanup, see above
153 env.Append (
155 #urg
156 BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
157 BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
161 def add_ps_target (target, source, env):
162 base = os.path.splitext (str (target[0]))[0]
163 return (target + [base + '.ps'], source)
165 # TODO:
166 # FIXME: INCLUDES, FLAGS, use LILYPOND_BIN for building ?
167 lilypond =\
168 Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
169 suffix = '.pdf', src_suffix = '.ly')
170 ## emitter = add_ps_target)
171 env.Append (BUILDERS = {'LilyPond': lilypond})
173 ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
174 suffix = '.ly', src_suffix = '.abc')
175 env.Append (BUILDERS = {'ABC': ABC})
177 def add_log_target (target, source, env):
178 base = os.path.splitext (str (target[0]))[0]
179 return (target + [base + '.log'], source)
181 def add_enc_ly_tex_target (target, source, env):
182 base = os.path.splitext (str (target[0]))[0]
183 return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
184 source)
185 a = 'cd ${TARGET.dir} && \
186 MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
187 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
188 | grep -v "@\|>>"'
189 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
190 # emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
191 emitter = add_log_target)
192 env.Append (BUILDERS = {'TFM': tfm})
194 a = '$PYTHON $MF_TO_TABLE_PY \
195 --outdir=${TARGET.dir} \
196 --afm=${TARGET.base}.afm \
197 --enc=${TARGET.base}.enc \
198 --tex=${TARGET.base}.tex \
199 --ly=${TARGET.base}list.ly \
200 ${TARGET.base}.log'
201 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
202 emitter = add_enc_ly_tex_target)
203 env.Append (BUILDERS = {'AFM': afm})
205 def add_enc_src (target, source, env):
206 base = os.path.splitext (str (target[0]))[0]
207 return (target, source + [base + '.enc'])
209 # UGH, should fix --output option for mftrace
210 # mftrace --verbose is too verbose
211 a = 'cd ${TARGET.dir} && \
212 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
213 MFINPUTS=$srcdir/mf:.: \
214 mftrace --pfa --simplify --keep-trying $$encoding $TOO__verbose \
215 --include=${TARGET.dir} \
216 ${SOURCE.file}'
218 pfa = Builder (action = a,
219 suffix = '.pfa',
220 src_suffix = '.mf',
221 emitter = add_enc_src)
222 env.Append (BUILDERS = {'PFA': pfa})
224 # Specific builders
225 env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
226 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
227 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
228 env.Append (BUILDERS = {'PATCH': patch})
230 atvars = [
231 'BASH',
232 'DATE',
233 'sharedstatedir',
234 'GUILE',
235 'bindir',
236 'date',
237 'datadir',
238 'lilypond_datadir',
239 'lilypond_libdir',
240 'local_lilypond_datadir',
241 'local_lilypond_libdir',
242 'localedir',
243 'PACKAGE',
244 'package',
245 'PATHSEP',
246 'PERL',
247 'prefix',
248 'program_prefix',
249 'program_suffix',
250 'PYTHON',
251 'SHELL',
252 'TOPLEVEL_VERSION',
253 'step-bindir',
256 # naming
257 def at_copy (target, source, env):
258 s = open (str (source[0])).read ()
259 for i in atvars:
260 if env.has_key (i):
261 s = string.replace (s, '@%s@'% i, env[i])
262 t = str (target[0])
263 open (t, 'w').write (s)
264 # wugh
265 if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
266 os.chmod (t, 0755)
268 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
269 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
271 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
272 suffix = '.mo', src_suffix = '.po')
273 env.Append (BUILDERS = {'MO': MO})
275 ugh = 'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po; '
276 a = ugh + 'xgettext --default-domain=lilypond --join \
277 --output-dir=${TARGET.dir} --add-comments \
278 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
279 PO = Builder (action = a, suffix = '.pot',
280 src_suffix = ['.cc', '.hh', '.py'], multi = 1)
281 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
282 'lilypond.pot')
283 env['pocommand'] = a
285 ugh = '; mv ${TARGET} ${SOURCE}'
286 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
287 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
288 env.Append (BUILDERS = {'POMERGE': POMERGE})
290 #UGRr
291 a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
292 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
293 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
295 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
296 --name=${TARGET.base} --title="$TITLE" $SOURCES'
297 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
298 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
301 def mutopia (ly = None, abc = None):
303 # FIXME: ugr, huh? The values from ../SConstruct get appended
304 # to the predefined values from this builder context:
306 # abc2ly/usr/bin/python ..../abc2.py
308 # Override them again to fix web build...
311 BUILD_ABC2LY = '${set__x}$PYTHON $srcdir/scripts/abc2ly.py'
312 BUILD_LILYPOND = '${set__x}$PYTHON $srcdir/scripts/lilypond.py${__verbose}'
313 e = env.Copy (
314 LILYPOND = BUILD_LILYPOND,
315 ABC2LY = BUILD_ABC2LY,
318 if not abc:
319 abc = base_glob ('*.abc')
320 if not ly:
321 ly = base_glob ('*.ly') + map (e.ABC, abc)
322 pdf = map (e.LilyPond, ly)
324 # We need lily and mf to build these.
325 env.Depends (pdf, ['#/lily', '#/mf'])
326 env.Alias ('doc', pdf)
328 Export ('mutopia')
331 def collate (title = 'collated files'):
332 ly = base_glob ('*.ly')
334 e = env.Copy (
335 TITLE = title,
336 LILYPOND_BOOK_FLAGS = '''--process="lilypond-bin --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'"''',
337 __verbose = ' --verbose',
340 tely = e.LYS2TELY ('collated-files', ly)
341 texi = e.TEXI (tely)
342 # We need lily and mf to build these.
343 env.Depends (texi, ['#/lily', '#/mf'])
344 dvi = e.TEXIDVI (texi)
345 pspdf = e.DVIPDF (dvi)
346 pdf = e.PSPDF (pspdf)
347 html = e.HTML (texi)
349 env.Alias ('doc', pdf)
350 env.Alias ('doc', html)
352 Export ('collate')
354 Export ('env')