]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
*** empty log message ***
[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         LILYPOND_BIN = 'lilypond-bin',
73         LILYOND_BOOK = 'lilypond-book',
74
75         #ugr
76         #LILYPOND_BOOK_FORMAT = 'texi',
77         LILYPOND_BOOK_FORMAT = '',
78         LILYPOND_BOOK_FLAGS = ['--format=$LILYPOND_BOOK_FORMAT'],
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
89         TEXI2DVI_FLAGS = [],
90         _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
91         )
92
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})
98
99 INFO =\
100      Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
101               suffix = '.info', src_suffix = '.texi')
102 env.Append (BUILDERS = {'INFO': INFO})
103
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})
109
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})
119
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})
125
126 DVIPS =\
127       Builder (action = 'dvips -o $TARGET $DVIPS_FLAGS $SOURCE',
128                suffix = '.ps', src_suffix = '.dvi')
129 env.Append (BUILDERS = {'DVIPS': DVIPS})
130
131 DVIPDF =\
132       Builder (action = 'dvips -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
133                suffix = '.pdfps', src_suffix = '.dvi')
134 env.Append (BUILDERS = {'DVIPDF': DVIPDF})
135
136 PSPDF =\
137       Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
138                suffix = '.pdf', src_suffix = '.pdfps')
139 env.Append (BUILDERS = {'PSPDF': PSPDF})
140
141 PNG2EPS =\
142         Builder (action = 'convert $SOURCE $TARGET',
143                  suffix = '.eps', src_suffix = '.png')
144 env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
145
146
147
148 # FIXME: cleanup, see above
149
150
151 env.Append (
152
153         #urg
154         BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
155         BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
156 )
157
158
159 def add_ps_target (target, source, env):
160         base = os.path.splitext (str (target[0]))[0]
161         return (target + [base + '.ps'], source)
162
163 # TODO: 
164 # FIXME: INCLUDES, FLAGS, use LILYPOND_BIN for building ? 
165 lilypond =\
166          Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
167                   suffix = '.pdf', src_suffix = '.ly')
168 ##                  emitter = add_ps_target)
169 env.Append (BUILDERS = {'LilyPond': lilypond})
170
171 ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
172                suffix = '.ly', src_suffix = '.abc')
173 env.Append (BUILDERS = {'ABC': ABC})
174
175 def add_log_target (target, source, env):
176         base = os.path.splitext (str (target[0]))[0]
177         return (target + [base + '.log'], source)
178
179 def add_lisp_enc_tex_ly_target (target, source, env):
180         base = os.path.splitext (str (target[0]))[0]
181         return (target + [base + '.lisp', base + '.enc', base + '.tex',
182                           base + 'list.ly'],
183                 source)
184
185 def add_cff_cffps_svg (target, source, env):
186         base = os.path.splitext (str (target[0]))[0]
187         return (target + [base + '.cff', base + '.cff.ps', base + '.svg'],
188                 source)
189
190 a = 'cd ${TARGET.dir} \
191 && MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
192 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
193 | grep -v "@\|>>\|w:\|h:";'
194 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
195 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
196                emitter = add_log_target)
197 env.Append (BUILDERS = {'TFM': tfm})
198
199 a = '$PYTHON $MF_TO_TABLE_PY \
200 --outdir=${TARGET.dir} \
201 --global-lisp=${TARGET.base}.otf-gtable \
202 --lisp=${TARGET.base}.lisp \
203 --enc=${TARGET.base}.enc \
204 --tex=${TARGET.base}.tex \
205 --ly=${TARGET.base}list.ly \
206 ${TARGET.base}.log'
207 gtable = Builder (action = a, suffix = '.otf-gtable', src_suffix = '.log',
208                   emitter = add_lisp_enc_tex_ly_target)
209 env.Append (BUILDERS = {'GTABLE': gtable})
210
211 def add_enc_src (target, source, env):
212         base = os.path.splitext (str (target[0]))[0]
213         return (target, source + [base + '.enc'])
214
215 # UGH, should fix --output option for mftrace
216 # mftrace --verbose is too verbose
217 a = 'cd ${TARGET.dir} && \
218 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
219 MFINPUTS=$srcdir/mf:.: \
220 mftrace --formats=pfa --simplify --keep-trying --no-afm --verbose \
221 $$encoding $TOO__verbose \
222 --include=${TARGET.dir} \
223 ${SOURCE.file}'
224
225 pfa = Builder (action = a,
226                suffix = '.pfa',
227                src_suffix = '.mf',
228                emitter = add_enc_src)
229 env.Append (BUILDERS = {'PFA': pfa})
230
231 a = ['(cd ${TARGET.dir} && fontforge -script ${SOURCE.file})',
232      '$PYTHON $srcdir/buildscripts/ps-embed-cff.py ${SOURCE.filebase}.cff $(${SOURCE.filebase}).fontname) ${SOURCE.filebase}.cff.ps',
233      'rm -f ${TARGET.dir}/*.scale.pfa']
234 otf = Builder (action = a,
235                suffix = '.otf',
236                src_suffix = '.pe',
237                emitter = add_cff_cffps_svg)
238 env.Append (BUILDERS = {'OTF': otf})
239
240
241 # Specific builders
242
243 env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
244 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
245 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
246 env.Append (BUILDERS = {'PATCH': patch})
247
248 atvars = [
249 'BASH',
250 'DATE',
251 'sharedstatedir',
252 'GUILE',
253 'bindir',
254 'date',
255 'datadir',
256 'lilypond_datadir',
257 'lilypond_libdir',
258 'local_lilypond_datadir',
259 'local_lilypond_libdir',
260 'localedir',
261 'PACKAGE',
262 'package',
263 'PATHSEP',
264 'PERL',
265 'prefix',
266 'program_prefix',
267 'program_suffix',
268 'PYTHON',
269 'SHELL',
270 'TOPLEVEL_VERSION',
271 'step-bindir',
272 ]
273
274 # naming
275 def at_copy (target, source, env):
276     s = open (str (source[0])).read ()
277     for i in atvars:
278             if env.has_key (i):
279                     s = string.replace (s, '@%s@'% i, env[i])
280     t = str (target[0])
281     open (t, 'w').write (s)
282     # wugh
283     if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
284             os.chmod (t, 0755)
285
286 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
287 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
288
289 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
290               suffix = '.mo', src_suffix = '.po')
291 env.Append (BUILDERS = {'MO': MO})
292
293 # ' '; ?
294 ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po ; '
295 a = ugh + 'xgettext --default-domain=lilypond --join \
296 --output-dir=${TARGET.dir} --add-comments \
297 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
298 PO = Builder (action = a, suffix = '.pot',
299               src_suffix = ['.cc', '.hh', '.py'], multi = 1)
300 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
301                                 'lilypond.pot')
302 env['pocommand'] = a
303
304 ugh = '; mv ${TARGET} ${SOURCE}'
305 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
306 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
307 env.Append (BUILDERS = {'POMERGE': POMERGE})
308
309 #UGRr
310 a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
311 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
312 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
313
314 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
315 --name=${TARGET.base} --title="$TITLE" $SOURCES'
316 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
317 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
318
319
320 def mutopia (ly = None, abc = None):
321
322         # FIXME: ugr, huh?  The values from ../SConstruct get appended
323         # to the predefined values from this builder context:
324
325         # abc2ly/usr/bin/python ..../abc2.py
326
327         # Override them again to fix web build...
328
329         
330         BUILD_ABC2LY = '${set__x}$PYTHON $srcdir/scripts/abc2ly.py'
331         BUILD_LILYPOND = '${set__x}$PYTHON $srcdir/scripts/lilypond.py${__verbose}'
332         e = env.Copy (
333                 LILYPOND = BUILD_LILYPOND,
334                 ABC2LY = BUILD_ABC2LY,
335         )
336         
337         if not abc:
338                 abc = base_glob ('*.abc')
339         if not ly:
340                 ly = base_glob ('*.ly') + map (e.ABC, abc)
341         pdf = map (e.LilyPond, ly)
342         
343         # We need lily and mf to build these.
344         env.Depends (pdf, ['#/lily', '#/mf'])
345         env.Alias ('doc', pdf)
346
347 Export ('mutopia')
348
349
350 def collate (title = 'collated files'):
351         ly = base_glob ('*.ly')
352         
353         e = env.Copy (
354                 TITLE = title,
355                 LILYPOND_BOOK_FLAGS = '''--process="lilypond-bin --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'"''',
356                                                                                                             __verbose = ' --verbose',
357                                                                                                             )
358         #               
359         tely = e.LYS2TELY ('collated-files', ly)
360         texi = e.TEXI (tely)
361         # We need lily and mf to build these.
362         env.Depends (texi, ['#/lily', '#/mf'])
363         dvi = e.TEXIDVI (texi)
364         pspdf = e.DVIPDF (dvi)
365         pdf = e.PSPDF (pspdf)
366         html = e.HTML (texi)
367
368         env.Alias ('doc', pdf)
369         env.Alias ('doc', html)
370
371 Export ('collate')
372
373 Export ('env')