]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
scons update
[lilypond.git] / buildscripts / builder.py
1 # -*-python-*-
2
3 import glob
4 import os
5 import string
6
7 Import ('env')
8
9 # utility
10
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))
15
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)
23
24
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
31
32 Export ('src_glob')
33
34 def base_glob (s):
35         return map (lambda x: os.path.splitext (x)[0], src_glob (s))
36
37 Export ('base_glob')
38
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)
46
47 Export ('install')
48
49 def _fixme (s):
50         x = string.replace (s, '#', env['srcdir'])
51         x = string.replace (x, '@', env['absbuild'])
52         return x
53
54 # Clean separation between generic action + flags and actual
55 # configuration and flags in environment for this build.
56
57 # Generic builders could/should be part of SCons.
58
59
60 HH = Builder (action = 'bison -d -o ${TARGET.base}.cc $SOURCE',
61               suffix = '.hh', src_suffix = '.yy')
62 env.Append (BUILDERS = {'HH' : HH})
63
64
65 # Setup LilyPond environment.  For the LilyPond build, we override
66 # some of these commands in the ENVironment.
67
68 env.Append (
69         _fixme = _fixme,
70         ##ABC2LY = 'abc2ly',
71         ##LILYPOND = 'lilypond',
72         LILYOND_BOOK = 'lilypond-book',
73
74         #ugr
75         #LILYPOND_BOOK_FORMAT = 'texi',
76         LILYPOND_BOOK_FORMAT = '',
77         #LILYPOND_BOOK_FLAGS = ['--format=$LILYPOND_BOOK_FORMAT'],
78         LILYPOND_BOOK_FLAGS = '''--format=$LILYPOND_BOOK_FORMAT --process="lilypond --backend=eps --formats=ps,png --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'" ''',
79
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__)} $)',
84
85         MAKEINFO_PATH = [],
86         MAKEINFO_FLAGS = [],
87         MAKEINFO_INCFLAGS = '$( ${_concat(INCPREFIX, MAKEINFO_PATH, INCSUFFIX, __env__, RDirs)} $)',
88         # should not be necessary
89         # PYTHONPATH = ['$absbuild/python/$out'],
90         TEXI2DVI_FLAGS = [],
91         _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
92         )
93
94 TXT =\
95     Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS\
96     --no-split --no-headers $SOURCE',
97                suffix = '.txt', src_suffix = '.texi')
98 env.Append (BUILDERS = {'TXT': TXT})
99
100 INFO =\
101      Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
102               suffix = '.info', src_suffix = '.texi')
103 env.Append (BUILDERS = {'INFO': INFO})
104
105 HTML =\
106      Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCLUDES\
107      --html --no-split --no-headers $MAKEINFO_FLAGS $SOURCE',
108 suffix = '.html', src_suffix = '.texi')
109 env.Append (BUILDERS = {'HTML': HTML})
110
111 TEXI =\
112      Builder (action =
113               '$LILYPOND_BOOK --output=${TARGET.dir} \
114               --include=${TARGET.dir} $LILYPOND_INCFLAGS \
115               --process="$LILYPOND $LILYPOND_INCFLAGS" \
116               $LILYPOND_BOOK_FLAGS \
117               $SOURCE',
118               suffix = '.texi', src_suffix = '.tely')
119 env.Append (BUILDERS = {'TEXI': TEXI})
120
121 TEXIDVI =\
122         Builder (action = 'cd ${TARGET.dir} && \
123         texi2dvi --batch $_TEXI2DVI_FLAGS ${SOURCE.file}',
124                  suffix = '.dvi', src_suffix = '.texi')
125 env.Append (BUILDERS = {'TEXIDVI': TEXIDVI})
126
127 DVIPS =\
128       Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET $DVIPS_FLAGS $SOURCE',
129                suffix = '.ps', src_suffix = '.dvi')
130 env.Append (BUILDERS = {'DVIPS': DVIPS})
131
132 DVIPDF =\
133       Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
134                suffix = '.pdfps', src_suffix = '.dvi')
135 env.Append (BUILDERS = {'DVIPDF': DVIPDF})
136
137 PSPDF =\
138       Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
139                suffix = '.pdf', src_suffix = '.pdfps')
140 env.Append (BUILDERS = {'PSPDF': PSPDF})
141
142 PNG2EPS =\
143         Builder (action = 'convert $SOURCE $TARGET',
144                  suffix = '.eps', src_suffix = '.png')
145 env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
146
147
148
149 # FIXME: cleanup, see above
150
151
152 env.Append (
153
154         #urg
155         BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
156         BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
157 )
158
159
160 def add_ps_target (target, source, env):
161         base = os.path.splitext (str (target[0]))[0]
162         return (target + [base + '.ps'], source)
163
164 lilypond =\
165          Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
166                   suffix = '.pdf', src_suffix = '.ly')
167 ##                  emitter = add_ps_target)
168 env.Append (BUILDERS = {'LilyPond': lilypond})
169
170 ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
171                suffix = '.ly', src_suffix = '.abc')
172 env.Append (BUILDERS = {'ABC': ABC})
173
174 def add_log_target (target, source, env):
175         base = os.path.splitext (str (target[0]))[0]
176         return (target + [base + '.log'], source)
177
178 def add_tfm_target (target, source, env):
179         base = os.path.splitext (str (target[0]))[0]
180         return (target + [base + '.tfm'], source)
181
182 def add_lisp_enc_tex_ly_target (target, source, env):
183         base = os.path.splitext (str (target[0]))[0]
184         return (target + [base + '.lisp', base + '.enc', base + '.tex',
185                           base + 'list.ly'],
186                 source)
187
188 def add_cff_cffps_svg (target, source, env):
189         base = os.path.splitext (str (target[0]))[0]
190         return (target + [base + '.cff', base + '.cff.ps', base + '.svg'],
191                 source)
192
193 a = 'cd ${TARGET.dir} \
194 && MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
195 $MF "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
196 | grep -v "@\|>>\|w:\|h:";'
197 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
198 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
199                emitter = add_log_target)
200 env.Append (BUILDERS = {'TFM': tfm})
201
202 a = '$PYTHON $MF_TO_TABLE_PY \
203 --outdir=${TARGET.dir} \
204 --global-lisp=${TARGET.base}.otf-gtable \
205 --lisp=${TARGET.base}.lisp \
206 --enc=${TARGET.base}.enc \
207 --tex=${TARGET.base}.tex \
208 --ly=${TARGET.base}list.ly \
209 ${TARGET.base}.log'
210 gtable = Builder (action = a, suffix = '.otf-gtable', src_suffix = '.log',
211                   emitter = add_lisp_enc_tex_ly_target)
212 env.Append (BUILDERS = {'GTABLE': gtable})
213
214 def add_enc_src (target, source, env):
215         base = os.path.splitext (str (target[0]))[0]
216         return (target, source + [base + '.enc'])
217
218 # FIXME UGH, should fix --output option for mftrace
219 a = 'cd ${TARGET.dir} && \
220 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
221 MFINPUTS=$srcdir/mf:.: \
222 $MFTRACE --formats=pfa --simplify --keep-trying --no-afm \
223 $$encoding $__verbose \
224 --include=${TARGET.dir} \
225 ${SOURCE.file}'
226
227 pfa = Builder (action = a,
228                suffix = '.pfa',
229                src_suffix = '.mf',
230                emitter = add_enc_src)
231 env.Append (BUILDERS = {'PFA': pfa})
232
233 a = ['(cd ${TARGET.dir} && $FONTFORGE -script ${SOURCE.file})',
234      '$PYTHON $srcdir/buildscripts/ps-embed-cff.py ${SOURCE.base}.cff $$(cat ${SOURCE.base}.fontname) ${SOURCE.base}.cff.ps',
235      'rm -f ${TARGET.dir}/*.scale.pfa']
236 otf = Builder (action = a,
237                suffix = '.otf',
238                src_suffix = '.pe',
239                emitter = add_cff_cffps_svg)
240 env.Append (BUILDERS = {'OTF': otf})
241
242
243 # Specific builders
244
245 env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
246 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
247 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
248 env.Append (BUILDERS = {'PATCH': patch})
249
250 atvars = [
251 'BASH',
252 'DATE',
253 'sharedstatedir',
254 'GUILE',
255 'bindir',
256 'date',
257 'datadir',
258 'lilypond_datadir',
259 'lilypond_libdir',
260 'local_lilypond_datadir',
261 'local_lilypond_libdir',
262 'localedir',
263 'PACKAGE',
264 'package',
265 'PATHSEP',
266 'PERL',
267 'prefix',
268 'program_prefix',
269 'program_suffix',
270 'PYTHON',
271 'SHELL',
272 'TOPLEVEL_VERSION',
273 'step-bindir',
274 ]
275
276 # naming
277 def at_copy (target, source, env):
278     n = str (source[0])
279     s = open (n).read ()
280     for i in atvars:
281             if env.has_key (i):
282                     s = string.replace (s, '@%s@'% i, env[i])
283     t = str (target[0])
284     open (t, 'w').write (s)
285     # wugh
286     if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
287             os.chmod (t, 0755)
288
289 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
290 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
291
292 # naming
293 def at_copy_ext (target, source, env):
294     n = str (source[0])
295     s = open (n).read ()
296     for i in atvars:
297             if env.has_key (i):
298                     s = string.replace (s, '@%s@'% i, env[i])
299     # whugh
300     e = os.path.splitext (n)[1]
301     t = str (target[0]) + e
302     open (t, 'w').write (s)
303
304 AT_COPY_EXT = Builder (action = at_copy_ext, src_suffix = ['.py', '.sh',])
305 env.Append (BUILDERS = {'AT_COPY_EXT': AT_COPY_EXT})
306
307
308 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
309               suffix = '.mo', src_suffix = '.po')
310 env.Append (BUILDERS = {'MO': MO})
311
312 # ' '; ?
313 ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po ; '
314 a = ugh + 'xgettext --default-domain=lilypond --join \
315 --output-dir=${TARGET.dir} --add-comments \
316 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
317 PO = Builder (action = a, suffix = '.pot',
318               src_suffix = ['.cc', '.hh', '.py'], multi = 1)
319 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
320                                 'lilypond.pot')
321 env['pocommand'] = a
322
323 ugh = '; mv ${TARGET} ${SOURCE}'
324 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
325 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
326 env.Append (BUILDERS = {'POMERGE': POMERGE})
327
328 #UGRr
329 a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
330 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
331 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
332
333 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
334 --name=${TARGET.base} --title="$TITLE" $SOURCES'
335 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
336 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
337
338
339 def mutopia (ly = None, abc = None):
340
341         # FIXME: ugr, huh?  The values from ../SConstruct get appended
342         # to the predefined values from this builder context:
343
344         # abc2ly/usr/bin/python ..../abc2.py
345
346         # Override them again to fix web build...
347
348         
349         #BUILD_ABC2LY = '${set__x}$PYTHON $srcdir/scripts/abc2ly.py'
350         #BUILD_LILYPOND = '$absbuild/$out/lilypond ${__verbose}'
351         e = env.Copy (
352                 #LILYPOND = BUILD_LILYPOND,
353                 #ABC2LY = BUILD_ABC2LY,
354         )
355         
356         if not abc:
357                 abc = base_glob ('*.abc')
358         if not ly:
359                 ly = base_glob ('*.ly') + map (e.ABC, abc)
360         pdf = map (e.LilyPond, ly)
361         
362         # We need lily and mf to build these.
363         env.Depends (pdf, ['#/lily', '#/mf'])
364         env.Alias ('doc', pdf)
365
366 Export ('mutopia')
367
368
369 def collate (title = 'collated files'):
370         ly = base_glob ('*.ly')
371         
372         e = env.Copy (
373                 TITLE = title,
374                 LILYPOND_BOOK_FLAGS = '''--process="lilypond --backend=eps --formats=ps,png --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'" ''',
375                                                                                                                                        __verbose = ' --verbose',
376                                                                                                                                        )
377         #
378         tely = e.LYS2TELY ('collated-files', ly)
379         texi = e.TEXI (tely)
380         # We need lily and mf to build these.
381         env.Depends (texi, ['#/lily', '#/mf'])
382         dvi = e.TEXIDVI (texi)
383         pspdf = e.DVIPDF (dvi)
384         pdf = e.PSPDF (pspdf)
385         html = e.HTML (texi)
386
387         env.Alias ('doc', pdf)
388         env.Alias ('doc', html)
389
390 Export ('collate')
391
392 Export ('env')